The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 17 | package com.android.server.wm; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 20 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 21 | import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 23 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 25 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 26 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 28 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 30 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.TYPE_DREAM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 33 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 34 | import static android.view.WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND; |
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; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import com.android.internal.view.IInputContext; |
| 41 | import com.android.internal.view.IInputMethodClient; |
| 42 | import com.android.internal.view.IInputMethodManager; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 43 | import com.android.internal.view.WindowManagerPolicyThread; |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 44 | import com.android.server.AttributeCache; |
| 45 | import com.android.server.EventLogTags; |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 46 | import com.android.server.Watchdog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import com.android.server.am.BatteryStatsService; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 48 | import com.android.server.display.DisplayDeviceInfo; |
| 49 | import com.android.server.display.DisplayManagerService; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 50 | import com.android.server.input.InputManagerService; |
Jeff Brown | 4f8ecd8 | 2012-06-18 18:29:13 -0700 | [diff] [blame] | 51 | import com.android.server.power.PowerManagerService; |
| 52 | import com.android.server.power.ShutdownThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | |
| 54 | import android.Manifest; |
| 55 | import android.app.ActivityManagerNative; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 56 | import android.app.ActivityOptions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.app.IActivityManager; |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 58 | import android.app.StatusBarManager; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 59 | import android.app.admin.DevicePolicyManager; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 60 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.content.Context; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 62 | import android.content.Intent; |
| 63 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.content.pm.ActivityInfo; |
| 65 | import android.content.pm.PackageManager; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 66 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.content.res.Configuration; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 68 | import android.graphics.Bitmap; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 69 | import android.graphics.Canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import android.graphics.Matrix; |
| 71 | import android.graphics.PixelFormat; |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 72 | import android.graphics.Point; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import android.graphics.Rect; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 74 | import android.graphics.RectF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.graphics.Region; |
| 76 | import android.os.BatteryStats; |
| 77 | import android.os.Binder; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 78 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | import android.os.Debug; |
| 80 | import android.os.Handler; |
| 81 | import android.os.IBinder; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 82 | import android.os.IRemoteCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import android.os.Looper; |
| 84 | import android.os.Message; |
| 85 | import android.os.Parcel; |
| 86 | import android.os.ParcelFileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | import android.os.PowerManager; |
| 88 | import android.os.Process; |
| 89 | import android.os.RemoteException; |
| 90 | import android.os.ServiceManager; |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 91 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | import android.os.SystemClock; |
| 93 | import android.os.SystemProperties; |
| 94 | import android.os.TokenWatcher; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 95 | import android.os.Trace; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.provider.Settings; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 97 | import android.util.DisplayMetrics; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | import android.util.EventLog; |
Michael Jurka | 4accb6a | 2012-03-26 09:18:46 -0700 | [diff] [blame] | 99 | import android.util.FloatMath; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 100 | import android.util.Log; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 101 | import android.util.SparseArray; |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 102 | //import android.util.LogPrinter; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 103 | import android.util.Pair; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 104 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | import android.util.SparseIntArray; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 106 | import android.util.TypedValue; |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 107 | import android.view.Choreographer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | import android.view.Display; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 109 | import android.view.DisplayInfo; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 110 | import android.view.Gravity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | import android.view.IApplicationToken; |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 112 | import android.view.IInputFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.IOnKeyguardExitResult; |
| 114 | import android.view.IRotationWatcher; |
| 115 | import android.view.IWindow; |
| 116 | import android.view.IWindowManager; |
| 117 | import android.view.IWindowSession; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 118 | import android.view.InputChannel; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 119 | import android.view.InputDevice; |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 120 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 121 | import android.view.InputEventReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | import android.view.KeyEvent; |
| 123 | import android.view.MotionEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | import android.view.Surface; |
| 125 | import android.view.SurfaceSession; |
| 126 | import android.view.View; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 127 | import android.view.ViewTreeObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | import android.view.WindowManager; |
| 129 | import android.view.WindowManagerImpl; |
| 130 | import android.view.WindowManagerPolicy; |
| 131 | import android.view.WindowManager.LayoutParams; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 132 | import android.view.WindowManagerPolicy.FakeWindow; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 133 | import android.view.animation.AlphaAnimation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | import android.view.animation.Animation; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 135 | import android.view.animation.AnimationSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | import android.view.animation.AnimationUtils; |
Michael Jurka | c016aaa | 2012-06-05 17:22:24 -0700 | [diff] [blame] | 137 | import android.view.animation.DecelerateInterpolator; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 138 | import android.view.animation.Interpolator; |
| 139 | import android.view.animation.ScaleAnimation; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 140 | import android.view.animation.Transformation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | |
| 142 | import java.io.BufferedWriter; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 143 | import java.io.DataInputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | import java.io.File; |
| 145 | import java.io.FileDescriptor; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 146 | import java.io.FileInputStream; |
| 147 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | import java.io.IOException; |
| 149 | import java.io.OutputStream; |
| 150 | import java.io.OutputStreamWriter; |
| 151 | import java.io.PrintWriter; |
| 152 | import java.io.StringWriter; |
| 153 | import java.net.Socket; |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 154 | import java.text.DateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | import java.util.ArrayList; |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 156 | import java.util.Date; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | import java.util.HashMap; |
| 158 | import java.util.HashSet; |
| 159 | import java.util.Iterator; |
| 160 | import java.util.List; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 161 | import java.util.NoSuchElementException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | |
| 163 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 164 | public class WindowManagerService extends IWindowManager.Stub |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 165 | implements Watchdog.Monitor, WindowManagerPolicy.WindowManagerFuncs { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | static final String TAG = "WindowManager"; |
| 167 | static final boolean DEBUG = false; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 168 | static final boolean DEBUG_ADD_REMOVE = false; |
Craig Mautner | 343511c | 2012-02-28 17:30:50 -0800 | [diff] [blame] | 169 | static final boolean DEBUG_FOCUS = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | static final boolean DEBUG_ANIM = false; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 171 | static final boolean DEBUG_LAYOUT = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 172 | static final boolean DEBUG_RESIZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | static final boolean DEBUG_LAYERS = false; |
| 174 | static final boolean DEBUG_INPUT = false; |
| 175 | static final boolean DEBUG_INPUT_METHOD = false; |
| 176 | static final boolean DEBUG_VISIBILITY = false; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 177 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 178 | static final boolean DEBUG_TOKEN_MOVEMENT = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | static final boolean DEBUG_ORIENTATION = false; |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 180 | static final boolean DEBUG_APP_ORIENTATION = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 181 | static final boolean DEBUG_CONFIGURATION = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 183 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 184 | static final boolean DEBUG_REORDER = false; |
Craig Mautner | 343511c | 2012-02-28 17:30:50 -0800 | [diff] [blame] | 185 | static final boolean DEBUG_WALLPAPER = false; |
Christopher Tate | 994ef92 | 2011-01-12 20:06:07 -0800 | [diff] [blame] | 186 | static final boolean DEBUG_DRAG = false; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 187 | static final boolean DEBUG_SCREEN_ON = false; |
Dianne Hackborn | cfb9f2b | 2011-08-24 10:51:49 -0700 | [diff] [blame] | 188 | static final boolean DEBUG_SCREENSHOT = false; |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 189 | static final boolean DEBUG_BOOT = false; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 190 | static final boolean DEBUG_LAYOUT_REPEATS = true; |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 191 | static final boolean DEBUG_SURFACE_TRACE = false; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 192 | static final boolean DEBUG_WINDOW_TRACE = false; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 193 | static final boolean SHOW_SURFACE_ALLOC = false; |
Craig Mautner | 343511c | 2012-02-28 17:30:50 -0800 | [diff] [blame] | 194 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 195 | static final boolean SHOW_LIGHT_TRANSACTIONS = false || SHOW_TRANSACTIONS; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 196 | static final boolean HIDE_STACK_CRAWLS = true; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 197 | static final int LAYOUT_REPEAT_THRESHOLD = 4; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | static final boolean PROFILE_ORIENTATION = false; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 200 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 201 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | /** How much to multiply the policy's type layer, to reserve room |
| 203 | * for multiple windows of the same type and Z-ordering adjustment |
| 204 | * with TYPE_LAYER_OFFSET. */ |
| 205 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 206 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 208 | * or below others in the same layer. */ |
| 209 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 210 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | /** How much to increment the layer for each window, to reserve room |
| 212 | * for effect surfaces between them. |
| 213 | */ |
| 214 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 215 | |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 216 | /** |
| 217 | * Dim surface layer is immediately below target window. |
| 218 | */ |
| 219 | static final int LAYER_OFFSET_DIM = 1; |
| 220 | |
| 221 | /** |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 222 | * Blur surface layer is immediately below dim layer. |
| 223 | */ |
| 224 | static final int LAYER_OFFSET_BLUR = 2; |
| 225 | |
| 226 | /** |
| 227 | * Animation thumbnail is as far as possible below the window above |
| 228 | * the thumbnail (or in other words as far as possible above the window |
| 229 | * below it). |
| 230 | */ |
| 231 | static final int LAYER_OFFSET_THUMBNAIL = WINDOW_LAYER_MULTIPLIER-1; |
| 232 | |
| 233 | /** |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 234 | * Layer at which to put the rotation freeze snapshot. |
| 235 | */ |
| 236 | static final int FREEZE_LAYER = (TYPE_LAYER_MULTIPLIER * 200) + 1; |
| 237 | |
| 238 | /** |
| 239 | * Layer at which to put the mask for emulated screen sizes. |
| 240 | */ |
| 241 | static final int MASK_LAYER = TYPE_LAYER_MULTIPLIER * 200; |
| 242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | /** The maximum length we will accept for a loaded animation duration: |
| 244 | * this is 10 seconds. |
| 245 | */ |
| 246 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 247 | |
| 248 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 249 | * value to another, when no window animation is driving it. |
| 250 | */ |
| 251 | static final int DEFAULT_DIM_DURATION = 200; |
| 252 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 253 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 254 | * compatible windows. |
| 255 | */ |
| 256 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 257 | |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 258 | /** |
| 259 | * If true, the window manager will do its own custom freezing and general |
| 260 | * management of the screen during rotation. |
| 261 | */ |
| 262 | static final boolean CUSTOM_SCREEN_ROTATION = true; |
| 263 | |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 264 | // Maximum number of milliseconds to wait for input devices to be enumerated before |
| 265 | // proceding with safe mode detection. |
| 266 | private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000; |
Jim Miller | 28637ba | 2011-07-06 19:57:05 -0700 | [diff] [blame] | 267 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 268 | // Default input dispatching timeout in nanoseconds. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 269 | static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 272 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 273 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 274 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 275 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 277 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | |
| 279 | /** |
| 280 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 281 | * the window policy has finished. |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 282 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 283 | * actually disabled the keyguard. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | */ |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 285 | private boolean mKeyguardDisabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 287 | private final boolean mHeadless; |
| 288 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 289 | private static final int ALLOW_DISABLE_YES = 1; |
| 290 | private static final int ALLOW_DISABLE_NO = 0; |
| 291 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 292 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 293 | |
Michael Jurka | c016aaa | 2012-06-05 17:22:24 -0700 | [diff] [blame] | 294 | private static final float THUMBNAIL_ANIMATION_DECELERATE_FACTOR = 1.5f; |
| 295 | |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 296 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 297 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
Craig Mautner | 2f995a7 | 2012-02-21 09:53:21 -0800 | [diff] [blame] | 298 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | public void acquired() { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 300 | if (shouldAllowDisableKeyguard()) { |
| 301 | mPolicy.enableKeyguard(false); |
| 302 | mKeyguardDisabled = true; |
| 303 | } else { |
| 304 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 305 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | } |
Craig Mautner | 2f995a7 | 2012-02-21 09:53:21 -0800 | [diff] [blame] | 307 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | public void released() { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 309 | mPolicy.enableKeyguard(true); |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 310 | synchronized (mKeyguardTokenWatcher) { |
| 311 | mKeyguardDisabled = false; |
| 312 | mKeyguardTokenWatcher.notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | }; |
| 316 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 317 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 318 | @Override |
| 319 | public void onReceive(Context context, Intent intent) { |
| 320 | mPolicy.enableKeyguard(true); |
| 321 | synchronized(mKeyguardTokenWatcher) { |
| 322 | // lazily evaluate this next time we're asked to disable keyguard |
| 323 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 324 | mKeyguardDisabled = false; |
| 325 | } |
| 326 | } |
| 327 | }; |
| 328 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | final Context mContext; |
| 330 | |
| 331 | final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 332 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 333 | final boolean mAllowBootMessages; |
| 334 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | final boolean mLimitedAlphaCompositing; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 336 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 338 | |
| 339 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | /** |
| 344 | * All currently active sessions with clients. |
| 345 | */ |
| 346 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 347 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | /** |
| 349 | * Mapping from an IWindow IBinder to the server's Window object. |
| 350 | * This is also used as the lock for all of our state. |
| 351 | */ |
| 352 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 353 | |
| 354 | /** |
| 355 | * Mapping from a token IBinder to a WindowToken object. |
| 356 | */ |
| 357 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 358 | new HashMap<IBinder, WindowToken>(); |
| 359 | |
| 360 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | * Window tokens that are in the process of exiting, but still |
| 362 | * on screen for animations. |
| 363 | */ |
| 364 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 365 | |
| 366 | /** |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 367 | * List controlling the ordering of windows in different applications which must |
| 368 | * be kept in sync with ActivityManager. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | */ |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 370 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | |
| 372 | /** |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 373 | * AppWindowTokens in the Z order they were in at the start of an animation. Between |
| 374 | * animations this list is maintained in the exact order of mAppTokens. If tokens |
| 375 | * are added to mAppTokens during an animation an attempt is made to insert them at the same |
| 376 | * logical location in this list. Note that this list is always in sync with mWindows. |
| 377 | */ |
| 378 | ArrayList<AppWindowToken> mAnimatingAppTokens = new ArrayList<AppWindowToken>(); |
| 379 | |
| 380 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | * Application tokens that are in the process of exiting, but still |
| 382 | * on screen for animations. |
| 383 | */ |
| 384 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 385 | |
| 386 | /** |
| 387 | * List of window tokens that have finished starting their application, |
| 388 | * and now need to have the policy remove their windows. |
| 389 | */ |
| 390 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 391 | |
| 392 | /** |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 393 | * Fake windows added to the window manager. Note: ordered from top to |
| 394 | * bottom, opposite of mWindows. |
| 395 | */ |
| 396 | final ArrayList<FakeWindowImpl> mFakeWindows = new ArrayList<FakeWindowImpl>(); |
| 397 | |
| 398 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | * Windows that are being resized. Used so we can tell the client about |
| 400 | * the resize after closing the transaction in which we resized the |
| 401 | * underlying surface. |
| 402 | */ |
| 403 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 404 | |
| 405 | /** |
| 406 | * Windows whose animations have ended and now must be removed. |
| 407 | */ |
| 408 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 409 | |
| 410 | /** |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 411 | * Used when processing mPendingRemove to avoid working on the original array. |
| 412 | */ |
| 413 | WindowState[] mPendingRemoveTmp = new WindowState[20]; |
| 414 | |
| 415 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | * Windows whose surface should be destroyed. |
| 417 | */ |
| 418 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 419 | |
| 420 | /** |
| 421 | * Windows that have lost input focus and are waiting for the new |
| 422 | * focus window to be displayed before they are told about this. |
| 423 | */ |
| 424 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 425 | |
| 426 | /** |
| 427 | * This is set when we have run out of memory, and will either be an empty |
| 428 | * list or contain windows that need to be force removed. |
| 429 | */ |
| 430 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 431 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 432 | /** |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 433 | * Windows that clients are waiting to have drawn. |
| 434 | */ |
| 435 | ArrayList<Pair<WindowState, IRemoteCallback>> mWaitingForDrawn |
| 436 | = new ArrayList<Pair<WindowState, IRemoteCallback>>(); |
| 437 | |
| 438 | /** |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 439 | * Windows that have called relayout() while we were running animations, |
| 440 | * so we need to tell when the animation is done. |
| 441 | */ |
| 442 | final ArrayList<WindowState> mRelayoutWhileAnimating = new ArrayList<WindowState>(); |
| 443 | |
| 444 | /** |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 445 | * Used when rebuilding window list to keep track of windows that have |
| 446 | * been removed. |
| 447 | */ |
| 448 | WindowState[] mRebuildTmp = new WindowState[20]; |
| 449 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 451 | |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 452 | final SurfaceSession mFxSession; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 453 | Watermark mWatermark; |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 454 | StrictModeFlash mStrictModeFlash; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 455 | |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 456 | BlackFrame mBlackFrame; |
| 457 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | final float[] mTmpFloats = new float[9]; |
| 459 | |
| 460 | boolean mSafeMode; |
| 461 | boolean mDisplayEnabled = false; |
| 462 | boolean mSystemBooted = false; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 463 | boolean mForceDisplayEnabled = false; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 464 | boolean mShowingBootMessages = false; |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 465 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 466 | String mLastANRState; |
| 467 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 468 | /** All DisplayDontents in the world, kept here */ |
| 469 | private SparseArray<DisplayContent> mDisplayContents = new SparseArray<DisplayContent>(); |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 470 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | int mRotation = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 472 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 473 | boolean mAltOrientation = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | ArrayList<IRotationWatcher> mRotationWatchers |
| 475 | = new ArrayList<IRotationWatcher>(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 476 | int mDeferredRotationPauseCount; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 477 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 478 | final Rect mSystemDecorRect = new Rect(); |
| 479 | int mSystemDecorLayer = 0; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 480 | final Rect mScreenRect = new Rect(); |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 481 | |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 482 | int mPendingLayoutChanges = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 483 | boolean mLayoutNeeded = true; |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 484 | boolean mTraversalScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | boolean mDisplayFrozen = false; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 486 | boolean mWaitingForConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | boolean mWindowsFreezingScreen = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | int mAppsFreezingScreen = 0; |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 489 | int mLastWindowForcedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 491 | int mLayoutSeq = 0; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 492 | |
| 493 | int mLastStatusBarVisibility = 0; |
| 494 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 495 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 496 | boolean mFocusMayChange; |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 497 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 498 | Configuration mCurConfiguration = new Configuration(); |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 499 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | // This is held as long as we have the screen frozen, to give us time to |
| 501 | // perform a rotation animation when turning off shows the lock screen which |
| 502 | // changes the orientation. |
| 503 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 504 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | // State management of app transitions. When we are preparing for a |
| 506 | // transition, mNextAppTransition will be the kind of transition to |
| 507 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 508 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 509 | // made visible or hidden at the next transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 510 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 511 | int mNextAppTransitionType = ActivityOptions.ANIM_NONE; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 512 | String mNextAppTransitionPackage; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 513 | Bitmap mNextAppTransitionThumbnail; |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 514 | boolean mNextAppTransitionDelayed; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 515 | IRemoteCallback mNextAppTransitionCallback; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 516 | int mNextAppTransitionEnter; |
| 517 | int mNextAppTransitionExit; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 518 | int mNextAppTransitionStartX; |
| 519 | int mNextAppTransitionStartY; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 520 | int mNextAppTransitionStartWidth; |
| 521 | int mNextAppTransitionStartHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 522 | boolean mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 523 | boolean mAppTransitionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | boolean mAppTransitionTimeout = false; |
| 525 | boolean mStartingIconInTransition = false; |
| 526 | boolean mSkipAppTransitionAnimation = false; |
| 527 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 528 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | Display mDisplay; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 531 | |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 532 | boolean mIsTouchDevice; |
| 533 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 534 | final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 535 | final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics(); |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 536 | final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics(); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 537 | final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics(); |
| 538 | |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 539 | final H mH = new H(); |
| 540 | |
| 541 | final Choreographer mChoreographer = Choreographer.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 542 | |
| 543 | WindowState mCurrentFocus = null; |
| 544 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 545 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 546 | /** This just indicates the window the input method is on top of, not |
| 547 | * necessarily the window its input is going to. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | WindowState mInputMethodTarget = null; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 549 | |
| 550 | /** If true hold off on modifying the animation layer of mInputMethodTarget */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | boolean mInputMethodTargetWaitingAnim; |
| 552 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 553 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | WindowState mInputMethodWindow = null; |
| 555 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 556 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 557 | boolean mHardKeyboardAvailable; |
| 558 | boolean mHardKeyboardEnabled; |
| 559 | OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener; |
| 560 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 561 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 562 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 563 | // If non-null, this is the currently visible window that is associated |
| 564 | // with the wallpaper. |
| 565 | WindowState mWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 566 | // If non-null, we are in the middle of animating from one wallpaper target |
| 567 | // to another, and this is the lower one in Z-order. |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 568 | private WindowState mLowerWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 569 | // If non-null, we are in the middle of animating from one wallpaper target |
| 570 | // to another, and this is the higher one in Z-order. |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 571 | private WindowState mUpperWallpaperTarget = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 572 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 573 | float mLastWallpaperX = -1; |
| 574 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 575 | float mLastWallpaperXStep = -1; |
| 576 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 577 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 578 | // changing its scroll position. |
| 579 | WindowState mWaitingOnWallpaper; |
| 580 | // The last time we had a timeout when waiting for a wallpaper. |
| 581 | long mLastWallpaperTimeoutTime; |
| 582 | // We give a wallpaper up to 150ms to finish scrolling. |
| 583 | static final long WALLPAPER_TIMEOUT = 150; |
| 584 | // Time we wait after a timeout before trying to wait again. |
| 585 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | AppWindowToken mFocusedApp = null; |
| 588 | |
| 589 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 590 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 591 | float mWindowAnimationScale = 1.0f; |
| 592 | float mTransitionAnimationScale = 1.0f; |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 593 | float mAnimatorDurationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 594 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 595 | final InputManagerService mInputManager; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 596 | final DisplayManagerService mDisplayManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 597 | |
| 598 | // Who is holding the screen on. |
| 599 | Session mHoldingScreenOn; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 600 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 601 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 602 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 603 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 604 | DragState mDragState = null; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 605 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 606 | /** Pulled out of performLayoutAndPlaceSurfacesLockedInner in order to refactor into multiple |
| 607 | * methods. */ |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 608 | class LayoutFields { |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 609 | static final int SET_UPDATE_ROTATION = 1 << 0; |
| 610 | static final int SET_WALLPAPER_MAY_CHANGE = 1 << 1; |
| 611 | static final int SET_FORCE_HIDING_CHANGED = 1 << 2; |
Craig Mautner | 2639da5 | 2012-07-09 09:39:06 -0700 | [diff] [blame] | 612 | static final int SET_ORIENTATION_CHANGE_COMPLETE = 1 << 3; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 613 | static final int SET_TURN_ON_SCREEN = 1 << 4; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 614 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 615 | boolean mWallpaperForceHidingChanged = false; |
| 616 | boolean mWallpaperMayChange = false; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 617 | boolean mOrientationChangeComplete = true; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 618 | int mAdjResult = 0; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 619 | private Session mHoldScreen = null; |
| 620 | private boolean mObscured = false; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 621 | boolean mDimming = false; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 622 | private boolean mSyswin = false; |
| 623 | private float mScreenBrightness = -1; |
| 624 | private float mButtonBrightness = -1; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 625 | private boolean mUpdateRotation = false; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 626 | } |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 627 | final LayoutFields mInnerFields = new LayoutFields(); |
| 628 | |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 629 | static class AppWindowAnimParams { |
| 630 | AppWindowAnimator mAppAnimator; |
| 631 | ArrayList<WindowStateAnimator> mWinAnimators; |
| 632 | |
| 633 | public AppWindowAnimParams(final AppWindowAnimator appAnimator) { |
| 634 | mAppAnimator = appAnimator; |
| 635 | |
| 636 | final AppWindowToken wtoken = appAnimator.mAppToken; |
| 637 | mWinAnimators = new ArrayList<WindowStateAnimator>(); |
| 638 | final int N = wtoken.allAppWindows.size(); |
| 639 | for (int i = 0; i < N; i++) { |
| 640 | mWinAnimators.add(wtoken.allAppWindows.get(i).mWinAnimator); |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 645 | static class LayoutToAnimatorParams { |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 646 | boolean mParamsModified; |
| 647 | |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 648 | static final long WALLPAPER_TOKENS_CHANGED = 1 << 0; |
| 649 | long mChanges; |
| 650 | |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 651 | boolean mAnimationScheduled; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 652 | ArrayList<WinAnimatorList> mWinAnimatorLists = new ArrayList<WinAnimatorList>(); |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 653 | WindowState mWallpaperTarget; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 654 | WindowState mLowerWallpaperTarget; |
| 655 | WindowState mUpperWallpaperTarget; |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 656 | DimAnimator.Parameters mDimParams; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 657 | ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 658 | ArrayList<AppWindowAnimParams> mAppWindowAnimParams = new ArrayList<AppWindowAnimParams>(); |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 659 | } |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 660 | /** Params from WindowManagerService to WindowAnimator. Do not modify or read without first |
| 661 | * locking on either mWindowMap or mAnimator and then on mLayoutToAnim */ |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 662 | final LayoutToAnimatorParams mLayoutToAnim = new LayoutToAnimatorParams(); |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 663 | |
| 664 | /** The lowest wallpaper target with a detached wallpaper animation on it. */ |
| 665 | WindowState mWindowDetachedWallpaper = null; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 666 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 667 | /** Skip repeated AppWindowTokens initialization. Note that AppWindowsToken's version of this |
| 668 | * is a long initialized to Long.MIN_VALUE so that it doesn't match this value on startup. */ |
| 669 | private int mTransactionSequence; |
| 670 | |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 671 | /** Only do a maximum of 6 repeated layouts. After that quit */ |
| 672 | private int mLayoutRepeatCount; |
| 673 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 674 | final WindowAnimator mAnimator; |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 675 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 676 | final class DragInputEventReceiver extends InputEventReceiver { |
| 677 | public DragInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 678 | super(inputChannel, looper); |
| 679 | } |
| 680 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 681 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 682 | public void onInputEvent(InputEvent event) { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 683 | boolean handled = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 684 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 685 | if (event instanceof MotionEvent |
| 686 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 687 | && mDragState != null) { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 688 | final MotionEvent motionEvent = (MotionEvent)event; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 689 | boolean endDrag = false; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 690 | final float newX = motionEvent.getRawX(); |
| 691 | final float newY = motionEvent.getRawY(); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 692 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 693 | switch (motionEvent.getAction()) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 694 | case MotionEvent.ACTION_DOWN: { |
| 695 | if (DEBUG_DRAG) { |
| 696 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 697 | } |
| 698 | } break; |
| 699 | |
| 700 | case MotionEvent.ACTION_MOVE: { |
| 701 | synchronized (mWindowMap) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 702 | // move the surface and tell the involved window(s) where we are |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 703 | mDragState.notifyMoveLw(newX, newY); |
| 704 | } |
| 705 | } break; |
| 706 | |
| 707 | case MotionEvent.ACTION_UP: { |
| 708 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 709 | + newX + "," + newY); |
| 710 | synchronized (mWindowMap) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 711 | endDrag = mDragState.notifyDropLw(newX, newY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 712 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 713 | } break; |
| 714 | |
| 715 | case MotionEvent.ACTION_CANCEL: { |
| 716 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 717 | endDrag = true; |
| 718 | } break; |
| 719 | } |
| 720 | |
| 721 | if (endDrag) { |
| 722 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 723 | // tell all the windows that the drag has ended |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 724 | synchronized (mWindowMap) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 725 | mDragState.endDragLw(); |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 726 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 727 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 728 | |
| 729 | handled = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 730 | } |
| 731 | } catch (Exception e) { |
| 732 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 733 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 734 | finishInputEvent(event, handled); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 735 | } |
| 736 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 737 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 738 | |
| 739 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | * Whether the UI is currently running in touch mode (not showing |
| 741 | * navigational focus because the user is directly pressing the screen). |
| 742 | */ |
Michael Jurka | e99adc7 | 2011-08-11 18:28:01 -0700 | [diff] [blame] | 743 | boolean mInTouchMode = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | |
| 745 | private ViewServer mViewServer; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 746 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 747 | new ArrayList<WindowChangeListener>(); |
| 748 | private boolean mWindowsChanged = false; |
| 749 | |
| 750 | public interface WindowChangeListener { |
| 751 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 752 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 753 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 754 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 755 | final Configuration mTempConfiguration = new Configuration(); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 756 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 757 | // The desired scaling factor for compatible apps. |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 758 | float mCompatibleScreenScale; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 759 | |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 760 | // If true, only the core apps and services are being launched because the device |
| 761 | // is in a special boot mode, such as being encrypted or waiting for a decryption password. |
| 762 | // For example, when this flag is true, there will be no wallpaper service. |
| 763 | final boolean mOnlyCore; |
| 764 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 765 | public static WindowManagerService main(Context context, |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 766 | PowerManagerService pm, DisplayManagerService dm, |
| 767 | boolean haveInputMethods, boolean allowBootMsgs, |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 768 | boolean onlyCore) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 769 | WMThread thr = new WMThread(context, pm, dm, haveInputMethods, allowBootMsgs, onlyCore); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 770 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 771 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | synchronized (thr) { |
| 773 | while (thr.mService == null) { |
| 774 | try { |
| 775 | thr.wait(); |
| 776 | } catch (InterruptedException e) { |
| 777 | } |
| 778 | } |
Jozef BABJAK | 06e57b5 | 2011-01-20 08:09:25 +0100 | [diff] [blame] | 779 | return thr.mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 780 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 781 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 782 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | static class WMThread extends Thread { |
| 784 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 785 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | private final Context mContext; |
| 787 | private final PowerManagerService mPM; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 788 | private final DisplayManagerService mDisplayManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 789 | private final boolean mHaveInputMethods; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 790 | private final boolean mAllowBootMessages; |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 791 | private final boolean mOnlyCore; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | public WMThread(Context context, PowerManagerService pm, |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 794 | DisplayManagerService dm, |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 795 | boolean haveInputMethods, boolean allowBootMsgs, boolean onlyCore) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | super("WindowManager"); |
| 797 | mContext = context; |
| 798 | mPM = pm; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 799 | mDisplayManager = dm; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | mHaveInputMethods = haveInputMethods; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 801 | mAllowBootMessages = allowBootMsgs; |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 802 | mOnlyCore = onlyCore; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 803 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 804 | |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 805 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | public void run() { |
| 807 | Looper.prepare(); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 808 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| 809 | // android.util.Log.DEBUG, TAG, android.util.Log.LOG_ID_SYSTEM)); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 810 | WindowManagerService s = new WindowManagerService(mContext, mPM, mDisplayManager, |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 811 | mHaveInputMethods, mAllowBootMessages, mOnlyCore); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | android.os.Process.setThreadPriority( |
| 813 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 814 | android.os.Process.setCanSelfBackground(false); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 815 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 816 | synchronized (this) { |
| 817 | mService = s; |
| 818 | notifyAll(); |
| 819 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 820 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 821 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 822 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 823 | Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper"); |
| 824 | } |
| 825 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 826 | Looper.loop(); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | static class PolicyThread extends Thread { |
| 831 | private final WindowManagerPolicy mPolicy; |
| 832 | private final WindowManagerService mService; |
| 833 | private final Context mContext; |
| 834 | private final PowerManagerService mPM; |
| 835 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 836 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | public PolicyThread(WindowManagerPolicy policy, |
| 838 | WindowManagerService service, Context context, |
| 839 | PowerManagerService pm) { |
| 840 | super("WindowManagerPolicy"); |
| 841 | mPolicy = policy; |
| 842 | mService = service; |
| 843 | mContext = context; |
| 844 | mPM = pm; |
| 845 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 846 | |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 847 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 848 | public void run() { |
| 849 | Looper.prepare(); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 850 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 851 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 853 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | android.os.Process.setThreadPriority( |
Jim Miller | 54dbbce | 2012-01-23 15:24:42 -0800 | [diff] [blame] | 855 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 856 | android.os.Process.setCanSelfBackground(false); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 857 | mPolicy.init(mContext, mService, mService, mPM); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 858 | mService.mAnimator.mAboveUniverseLayer = mPolicy.getAboveUniverseLayer() |
| 859 | * TYPE_LAYER_MULTIPLIER |
| 860 | + TYPE_LAYER_OFFSET; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 861 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 862 | synchronized (this) { |
| 863 | mRunning = true; |
| 864 | notifyAll(); |
| 865 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 866 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 867 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 868 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 869 | Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper"); |
| 870 | } |
| 871 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 872 | Looper.loop(); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | private WindowManagerService(Context context, PowerManagerService pm, |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 877 | DisplayManagerService displayManager, |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 878 | boolean haveInputMethods, boolean showBootMsgs, boolean onlyCore) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 879 | mContext = context; |
| 880 | mHaveInputMethods = haveInputMethods; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 881 | mAllowBootMessages = showBootMsgs; |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 882 | mOnlyCore = onlyCore; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 883 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 884 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 885 | mDisplayManager = displayManager; |
| 886 | mHeadless = displayManager.isHeadless(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 887 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 888 | mPowerManager = pm; |
| 889 | mPowerManager.setPolicy(mPolicy); |
| 890 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 891 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 892 | "SCREEN_FROZEN"); |
| 893 | mScreenFrozenLock.setReferenceCounted(false); |
| 894 | |
| 895 | mActivityManager = ActivityManagerNative.getDefault(); |
| 896 | mBatteryStats = BatteryStatsService.getService(); |
| 897 | |
| 898 | // Get persisted window scale setting |
| 899 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 900 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 901 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 902 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 903 | mAnimatorDurationScale = Settings.System.getFloat(context.getContentResolver(), |
| 904 | Settings.System.ANIMATOR_DURATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 905 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 906 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 907 | IntentFilter filter = new IntentFilter(); |
| 908 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 909 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 910 | |
Dianne Hackborn | b80395c | 2012-06-14 19:38:20 -0700 | [diff] [blame] | 911 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
| 912 | | PowerManager.ON_AFTER_RELEASE, "KEEP_SCREEN_ON_FLAG"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 913 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 914 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 915 | mInputManager = new InputManagerService(context, mInputMonitor); |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 916 | mFxSession = new SurfaceSession(); |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 917 | mAnimator = new WindowAnimator(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 920 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 922 | synchronized (thr) { |
| 923 | while (!thr.mRunning) { |
| 924 | try { |
| 925 | thr.wait(); |
| 926 | } catch (InterruptedException e) { |
| 927 | } |
| 928 | } |
| 929 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 930 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 931 | mInputManager.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 932 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | // Add ourself to the Watchdog monitors. |
| 934 | Watchdog.getInstance().addMonitor(this); |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 935 | |
| 936 | Surface.openTransaction(); |
| 937 | createWatermark(); |
| 938 | Surface.closeTransaction(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | } |
| 940 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 941 | public InputManagerService getInputManagerService() { |
| 942 | return mInputManager; |
| 943 | } |
| 944 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 945 | @Override |
| 946 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 947 | throws RemoteException { |
| 948 | try { |
| 949 | return super.onTransact(code, data, reply, flags); |
| 950 | } catch (RuntimeException e) { |
| 951 | // The window manager only throws security exceptions, so let's |
| 952 | // log all others. |
| 953 | if (!(e instanceof SecurityException)) { |
Dianne Hackborn | 8962028 | 2011-09-11 12:47:45 -0700 | [diff] [blame] | 954 | Log.wtf(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 955 | } |
| 956 | throw e; |
| 957 | } |
| 958 | } |
| 959 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 960 | private void placeWindowAfter(WindowState pos, WindowState window) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 961 | final WindowList windows = pos.getWindowList(); |
| 962 | final int i = windows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 963 | 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] | 964 | TAG, "Adding window " + window + " at " |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 965 | + (i+1) + " of " + windows.size() + " (after " + pos + ")"); |
| 966 | windows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 967 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 968 | } |
| 969 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 970 | private void placeWindowBefore(WindowState pos, WindowState window) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 971 | final WindowList windows = pos.getWindowList(); |
| 972 | final int i = windows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 973 | 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] | 974 | TAG, "Adding window " + window + " at " |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 975 | + i + " of " + windows.size() + " (before " + pos + ")"); |
| 976 | windows.add(i, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 977 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | //This method finds out the index of a window that has the same app token as |
| 981 | //win. used for z ordering the windows in mWindows |
| 982 | private int findIdxBasedOnAppTokens(WindowState win) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 983 | WindowList windows = win.getWindowList(); |
| 984 | for(int j = windows.size() - 1; j >= 0; j--) { |
| 985 | WindowState wentry = windows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | if(wentry.mAppToken == win.mAppToken) { |
| 987 | return j; |
| 988 | } |
| 989 | } |
| 990 | return -1; |
| 991 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 993 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 994 | final IWindow client = win.mClient; |
| 995 | final WindowToken token = win.mToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 996 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 997 | final WindowList windows = win.getWindowList(); |
| 998 | final int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 999 | final WindowState attached = win.mAttachedWindow; |
| 1000 | int i; |
| 1001 | if (attached == null) { |
| 1002 | int tokenWindowsPos = token.windows.size(); |
| 1003 | if (token.appWindowToken != null) { |
| 1004 | int index = tokenWindowsPos-1; |
| 1005 | if (index >= 0) { |
| 1006 | // If this application has existing windows, we |
| 1007 | // simply place the new window on top of them... but |
| 1008 | // keep the starting window on top. |
| 1009 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1010 | // Base windows go behind everything else. |
| 1011 | placeWindowBefore(token.windows.get(0), win); |
| 1012 | tokenWindowsPos = 0; |
| 1013 | } else { |
| 1014 | AppWindowToken atoken = win.mAppToken; |
| 1015 | if (atoken != null && |
| 1016 | token.windows.get(index) == atoken.startingWindow) { |
| 1017 | placeWindowBefore(token.windows.get(index), win); |
| 1018 | tokenWindowsPos--; |
| 1019 | } else { |
| 1020 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1021 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1022 | //there is a window above this one associated with the same |
| 1023 | //apptoken note that the window could be a floating window |
| 1024 | //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] | 1025 | //windows associated with this token. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1026 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1027 | Slog.v(TAG, "Adding window " + win + " at " |
| 1028 | + (newIdx+1) + " of " + N); |
| 1029 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1030 | windows.add(newIdx+1, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1031 | mWindowsChanged = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1032 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1033 | } |
| 1034 | } |
| 1035 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1036 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1037 | TAG, "Figuring out where to add app window " |
| 1038 | + client.asBinder() + " (token=" + token + ")"); |
| 1039 | // Figure out where the window should go, based on the |
| 1040 | // order of applications. |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 1041 | final int NA = mAnimatingAppTokens.size(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1042 | WindowState pos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1043 | for (i=NA-1; i>=0; i--) { |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 1044 | AppWindowToken t = mAnimatingAppTokens.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1045 | if (t == token) { |
| 1046 | i--; |
| 1047 | break; |
| 1048 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1049 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1050 | // We haven't reached the token yet; if this token |
| 1051 | // is not going to the bottom and has windows, we can |
| 1052 | // use it as an anchor for when we do reach the token. |
| 1053 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1054 | pos = t.windows.get(0); |
| 1055 | } |
| 1056 | } |
| 1057 | // We now know the index into the apps. If we found |
| 1058 | // an app window above, that gives us the position; else |
| 1059 | // we need to look some more. |
| 1060 | if (pos != null) { |
| 1061 | // Move behind any windows attached to this one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1062 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1063 | if (atoken != null) { |
| 1064 | final int NC = atoken.windows.size(); |
| 1065 | if (NC > 0) { |
| 1066 | WindowState bottom = atoken.windows.get(0); |
| 1067 | if (bottom.mSubLayer < 0) { |
| 1068 | pos = bottom; |
| 1069 | } |
| 1070 | } |
| 1071 | } |
| 1072 | placeWindowBefore(pos, win); |
| 1073 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1074 | // Continue looking down until we find the first |
| 1075 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | while (i >= 0) { |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 1077 | AppWindowToken t = mAnimatingAppTokens.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | final int NW = t.windows.size(); |
| 1079 | if (NW > 0) { |
| 1080 | pos = t.windows.get(NW-1); |
| 1081 | break; |
| 1082 | } |
| 1083 | i--; |
| 1084 | } |
| 1085 | if (pos != null) { |
| 1086 | // Move in front of any windows attached to this |
| 1087 | // one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1088 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1089 | if (atoken != null) { |
| 1090 | final int NC = atoken.windows.size(); |
| 1091 | if (NC > 0) { |
| 1092 | WindowState top = atoken.windows.get(NC-1); |
| 1093 | if (top.mSubLayer >= 0) { |
| 1094 | pos = top; |
| 1095 | } |
| 1096 | } |
| 1097 | } |
| 1098 | placeWindowAfter(pos, win); |
| 1099 | } else { |
| 1100 | // Just search for the start of this layer. |
| 1101 | final int myLayer = win.mBaseLayer; |
| 1102 | for (i=0; i<N; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1103 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1104 | if (w.mBaseLayer > myLayer) { |
| 1105 | break; |
| 1106 | } |
| 1107 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1108 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1109 | Slog.v(TAG, "Adding window " + win + " at " |
| 1110 | + i + " of " + N); |
| 1111 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1112 | windows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1113 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | } else { |
| 1118 | // Figure out where window should go, based on layer. |
| 1119 | final int myLayer = win.mBaseLayer; |
| 1120 | for (i=N-1; i>=0; i--) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1121 | if (windows.get(i).mBaseLayer <= myLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1122 | i++; |
| 1123 | break; |
| 1124 | } |
| 1125 | } |
| 1126 | if (i < 0) i = 0; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1127 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1128 | TAG, "Adding window " + win + " at " |
| 1129 | + i + " of " + N); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1130 | windows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1131 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1132 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1135 | 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] | 1136 | token.windows.add(tokenWindowsPos, win); |
| 1137 | } |
| 1138 | |
| 1139 | } else { |
| 1140 | // Figure out this window's ordering relative to the window |
| 1141 | // it is attached to. |
| 1142 | final int NA = token.windows.size(); |
| 1143 | final int sublayer = win.mSubLayer; |
| 1144 | int largestSublayer = Integer.MIN_VALUE; |
| 1145 | WindowState windowWithLargestSublayer = null; |
| 1146 | for (i=0; i<NA; i++) { |
| 1147 | WindowState w = token.windows.get(i); |
| 1148 | final int wSublayer = w.mSubLayer; |
| 1149 | if (wSublayer >= largestSublayer) { |
| 1150 | largestSublayer = wSublayer; |
| 1151 | windowWithLargestSublayer = w; |
| 1152 | } |
| 1153 | if (sublayer < 0) { |
| 1154 | // For negative sublayers, we go below all windows |
| 1155 | // in the same sublayer. |
| 1156 | if (wSublayer >= sublayer) { |
| 1157 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1158 | 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] | 1159 | token.windows.add(i, win); |
| 1160 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1161 | placeWindowBefore(wSublayer >= 0 ? attached : w, win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1162 | break; |
| 1163 | } |
| 1164 | } else { |
| 1165 | // For positive sublayers, we go above all windows |
| 1166 | // in the same sublayer. |
| 1167 | if (wSublayer > sublayer) { |
| 1168 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1169 | 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] | 1170 | token.windows.add(i, win); |
| 1171 | } |
| 1172 | placeWindowBefore(w, win); |
| 1173 | break; |
| 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | if (i >= NA) { |
| 1178 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1179 | 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] | 1180 | token.windows.add(win); |
| 1181 | } |
| 1182 | if (sublayer < 0) { |
| 1183 | placeWindowBefore(attached, win); |
| 1184 | } else { |
| 1185 | placeWindowAfter(largestSublayer >= 0 |
| 1186 | ? windowWithLargestSublayer |
| 1187 | : attached, |
| 1188 | win); |
| 1189 | } |
| 1190 | } |
| 1191 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1192 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1193 | if (win.mAppToken != null && addToToken) { |
| 1194 | win.mAppToken.allAppWindows.add(win); |
| 1195 | } |
| 1196 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1197 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 1198 | /** TODO(cmautner): Is this the same as {@link WindowState#canReceiveKeys()} */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1199 | static boolean canBeImeTarget(WindowState w) { |
| 1200 | final int fl = w.mAttrs.flags |
| 1201 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1202 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM) |
| 1203 | || w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 1204 | if (DEBUG_INPUT_METHOD) { |
| 1205 | Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding()); |
| 1206 | if (!w.isVisibleOrAdding()) { |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 1207 | Slog.i(TAG, " mSurface=" + w.mWinAnimator.mSurface |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1208 | + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 1209 | + " policyVis=" + w.mPolicyVisibility |
| 1210 | + " policyVisAfterAnim=" + w.mPolicyVisibilityAfterAnim |
| 1211 | + " attachHid=" + w.mAttachedHidden |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1212 | + " exiting=" + w.mExiting + " destroying=" + w.mDestroying); |
| 1213 | if (w.mAppToken != null) { |
| 1214 | Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested); |
| 1215 | } |
| 1216 | } |
| 1217 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1218 | return w.isVisibleOrAdding(); |
| 1219 | } |
| 1220 | return false; |
| 1221 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1222 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 1223 | /** |
| 1224 | * Dig through the WindowStates and find the one that the Input Method will target. |
| 1225 | * @param willMove |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1226 | * @param windows TODO(cmautner): |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 1227 | * @return The index+1 in mWindows of the discovered target. |
| 1228 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1229 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1230 | // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the |
| 1231 | // same display. Or even when the current IME/target are not on the same screen as the next |
| 1232 | // IME/target. For now only look for input windows on the main screen. |
| 1233 | WindowList windows = getDefaultWindowList(); |
| 1234 | final int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | WindowState w = null; |
| 1236 | int i = N; |
| 1237 | while (i > 0) { |
| 1238 | i--; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1239 | w = windows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1240 | |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1241 | if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i |
| 1242 | + " " + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1243 | if (canBeImeTarget(w)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1244 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1245 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1246 | // Yet more tricksyness! If this window is a "starting" |
| 1247 | // window, we do actually want to be on top of it, but |
| 1248 | // it is not -really- where input will go. So if the caller |
| 1249 | // is not actually looking to move the IME, look down below |
| 1250 | // for a real window to target... |
| 1251 | if (!willMove |
| 1252 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1253 | && i > 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1254 | WindowState wb = windows.get(i-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1255 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1256 | i--; |
| 1257 | w = wb; |
| 1258 | } |
| 1259 | } |
| 1260 | break; |
| 1261 | } |
| 1262 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1263 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 1264 | // Now w is either mWindows[0] or an IME (or null if mWindows is empty). |
| 1265 | |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1266 | if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 1267 | |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1268 | // Now, a special case -- if the last target's window is in the |
| 1269 | // process of exiting, and is above the new target, keep on the |
| 1270 | // last target to avoid flicker. Consider for example a Dialog with |
| 1271 | // the IME shown: when the Dialog is dismissed, we want to keep |
| 1272 | // the IME above it until it is completely gone so it doesn't drop |
| 1273 | // behind the dialog or its full-screen scrim. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1274 | final WindowState curTarget = mInputMethodTarget; |
| 1275 | if (curTarget != null && w != null |
| 1276 | && curTarget.isDisplayedLw() |
| 1277 | && curTarget.mExiting) { |
| 1278 | if (curTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer) { |
| 1279 | w = curTarget; |
| 1280 | i = windows.indexOf(w); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1281 | 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] | 1282 | } |
| 1283 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1284 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1285 | 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] | 1286 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1287 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1288 | if (willMove && w != null) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1289 | AppWindowToken token = curTarget == null ? null : curTarget.mAppToken; |
| 1290 | if (token != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1292 | // Now some fun for dealing with window animations that |
| 1293 | // modify the Z order. We need to look at all windows below |
| 1294 | // the current target that are in this app, finding the highest |
| 1295 | // visible one in layering. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1296 | WindowState highestTarget = null; |
| 1297 | int highestPos = 0; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1298 | if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1299 | WindowList curWindows = curTarget.getWindowList(); |
| 1300 | int pos = curWindows.indexOf(curTarget); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | while (pos >= 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1302 | WindowState win = curWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1303 | if (win.mAppToken != token) { |
| 1304 | break; |
| 1305 | } |
| 1306 | if (!win.mRemoved) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1307 | if (highestTarget == null || win.mWinAnimator.mAnimLayer > |
| 1308 | highestTarget.mWinAnimator.mAnimLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1309 | highestTarget = win; |
| 1310 | highestPos = pos; |
| 1311 | } |
| 1312 | } |
| 1313 | pos--; |
| 1314 | } |
| 1315 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1316 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1317 | if (highestTarget != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1318 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1319 | + mNextAppTransition + " " + highestTarget |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1320 | + " animating=" + highestTarget.mWinAnimator.isAnimating() |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1321 | + " layer=" + highestTarget.mWinAnimator.mAnimLayer |
| 1322 | + " new layer=" + w.mWinAnimator.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1323 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1324 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1325 | // If we are currently setting up for an animation, |
| 1326 | // hold everything until we can find out what will happen. |
| 1327 | mInputMethodTargetWaitingAnim = true; |
| 1328 | mInputMethodTarget = highestTarget; |
| 1329 | return highestPos + 1; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1330 | } else if (highestTarget.mWinAnimator.isAnimating() && |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1331 | highestTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1332 | // If the window we are currently targeting is involved |
| 1333 | // with an animation, and it is on top of the next target |
| 1334 | // we will be over, then hold off on moving until |
| 1335 | // that is done. |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1336 | mInputMethodTargetWaitingAnim = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1337 | mInputMethodTarget = highestTarget; |
| 1338 | return highestPos + 1; |
| 1339 | } |
| 1340 | } |
| 1341 | } |
| 1342 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1343 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1344 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1345 | if (w != null) { |
| 1346 | if (willMove) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1347 | if (DEBUG_INPUT_METHOD) Slog.w(TAG, "Moving IM target from " + curTarget + " to " |
| 1348 | + w + (HIDE_STACK_CRAWLS ? "" : " Callers=" + Debug.getCallers(4))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1349 | mInputMethodTarget = w; |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1350 | mInputMethodTargetWaitingAnim = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1351 | if (w.mAppToken != null) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1352 | setInputMethodAnimLayerAdjustment(w.mAppToken.mAppAnimator.animLayerAdjustment); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1353 | } else { |
| 1354 | setInputMethodAnimLayerAdjustment(0); |
| 1355 | } |
| 1356 | } |
| 1357 | return i+1; |
| 1358 | } |
| 1359 | if (willMove) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1360 | if (DEBUG_INPUT_METHOD) Slog.w(TAG, "Moving IM target from " + curTarget + " to null." |
| 1361 | + (HIDE_STACK_CRAWLS ? "" : " Callers=" + Debug.getCallers(4))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1362 | mInputMethodTarget = null; |
| 1363 | setInputMethodAnimLayerAdjustment(0); |
| 1364 | } |
| 1365 | return -1; |
| 1366 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1368 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1369 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1370 | if (pos >= 0) { |
| 1371 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1372 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1373 | TAG, "Adding input method window " + win + " at " + pos); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1374 | // TODO(multidisplay): IMEs are only supported on the default display. |
| 1375 | getDefaultWindowList().add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1376 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | moveInputMethodDialogsLocked(pos+1); |
| 1378 | return; |
| 1379 | } |
| 1380 | win.mTargetAppToken = null; |
| 1381 | addWindowToListInOrderLocked(win, true); |
| 1382 | moveInputMethodDialogsLocked(pos); |
| 1383 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1384 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1385 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1386 | 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] | 1387 | mInputMethodAnimLayerAdjustment = adj; |
| 1388 | WindowState imw = mInputMethodWindow; |
| 1389 | if (imw != null) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1390 | imw.mWinAnimator.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1391 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1392 | + " anim layer: " + imw.mWinAnimator.mAnimLayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1393 | int wi = imw.mChildWindows.size(); |
| 1394 | while (wi > 0) { |
| 1395 | wi--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1396 | WindowState cw = imw.mChildWindows.get(wi); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1397 | cw.mWinAnimator.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1398 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1399 | + " anim layer: " + cw.mWinAnimator.mAnimLayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1400 | } |
| 1401 | } |
| 1402 | int di = mInputMethodDialogs.size(); |
| 1403 | while (di > 0) { |
| 1404 | di --; |
| 1405 | imw = mInputMethodDialogs.get(di); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1406 | imw.mWinAnimator.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1407 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1408 | + " anim layer: " + imw.mWinAnimator.mAnimLayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1409 | } |
| 1410 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1412 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1413 | WindowList windows = win.getWindowList(); |
| 1414 | int wpos = windows.indexOf(win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1415 | if (wpos >= 0) { |
| 1416 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1417 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1418 | windows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1419 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1420 | int NC = win.mChildWindows.size(); |
| 1421 | while (NC > 0) { |
| 1422 | NC--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1423 | WindowState cw = win.mChildWindows.get(NC); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1424 | int cpos = windows.indexOf(cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | if (cpos >= 0) { |
| 1426 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1427 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1428 | + cpos + ": " + cw); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1429 | windows.remove(cpos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1430 | } |
| 1431 | } |
| 1432 | } |
| 1433 | return interestingPos; |
| 1434 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1436 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1437 | addWindowToListInOrderLocked(win, false); |
| 1438 | // This is a hack to get all of the child windows added as well |
| 1439 | // at the right position. Child windows should be rare and |
| 1440 | // this case should be rare, so it shouldn't be that big a deal. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1441 | WindowList windows = win.getWindowList(); |
| 1442 | int wpos = windows.indexOf(win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1443 | if (wpos >= 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1444 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos + ": " + win); |
| 1445 | windows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1446 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1447 | reAddWindowLocked(wpos, win); |
| 1448 | } |
| 1449 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1450 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1451 | void logWindowList(final WindowList windows, String prefix) { |
| 1452 | int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1453 | while (N > 0) { |
| 1454 | N--; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1455 | Slog.v(TAG, prefix + "#" + N + ": " + windows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1456 | } |
| 1457 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1458 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1459 | void moveInputMethodDialogsLocked(int pos) { |
| 1460 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1461 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1462 | // TODO(multidisplay): IMEs are only supported on the default display. |
| 1463 | WindowList windows = getDefaultWindowList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1464 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1465 | 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] | 1466 | for (int i=0; i<N; i++) { |
| 1467 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1468 | } |
| 1469 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1470 | Slog.v(TAG, "Window list w/pos=" + pos); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1471 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1472 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1473 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1474 | if (pos >= 0) { |
| 1475 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1476 | if (pos < windows.size()) { |
| 1477 | WindowState wp = windows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1478 | if (wp == mInputMethodWindow) { |
| 1479 | pos++; |
| 1480 | } |
| 1481 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1482 | 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] | 1483 | for (int i=0; i<N; i++) { |
| 1484 | WindowState win = dialogs.get(i); |
| 1485 | win.mTargetAppToken = targetAppToken; |
| 1486 | pos = reAddWindowLocked(pos, win); |
| 1487 | } |
| 1488 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1489 | Slog.v(TAG, "Final window list:"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1490 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1491 | } |
| 1492 | return; |
| 1493 | } |
| 1494 | for (int i=0; i<N; i++) { |
| 1495 | WindowState win = dialogs.get(i); |
| 1496 | win.mTargetAppToken = null; |
| 1497 | reAddWindowToListInOrderLocked(win); |
| 1498 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1499 | Slog.v(TAG, "No IM target, final list:"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1500 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1501 | } |
| 1502 | } |
| 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 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1506 | final WindowState imWin = mInputMethodWindow; |
| 1507 | final int DN = mInputMethodDialogs.size(); |
| 1508 | if (imWin == null && DN == 0) { |
| 1509 | return false; |
| 1510 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1511 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1512 | // TODO(multidisplay): IMEs are only supported on the default display. |
| 1513 | WindowList windows = getDefaultWindowList(); |
| 1514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1515 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1516 | if (imPos >= 0) { |
| 1517 | // In this case, the input method windows are to be placed |
| 1518 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | // First check to see if the input method windows are already |
| 1521 | // located here, and contiguous. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1522 | final int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1523 | WindowState firstImWin = imPos < N |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1524 | ? windows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1525 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1526 | // Figure out the actual input method window that should be |
| 1527 | // at the bottom of their stack. |
| 1528 | WindowState baseImWin = imWin != null |
| 1529 | ? imWin : mInputMethodDialogs.get(0); |
| 1530 | if (baseImWin.mChildWindows.size() > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1531 | WindowState cw = baseImWin.mChildWindows.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1532 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1533 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1535 | if (firstImWin == baseImWin) { |
| 1536 | // The windows haven't moved... but are they still contiguous? |
| 1537 | // First find the top IM window. |
| 1538 | int pos = imPos+1; |
| 1539 | while (pos < N) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1540 | if (!(windows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1541 | break; |
| 1542 | } |
| 1543 | pos++; |
| 1544 | } |
| 1545 | pos++; |
| 1546 | // Now there should be no more input method windows above. |
| 1547 | while (pos < N) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1548 | if ((windows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1549 | break; |
| 1550 | } |
| 1551 | pos++; |
| 1552 | } |
| 1553 | if (pos >= N) { |
| 1554 | // All is good! |
| 1555 | return false; |
| 1556 | } |
| 1557 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1558 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1559 | if (imWin != null) { |
| 1560 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1561 | Slog.v(TAG, "Moving IM from " + imPos); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1562 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1563 | } |
| 1564 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1565 | if (DEBUG_INPUT_METHOD) { |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1566 | Slog.v(TAG, "List after removing with new pos " + imPos + ":"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1567 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1568 | } |
| 1569 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1570 | reAddWindowLocked(imPos, imWin); |
| 1571 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1572 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1573 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | } |
| 1575 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1576 | } else { |
| 1577 | moveInputMethodDialogsLocked(imPos); |
| 1578 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1579 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1580 | } else { |
| 1581 | // In this case, the input method windows go in a fixed layer, |
| 1582 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1583 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1584 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1585 | 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] | 1586 | tmpRemoveWindowLocked(0, imWin); |
| 1587 | imWin.mTargetAppToken = null; |
| 1588 | reAddWindowToListInOrderLocked(imWin); |
| 1589 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1590 | Slog.v(TAG, "List with no IM target:"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1591 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1592 | } |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 1593 | if (DN > 0) moveInputMethodDialogsLocked(-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1594 | } else { |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 1595 | moveInputMethodDialogsLocked(-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1596 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1600 | if (needAssignLayers) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1601 | assignLayersLocked(windows); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1602 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1603 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1604 | return true; |
| 1605 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1606 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1607 | void adjustInputMethodDialogsLocked() { |
| 1608 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1609 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1610 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1611 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Craig Mautner | ad3a9bb | 2012-03-09 11:31:06 -0800 | [diff] [blame] | 1612 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target " + wallpaperTarget + ", obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1613 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1614 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1615 | ? wallpaperTarget.mAppToken.mAppAnimator.animation : null) |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1616 | + " upper=" + mUpperWallpaperTarget |
| 1617 | + " lower=" + mLowerWallpaperTarget); |
| 1618 | return (wallpaperTarget != null |
| 1619 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1620 | && wallpaperTarget.mAppToken.mAppAnimator.animation != null))) |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1621 | || mUpperWallpaperTarget != null |
| 1622 | || mLowerWallpaperTarget != null; |
| 1623 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1624 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1625 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1626 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1627 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1628 | int adjustWallpaperWindowsLocked() { |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 1629 | mInnerFields.mWallpaperMayChange = false; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1630 | int changed = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1631 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1632 | // TODO(multidisplay): Wallpapers on main screen only. |
| 1633 | final DisplayInfo displayInfo = getDefaultDisplayContent().getDisplayInfo(); |
| 1634 | final int dw = displayInfo.appWidth; |
| 1635 | final int dh = displayInfo.appHeight; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1636 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1637 | // First find top-most window that has asked to be on top of the |
| 1638 | // wallpaper; all wallpapers go behind it. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1639 | final WindowList windows = getDefaultWindowList(); |
| 1640 | int N = windows.size(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1641 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1642 | WindowState foundW = null; |
| 1643 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1644 | WindowState topCurW = null; |
| 1645 | int topCurI = 0; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1646 | int windowDetachedI = -1; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1647 | int i = N; |
| 1648 | while (i > 0) { |
| 1649 | i--; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1650 | w = windows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1651 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1652 | if (topCurW == null) { |
| 1653 | topCurW = w; |
| 1654 | topCurI = i; |
| 1655 | } |
| 1656 | continue; |
| 1657 | } |
| 1658 | topCurW = null; |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 1659 | if (w != mWindowDetachedWallpaper && w.mAppToken != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1660 | // If this window's app token is hidden and not animating, |
| 1661 | // it is of no interest to us. |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1662 | if (w.mAppToken.hidden && w.mAppToken.mAppAnimator.animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1663 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Craig Mautner | 1d961d4 | 2012-05-27 12:02:11 -0700 | [diff] [blame] | 1664 | "Skipping hidden and not animating token: " + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1665 | continue; |
| 1666 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1667 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1668 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win #" + i + " " + w + ": readyfordisplay=" |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1669 | + w.isReadyForDisplay() + " mDrawState=" + w.mWinAnimator.mDrawState); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1670 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 1671 | && (mWallpaperTarget == w || w.isDrawnLw())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1672 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1673 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1674 | foundW = w; |
| 1675 | foundI = i; |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 1676 | if (w == mWallpaperTarget && w.mWinAnimator.isAnimating()) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1677 | // The current wallpaper target is animating, so we'll |
| 1678 | // look behind it for another possible target and figure |
| 1679 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1680 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1681 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1682 | continue; |
| 1683 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1684 | break; |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 1685 | } else if (w == mWindowDetachedWallpaper) { |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1686 | windowDetachedI = i; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1687 | } |
| 1688 | } |
| 1689 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1690 | if (foundW == null && windowDetachedI >= 0) { |
| 1691 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 1692 | "Found animating detached wallpaper activity: #" + i + "=" + w); |
| 1693 | foundW = w; |
| 1694 | foundI = windowDetachedI; |
| 1695 | } |
| 1696 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1697 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1698 | // If we are currently waiting for an app transition, and either |
| 1699 | // the current target or the next target are involved with it, |
| 1700 | // then hold off on doing anything with the wallpaper. |
| 1701 | // Note that we are checking here for just whether the target |
| 1702 | // is part of an app token... which is potentially overly aggressive |
| 1703 | // (the app token may not be involved in the transition), but good |
| 1704 | // enough (we'll just wait until whatever transition is pending |
| 1705 | // executes). |
| 1706 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1707 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1708 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1709 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1710 | } |
| 1711 | if (foundW != null && foundW.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1712 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1713 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1714 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1715 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1716 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1717 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1718 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1719 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1720 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1721 | + " oldTarget: " + mWallpaperTarget); |
| 1722 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1723 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1724 | mLowerWallpaperTarget = null; |
| 1725 | mUpperWallpaperTarget = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1726 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1727 | WindowState oldW = mWallpaperTarget; |
| 1728 | mWallpaperTarget = foundW; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1729 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1730 | // Now what is happening... if the current and new targets are |
| 1731 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1732 | if (foundW != null && oldW != null) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1733 | boolean oldAnim = oldW.mWinAnimator.mAnimation != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1734 | || (oldW.mAppToken != null |
| 1735 | && oldW.mAppToken.mAppAnimator.animation != null); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1736 | boolean foundAnim = foundW.mWinAnimator.mAnimation != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1737 | || (foundW.mAppToken != null && |
| 1738 | foundW.mAppToken.mAppAnimator.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1739 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1740 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1741 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1742 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1743 | if (foundAnim && oldAnim) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1744 | int oldI = windows.indexOf(oldW); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1745 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1746 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1747 | } |
| 1748 | if (oldI >= 0) { |
| 1749 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1750 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1751 | + "=" + oldW + "; new#" + foundI |
| 1752 | + "=" + foundW); |
| 1753 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1754 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1755 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1756 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1757 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1758 | Slog.v(TAG, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1759 | } |
| 1760 | mWallpaperTarget = oldW; |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1761 | foundW = oldW; |
| 1762 | foundI = oldI; |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 1763 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1764 | // Now set the upper and lower wallpaper targets |
| 1765 | // correctly, and make sure that we are positioning |
| 1766 | // the wallpaper below the lower. |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1767 | else if (foundI > oldI) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1768 | // The new target is on top of the old one. |
| 1769 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1770 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1771 | } |
| 1772 | mUpperWallpaperTarget = foundW; |
| 1773 | mLowerWallpaperTarget = oldW; |
| 1774 | foundW = oldW; |
| 1775 | foundI = oldI; |
| 1776 | } else { |
| 1777 | // The new target is below the old one. |
| 1778 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1779 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1780 | } |
| 1781 | mUpperWallpaperTarget = oldW; |
| 1782 | mLowerWallpaperTarget = foundW; |
| 1783 | } |
| 1784 | } |
| 1785 | } |
| 1786 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1787 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1788 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1789 | // Is it time to stop animating? |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1790 | boolean lowerAnimating = mLowerWallpaperTarget.mWinAnimator.mAnimation != null |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1791 | || (mLowerWallpaperTarget.mAppToken != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1792 | && mLowerWallpaperTarget.mAppToken.mAppAnimator.animation != null); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1793 | boolean upperAnimating = mUpperWallpaperTarget.mWinAnimator.mAnimation != null |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1794 | || (mUpperWallpaperTarget.mAppToken != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1795 | && mUpperWallpaperTarget.mAppToken.mAppAnimator.animation != null); |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1796 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1797 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1798 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1799 | } |
| 1800 | mLowerWallpaperTarget = null; |
| 1801 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1802 | } |
| 1803 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1804 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1805 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1806 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1807 | // The window is visible to the compositor... but is it visible |
| 1808 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1809 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1810 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1811 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1812 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1813 | // its layer adjustment. Only do this if we are not transfering |
| 1814 | // between two wallpaper targets. |
| 1815 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1816 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1817 | ? foundW.mAppToken.mAppAnimator.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1818 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1819 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1820 | * TYPE_LAYER_MULTIPLIER |
| 1821 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1822 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1823 | // Now w is the window we are supposed to be behind... but we |
| 1824 | // 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] | 1825 | // AND any starting window associated with it, AND below the |
| 1826 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1827 | while (foundI > 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1828 | WindowState wb = windows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1829 | if (wb.mBaseLayer < maxLayer && |
| 1830 | wb.mAttachedWindow != foundW && |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1831 | (foundW.mAttachedWindow == null || |
| 1832 | wb.mAttachedWindow != foundW.mAttachedWindow) && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1833 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1834 | foundW.mToken == null || wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1835 | // This window is not related to the previous one in any |
| 1836 | // interesting way, so stop here. |
| 1837 | break; |
| 1838 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1839 | foundW = wb; |
| 1840 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1841 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1842 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1843 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1844 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1845 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1846 | if (foundW == null && topCurW != null) { |
| 1847 | // There is no wallpaper target, so it goes at the bottom. |
| 1848 | // We will assume it is the same place as last time, if known. |
| 1849 | foundW = topCurW; |
| 1850 | foundI = topCurI+1; |
| 1851 | } else { |
| 1852 | // Okay i is the position immediately above the wallpaper. Look at |
| 1853 | // what is below it for later. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1854 | foundW = foundI > 0 ? windows.get(foundI-1) : null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1855 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1856 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1857 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1858 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1859 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1860 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1861 | } |
| 1862 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1863 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1864 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1865 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1866 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1867 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1868 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1869 | // are correctly placed. |
| 1870 | int curTokenIndex = mWallpaperTokens.size(); |
| 1871 | while (curTokenIndex > 0) { |
| 1872 | curTokenIndex--; |
| 1873 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1874 | if (token.hidden == visible) { |
| 1875 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1876 | token.hidden = !visible; |
| 1877 | // Need to do a layout to ensure the wallpaper now has the |
| 1878 | // correct size. |
| 1879 | mLayoutNeeded = true; |
| 1880 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1881 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1882 | int curWallpaperIndex = token.windows.size(); |
| 1883 | while (curWallpaperIndex > 0) { |
| 1884 | curWallpaperIndex--; |
| 1885 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1886 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1887 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1888 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1889 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1890 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1891 | // First, make sure the client has the current visibility |
| 1892 | // state. |
Craig Mautner | 507a2ee | 2012-06-13 08:39:38 -0700 | [diff] [blame] | 1893 | dispatchWallpaperVisibility(wallpaper, visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1894 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1895 | wallpaper.mWinAnimator.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 1896 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "adjustWallpaper win " |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1897 | + wallpaper + " anim layer: " + wallpaper.mWinAnimator.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1898 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1899 | // First, if this window is at the current index, then all |
| 1900 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1901 | if (wallpaper == foundW) { |
| 1902 | foundI--; |
| 1903 | foundW = foundI > 0 |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1904 | ? windows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1905 | continue; |
| 1906 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1907 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1908 | // The window didn't match... the current wallpaper window, |
| 1909 | // wherever it is, is in the wrong place, so make sure it is |
| 1910 | // not in the list. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1911 | int oldIndex = windows.indexOf(wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1912 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1913 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1914 | + oldIndex + ": " + wallpaper); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1915 | windows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1916 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1917 | if (oldIndex < foundI) { |
| 1918 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1919 | } |
| 1920 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1921 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1922 | // Now stick it in. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1923 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1924 | Slog.v(TAG, "Moving wallpaper " + wallpaper |
| 1925 | + " from " + oldIndex + " to " + foundI); |
| 1926 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1927 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1928 | windows.add(foundI, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1929 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1930 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1931 | } |
| 1932 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1933 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1934 | return changed; |
| 1935 | } |
| 1936 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1937 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1938 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1939 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1940 | mWallpaperAnimLayerAdjustment = adj; |
| 1941 | int curTokenIndex = mWallpaperTokens.size(); |
| 1942 | while (curTokenIndex > 0) { |
| 1943 | curTokenIndex--; |
| 1944 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1945 | int curWallpaperIndex = token.windows.size(); |
| 1946 | while (curWallpaperIndex > 0) { |
| 1947 | curWallpaperIndex--; |
| 1948 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1949 | wallpaper.mWinAnimator.mAnimLayer = wallpaper.mLayer + adj; |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 1950 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "setWallpaper win " |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1951 | + wallpaper + " anim layer: " + wallpaper.mWinAnimator.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1952 | } |
| 1953 | } |
| 1954 | } |
| 1955 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1956 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1957 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1958 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1959 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1960 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1961 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 1962 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1963 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1964 | changed = wallpaperWin.mXOffset != offset; |
| 1965 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1966 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1967 | + wallpaperWin + " x: " + offset); |
| 1968 | wallpaperWin.mXOffset = offset; |
| 1969 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1970 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1971 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1972 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1973 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1974 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1975 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1976 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1977 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1978 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1979 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1980 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1981 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1982 | + wallpaperWin + " y: " + offset); |
| 1983 | changed = true; |
| 1984 | wallpaperWin.mYOffset = offset; |
| 1985 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1986 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1987 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1988 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1989 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1990 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1991 | |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 1992 | if (rawChanged && (wallpaperWin.mAttrs.privateFlags & |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 1993 | WindowManager.LayoutParams.PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS) != 0) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1994 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1995 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1996 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1997 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1998 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1999 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2000 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2001 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2002 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 2003 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2004 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2005 | if (mWaitingOnWallpaper != null) { |
| 2006 | long start = SystemClock.uptimeMillis(); |
| 2007 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 2008 | < start) { |
| 2009 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2010 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2011 | "Waiting for offset complete..."); |
| 2012 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 2013 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2014 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2015 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2016 | if ((start+WALLPAPER_TIMEOUT) |
| 2017 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2018 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2019 | + wallpaperWin); |
| 2020 | mLastWallpaperTimeoutTime = start; |
| 2021 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2022 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2023 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2024 | } |
| 2025 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2026 | } catch (RemoteException e) { |
| 2027 | } |
| 2028 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2029 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2030 | return changed; |
| 2031 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2032 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2033 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2034 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2035 | if (mWaitingOnWallpaper != null && |
| 2036 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2037 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2038 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2039 | } |
| 2040 | } |
| 2041 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2042 | |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 2043 | void updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2044 | final DisplayContent displayContent = changingTarget.mDisplayContent; |
| 2045 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 2046 | final int dw = displayInfo.appWidth; |
| 2047 | final int dh = displayInfo.appHeight; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2048 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2049 | WindowState target = mWallpaperTarget; |
| 2050 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2051 | if (target.mWallpaperX >= 0) { |
| 2052 | mLastWallpaperX = target.mWallpaperX; |
| 2053 | } else if (changingTarget.mWallpaperX >= 0) { |
| 2054 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 2055 | } |
| 2056 | if (target.mWallpaperY >= 0) { |
| 2057 | mLastWallpaperY = target.mWallpaperY; |
| 2058 | } else if (changingTarget.mWallpaperY >= 0) { |
| 2059 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 2060 | } |
| 2061 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2062 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2063 | int curTokenIndex = mWallpaperTokens.size(); |
| 2064 | while (curTokenIndex > 0) { |
| 2065 | curTokenIndex--; |
| 2066 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2067 | int curWallpaperIndex = token.windows.size(); |
| 2068 | while (curWallpaperIndex > 0) { |
| 2069 | curWallpaperIndex--; |
| 2070 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2071 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2072 | WindowStateAnimator winAnimator = wallpaper.mWinAnimator; |
| 2073 | winAnimator.computeShownFrameLocked(); |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 2074 | // No need to lay out the windows - we can just set the wallpaper position |
| 2075 | // directly. |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 2076 | // TODO(cmautner): Don't move this from here, just lock the WindowAnimator. |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2077 | if (winAnimator.mSurfaceX != wallpaper.mShownFrame.left |
| 2078 | || winAnimator.mSurfaceY != wallpaper.mShownFrame.top) { |
Craig Mautner | 12670b5 | 2012-07-03 19:15:35 -0700 | [diff] [blame] | 2079 | winAnimator.setWallpaperOffset((int) wallpaper.mShownFrame.left, |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 2080 | (int) wallpaper.mShownFrame.top); |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 2081 | } |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2082 | // We only want to be synchronous with one wallpaper. |
| 2083 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2084 | } |
| 2085 | } |
| 2086 | } |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2087 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2088 | |
Craig Mautner | 507a2ee | 2012-06-13 08:39:38 -0700 | [diff] [blame] | 2089 | /** |
| 2090 | * Check wallpaper for visiblity change and notify window if so. |
| 2091 | * @param wallpaper The wallpaper to test and notify. |
| 2092 | * @param visible Current visibility. |
| 2093 | */ |
| 2094 | void dispatchWallpaperVisibility(final WindowState wallpaper, final boolean visible) { |
| 2095 | if (wallpaper.mWallpaperVisible != visible) { |
| 2096 | wallpaper.mWallpaperVisible = visible; |
| 2097 | try { |
| 2098 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| 2099 | "Updating visibility of wallpaper " + wallpaper |
| 2100 | + ": " + visible + " Callers=" + Debug.getCallers(2)); |
| 2101 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2102 | } catch (RemoteException e) { |
| 2103 | } |
| 2104 | } |
| 2105 | } |
| 2106 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2107 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2108 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2109 | final DisplayContent displayContent = mWallpaperTarget.mDisplayContent; |
| 2110 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 2111 | final int dw = displayInfo.appWidth; |
| 2112 | final int dh = displayInfo.appHeight; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2113 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2114 | int curTokenIndex = mWallpaperTokens.size(); |
| 2115 | while (curTokenIndex > 0) { |
| 2116 | curTokenIndex--; |
| 2117 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2118 | if (token.hidden == visible) { |
| 2119 | token.hidden = !visible; |
| 2120 | // Need to do a layout to ensure the wallpaper now has the |
| 2121 | // correct size. |
| 2122 | mLayoutNeeded = true; |
| 2123 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2124 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2125 | int curWallpaperIndex = token.windows.size(); |
| 2126 | while (curWallpaperIndex > 0) { |
| 2127 | curWallpaperIndex--; |
| 2128 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2129 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2130 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2131 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2132 | |
Craig Mautner | 507a2ee | 2012-06-13 08:39:38 -0700 | [diff] [blame] | 2133 | dispatchWallpaperVisibility(wallpaper, visible); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2134 | } |
| 2135 | } |
| 2136 | } |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 2137 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2138 | public int addWindow(Session session, IWindow client, int seq, |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 2139 | WindowManager.LayoutParams attrs, int viewVisibility, int displayId, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2140 | Rect outContentInsets, InputChannel outInputChannel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2141 | int res = mPolicy.checkAddPermission(attrs); |
| 2142 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2143 | return res; |
| 2144 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2146 | boolean reportNewConfig = false; |
| 2147 | WindowState attachedWindow = null; |
| 2148 | WindowState win = null; |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2149 | long origId; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2151 | synchronized(mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2152 | if (mDisplay == null) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2153 | throw new IllegalStateException("Display has not been initialialized"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2154 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2155 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2156 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2157 | Slog.w(TAG, "Window " + client + " is already added"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2158 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 2159 | } |
| 2160 | |
| 2161 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2162 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2163 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2164 | 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] | 2165 | + attrs.token + ". Aborting."); |
| 2166 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2167 | } |
| 2168 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2169 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2170 | 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] | 2171 | + attrs.token + ". Aborting."); |
| 2172 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2173 | } |
| 2174 | } |
| 2175 | |
| 2176 | boolean addToken = false; |
| 2177 | WindowToken token = mTokenMap.get(attrs.token); |
| 2178 | if (token == null) { |
| 2179 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2180 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2181 | 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] | 2182 | + attrs.token + ". Aborting."); |
| 2183 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2184 | } |
| 2185 | if (attrs.type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2186 | 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] | 2187 | + attrs.token + ". Aborting."); |
| 2188 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2189 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2190 | if (attrs.type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2191 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2192 | + attrs.token + ". Aborting."); |
| 2193 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2194 | } |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 2195 | if (attrs.type == TYPE_DREAM) { |
| 2196 | Slog.w(TAG, "Attempted to add Dream window with unknown token " |
| 2197 | + attrs.token + ". Aborting."); |
| 2198 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2199 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2200 | token = new WindowToken(this, attrs.token, -1, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2201 | addToken = true; |
| 2202 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2203 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 2204 | AppWindowToken atoken = token.appWindowToken; |
| 2205 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2206 | 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] | 2207 | + token + ". Aborting."); |
| 2208 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 2209 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2210 | 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] | 2211 | + token + ". Aborting."); |
| 2212 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2213 | } |
| 2214 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 2215 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2216 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2217 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 2218 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 2219 | } |
| 2220 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 2221 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2222 | 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] | 2223 | + attrs.token + ". Aborting."); |
| 2224 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2225 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2226 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2227 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2228 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2229 | + attrs.token + ". Aborting."); |
| 2230 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2231 | } |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 2232 | } else if (attrs.type == TYPE_DREAM) { |
| 2233 | if (token.windowType != TYPE_DREAM) { |
| 2234 | Slog.w(TAG, "Attempted to add Dream window with bad token " |
| 2235 | + attrs.token + ". Aborting."); |
| 2236 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2237 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2238 | } |
| 2239 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2240 | final DisplayContent displayContent = getDisplayContent(displayId); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2241 | win = new WindowState(this, session, client, token, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2242 | attachedWindow, seq, attrs, viewVisibility, displayContent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2243 | if (win.mDeathRecipient == null) { |
| 2244 | // Client has apparently died, so there is no reason to |
| 2245 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2246 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2247 | + " that is dead, aborting."); |
| 2248 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2249 | } |
| 2250 | |
| 2251 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2253 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2254 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2255 | return res; |
| 2256 | } |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 2257 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2258 | if (outInputChannel != null && (attrs.inputFeatures |
| 2259 | & WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2260 | String name = win.makeInputChannelName(); |
| 2261 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2262 | win.setInputChannel(inputChannels[0]); |
Jeff Brown | 0a0ab12 | 2011-08-12 18:08:08 -0700 | [diff] [blame] | 2263 | inputChannels[1].transferTo(outInputChannel); |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 2264 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 2265 | mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2266 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2267 | |
| 2268 | // From now on, no exceptions or errors allowed! |
| 2269 | |
| 2270 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2271 | |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2272 | origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2274 | if (addToken) { |
| 2275 | mTokenMap.put(attrs.token, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2276 | } |
| 2277 | win.attach(); |
| 2278 | mWindowMap.put(client.asBinder(), win); |
| 2279 | |
| 2280 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2281 | token.appWindowToken != null) { |
| 2282 | token.appWindowToken.startingWindow = win; |
Craig Mautner | 38b2478 | 2012-07-02 16:21:28 -0700 | [diff] [blame] | 2283 | if (DEBUG_STARTING_WINDOW) Slog.v (TAG, "addWindow: " + token.appWindowToken |
| 2284 | + " startingWindow=" + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2288 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2289 | if (attrs.type == TYPE_INPUT_METHOD) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 2290 | win.mGivenInsetsPending = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2291 | mInputMethodWindow = win; |
| 2292 | addInputMethodWindowToListLocked(win); |
| 2293 | imMayMove = false; |
| 2294 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2295 | mInputMethodDialogs.add(win); |
| 2296 | addWindowToListInOrderLocked(win, true); |
| 2297 | adjustInputMethodDialogsLocked(); |
| 2298 | imMayMove = false; |
| 2299 | } else { |
| 2300 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2301 | if (attrs.type == TYPE_WALLPAPER) { |
| 2302 | mLastWallpaperTimeoutTime = 0; |
| 2303 | adjustWallpaperWindowsLocked(); |
| 2304 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2305 | adjustWallpaperWindowsLocked(); |
| 2306 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2307 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2308 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2309 | win.mWinAnimator.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2310 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2311 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2313 | if (mInTouchMode) { |
| 2314 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2315 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 2316 | if (win.mAppToken == null || !win.mAppToken.clientHidden) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2317 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2318 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2319 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2320 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 2321 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2322 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2323 | if (win.canReceiveKeys()) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2324 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS, |
| 2325 | false /*updateInputWindows*/); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2326 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2327 | imMayMove = false; |
| 2328 | } |
| 2329 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2331 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2332 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2333 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2334 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2335 | assignLayersLocked(displayContent.getWindowList()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2336 | // Don't do layout here, the window must call |
| 2337 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2338 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2339 | //dump(); |
| 2340 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2341 | if (focusChanged) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2342 | finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2343 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2344 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2345 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2346 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2347 | TAG, "New client " + client.asBinder() |
| 2348 | + ": window=" + win); |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 2349 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2350 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2351 | reportNewConfig = true; |
| 2352 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2353 | } |
| 2354 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2355 | if (reportNewConfig) { |
| 2356 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2357 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2359 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2360 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2361 | return res; |
| 2362 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2364 | public void removeWindow(Session session, IWindow client) { |
| 2365 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2366 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2367 | if (win == null) { |
| 2368 | return; |
| 2369 | } |
| 2370 | removeWindowLocked(session, win); |
| 2371 | } |
| 2372 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2374 | public void removeWindowLocked(Session session, WindowState win) { |
| 2375 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2376 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2377 | TAG, "Remove " + win + " client=" |
| 2378 | + Integer.toHexString(System.identityHashCode( |
| 2379 | win.mClient.asBinder())) |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2380 | + ", surface=" + win.mWinAnimator.mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2381 | |
| 2382 | final long origId = Binder.clearCallingIdentity(); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 2383 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2384 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2385 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2386 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2387 | TAG, "Remove " + win + ": mSurface=" + win.mWinAnimator.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2388 | + " mExiting=" + win.mExiting |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2389 | + " isAnimating=" + win.mWinAnimator.isAnimating() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2390 | + " app-animation=" |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 2391 | + (win.mAppToken != null ? win.mAppToken.mAppAnimator.animation : null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2392 | + " inPendingTransaction=" |
| 2393 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2394 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2395 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2396 | boolean wasVisible = false; |
| 2397 | // First, see if we need to run an animation. If we do, we have |
| 2398 | // to hold off on removing the window until the animation is done. |
| 2399 | // If the display is frozen, just remove immediately, since the |
| 2400 | // animation wouldn't be seen. |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2401 | if (win.mHasSurface && okToDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | // If we are not currently running the exit animation, we |
| 2403 | // need to see about starting one. |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 2404 | wasVisible = win.isWinVisibleLw(); |
| 2405 | if (wasVisible) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2406 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2407 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 2408 | if (win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2409 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2410 | } |
| 2411 | // Try starting an animation. |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2412 | if (win.mWinAnimator.applyAnimationLocked(transit, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2413 | win.mExiting = true; |
| 2414 | } |
| 2415 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2416 | if (win.mExiting || win.mWinAnimator.isAnimating()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2417 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2418 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2419 | win.mExiting = true; |
| 2420 | win.mRemoveOnExit = true; |
| 2421 | mLayoutNeeded = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2422 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2423 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2424 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2425 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2426 | if (win.mAppToken != null) { |
| 2427 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2428 | } |
| 2429 | //dump(); |
| 2430 | Binder.restoreCallingIdentity(origId); |
| 2431 | return; |
| 2432 | } |
| 2433 | } |
| 2434 | |
| 2435 | removeWindowInnerLocked(session, win); |
| 2436 | // Removing a visible window will effect the computed orientation |
| 2437 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2438 | if (wasVisible && computeForcedAppOrientationLocked() |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2439 | != mForcedAppOrientation |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2440 | && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2441 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2442 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2443 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2444 | Binder.restoreCallingIdentity(origId); |
| 2445 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2447 | private void removeWindowInnerLocked(Session session, WindowState win) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2448 | if (win.mRemoved) { |
| 2449 | // Nothing to do. |
| 2450 | return; |
| 2451 | } |
| 2452 | |
| 2453 | for (int i=win.mChildWindows.size()-1; i>=0; i--) { |
| 2454 | WindowState cwin = win.mChildWindows.get(i); |
| 2455 | Slog.w(TAG, "Force-removing child win " + cwin + " from container " |
| 2456 | + win); |
| 2457 | removeWindowInnerLocked(cwin.mSession, cwin); |
| 2458 | } |
| 2459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2460 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2461 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2462 | if (mInputMethodTarget == win) { |
| 2463 | moveInputMethodWindowsIfNeededLocked(false); |
| 2464 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2465 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2466 | if (false) { |
| 2467 | RuntimeException e = new RuntimeException("here"); |
| 2468 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2469 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2470 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2471 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2472 | mPolicy.removeWindowLw(win); |
| 2473 | win.removeLocked(); |
| 2474 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2475 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2476 | mWindowMap.remove(win.mClient.asBinder()); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2477 | |
| 2478 | final WindowList windows = win.getWindowList(); |
| 2479 | windows.remove(win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2480 | mPendingRemove.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2481 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2482 | 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] | 2483 | |
| 2484 | if (mInputMethodWindow == win) { |
| 2485 | mInputMethodWindow = null; |
| 2486 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2487 | mInputMethodDialogs.remove(win); |
| 2488 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | final WindowToken token = win.mToken; |
| 2491 | final AppWindowToken atoken = win.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2492 | 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] | 2493 | token.windows.remove(win); |
| 2494 | if (atoken != null) { |
| 2495 | atoken.allAppWindows.remove(win); |
| 2496 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2497 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2498 | TAG, "**** Removing window " + win + ": count=" |
| 2499 | + token.windows.size()); |
| 2500 | if (token.windows.size() == 0) { |
| 2501 | if (!token.explicit) { |
| 2502 | mTokenMap.remove(token.token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2503 | } else if (atoken != null) { |
| 2504 | atoken.firstWindowDrawn = false; |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | if (atoken != null) { |
| 2509 | if (atoken.startingWindow == win) { |
Craig Mautner | 38b2478 | 2012-07-02 16:21:28 -0700 | [diff] [blame] | 2510 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Nulling startingWindow " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2511 | atoken.startingWindow = null; |
| 2512 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2513 | // If this is the last window and we had requested a starting |
| 2514 | // transition window, well there is no point now. |
Craig Mautner | 38b2478 | 2012-07-02 16:21:28 -0700 | [diff] [blame] | 2515 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Nulling last startingWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2516 | atoken.startingData = null; |
| 2517 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2518 | // If this is the last window except for a starting transition |
| 2519 | // window, we need to get rid of the starting transition. |
| 2520 | if (DEBUG_STARTING_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2521 | Slog.v(TAG, "Schedule remove starting " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2522 | + ": no more real windows"); |
| 2523 | } |
| 2524 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2525 | mH.sendMessage(m); |
| 2526 | } |
| 2527 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2528 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2529 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2530 | mLastWallpaperTimeoutTime = 0; |
| 2531 | adjustWallpaperWindowsLocked(); |
| 2532 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2533 | adjustWallpaperWindowsLocked(); |
| 2534 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2536 | if (!mInLayout) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2537 | assignLayersLocked(windows); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2538 | mLayoutNeeded = true; |
| 2539 | performLayoutAndPlaceSurfacesLocked(); |
| 2540 | if (win.mAppToken != null) { |
| 2541 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2542 | } |
| 2543 | } |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 2544 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2545 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2546 | } |
| 2547 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2548 | static void logSurface(WindowState w, String msg, RuntimeException where) { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2549 | String str = " SURFACE " + msg + ": " + w; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2550 | if (where != null) { |
| 2551 | Slog.i(TAG, str, where); |
| 2552 | } else { |
| 2553 | Slog.i(TAG, str); |
| 2554 | } |
| 2555 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2556 | |
| 2557 | static void logSurface(Surface s, String title, String msg, RuntimeException where) { |
| 2558 | String str = " SURFACE " + s + ": " + msg + " / " + title; |
| 2559 | if (where != null) { |
| 2560 | Slog.i(TAG, str, where); |
| 2561 | } else { |
| 2562 | Slog.i(TAG, str); |
| 2563 | } |
| 2564 | } |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 2565 | |
| 2566 | // TODO(cmautner): Move to WindowStateAnimator. |
| 2567 | void setTransparentRegionHint(final WindowStateAnimator winAnimator, final Region region) { |
| 2568 | mH.sendMessage(mH.obtainMessage(H.SET_TRANSPARENT_REGION, |
| 2569 | new Pair<WindowStateAnimator, Region>(winAnimator, region))); |
| 2570 | } |
| 2571 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2572 | void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2573 | long origId = Binder.clearCallingIdentity(); |
| 2574 | try { |
| 2575 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2576 | WindowState w = windowForClientLocked(session, client, false); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2577 | if ((w != null) && w.mHasSurface) { |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 2578 | setTransparentRegionHint(w.mWinAnimator, region); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2579 | } |
| 2580 | } |
| 2581 | } finally { |
| 2582 | Binder.restoreCallingIdentity(origId); |
| 2583 | } |
| 2584 | } |
| 2585 | |
| 2586 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2587 | int touchableInsets, Rect contentInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2588 | Rect visibleInsets, Region touchableRegion) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2589 | long origId = Binder.clearCallingIdentity(); |
| 2590 | try { |
| 2591 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2592 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2593 | if (w != null) { |
| 2594 | w.mGivenInsetsPending = false; |
| 2595 | w.mGivenContentInsets.set(contentInsets); |
| 2596 | w.mGivenVisibleInsets.set(visibleInsets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2597 | w.mGivenTouchableRegion.set(touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2598 | w.mTouchableInsets = touchableInsets; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2599 | if (w.mGlobalScale != 1) { |
| 2600 | w.mGivenContentInsets.scale(w.mGlobalScale); |
| 2601 | w.mGivenVisibleInsets.scale(w.mGlobalScale); |
| 2602 | w.mGivenTouchableRegion.scale(w.mGlobalScale); |
| 2603 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2604 | mLayoutNeeded = true; |
| 2605 | performLayoutAndPlaceSurfacesLocked(); |
| 2606 | } |
| 2607 | } |
| 2608 | } finally { |
| 2609 | Binder.restoreCallingIdentity(origId); |
| 2610 | } |
| 2611 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2613 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2614 | Rect outDisplayFrame) { |
| 2615 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2616 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | if (win == null) { |
| 2618 | outDisplayFrame.setEmpty(); |
| 2619 | return; |
| 2620 | } |
| 2621 | outDisplayFrame.set(win.mDisplayFrame); |
| 2622 | } |
| 2623 | } |
| 2624 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2625 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2626 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2627 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2628 | window.mWallpaperX = x; |
| 2629 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2630 | window.mWallpaperXStep = xStep; |
| 2631 | window.mWallpaperYStep = yStep; |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 2632 | updateWallpaperOffsetLocked(window, true); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2633 | } |
| 2634 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2635 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2636 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2637 | synchronized (mWindowMap) { |
| 2638 | if (mWaitingOnWallpaper != null && |
| 2639 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2640 | mWaitingOnWallpaper = null; |
| 2641 | mWindowMap.notifyAll(); |
| 2642 | } |
| 2643 | } |
| 2644 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2645 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2646 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2647 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2648 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2649 | || window == mUpperWallpaperTarget) { |
| 2650 | boolean doWait = sync; |
| 2651 | int curTokenIndex = mWallpaperTokens.size(); |
| 2652 | while (curTokenIndex > 0) { |
| 2653 | curTokenIndex--; |
| 2654 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2655 | int curWallpaperIndex = token.windows.size(); |
| 2656 | while (curWallpaperIndex > 0) { |
| 2657 | curWallpaperIndex--; |
| 2658 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2659 | try { |
| 2660 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2661 | x, y, z, extras, sync); |
| 2662 | // We only want to be synchronous with one wallpaper. |
| 2663 | sync = false; |
| 2664 | } catch (RemoteException e) { |
| 2665 | } |
| 2666 | } |
| 2667 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2668 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2669 | if (doWait) { |
| 2670 | // XXX Need to wait for result. |
| 2671 | } |
| 2672 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2673 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2674 | return null; |
| 2675 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2676 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 2677 | public void setUniverseTransformLocked(WindowState window, float alpha, |
| 2678 | float offx, float offy, float dsdx, float dtdx, float dsdy, float dtdy) { |
| 2679 | Transformation transform = window.mWinAnimator.mUniverseTransform; |
| 2680 | transform.setAlpha(alpha); |
| 2681 | Matrix matrix = transform.getMatrix(); |
| 2682 | matrix.getValues(mTmpFloats); |
| 2683 | mTmpFloats[Matrix.MTRANS_X] = offx; |
| 2684 | mTmpFloats[Matrix.MTRANS_Y] = offy; |
| 2685 | mTmpFloats[Matrix.MSCALE_X] = dsdx; |
| 2686 | mTmpFloats[Matrix.MSKEW_Y] = dtdx; |
| 2687 | mTmpFloats[Matrix.MSKEW_X] = dsdy; |
| 2688 | mTmpFloats[Matrix.MSCALE_Y] = dtdy; |
| 2689 | matrix.setValues(mTmpFloats); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2690 | final DisplayInfo displayInfo = window.mDisplayContent.getDisplayInfo(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 2691 | final RectF dispRect = new RectF(0, 0, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2692 | displayInfo.logicalWidth, displayInfo.logicalHeight); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 2693 | matrix.mapRect(dispRect); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 2694 | window.mGivenTouchableRegion.set(0, 0, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2695 | displayInfo.logicalWidth, displayInfo.logicalHeight); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 2696 | window.mGivenTouchableRegion.op((int)dispRect.left, (int)dispRect.top, |
| 2697 | (int)dispRect.right, (int)dispRect.bottom, Region.Op.DIFFERENCE); |
| 2698 | window.mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION; |
| 2699 | mLayoutNeeded = true; |
| 2700 | performLayoutAndPlaceSurfacesLocked(); |
| 2701 | } |
| 2702 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2703 | public int relayoutWindow(Session session, IWindow client, int seq, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2704 | WindowManager.LayoutParams attrs, int requestedWidth, |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2705 | int requestedHeight, int viewVisibility, int flags, |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 2706 | Rect outFrame, Rect outContentInsets, |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2707 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2708 | boolean toBeDisplayed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2709 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2710 | boolean configChanged; |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2711 | boolean surfaceChanged = false; |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 2712 | boolean animating; |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 2713 | |
| 2714 | // if they don't have this permission, mask out the status bar bits |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2715 | int systemUiVisibility = 0; |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 2716 | if (attrs != null) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2717 | systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility); |
| 2718 | if ((systemUiVisibility & StatusBarManager.DISABLE_MASK) != 0) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2719 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR) |
| 2720 | != PackageManager.PERMISSION_GRANTED) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2721 | systemUiVisibility &= ~StatusBarManager.DISABLE_MASK; |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2722 | } |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 2723 | } |
| 2724 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2725 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2726 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2727 | synchronized(mWindowMap) { |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 2728 | // TODO(cmautner): synchronize on mAnimator or win.mWinAnimator. |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2729 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2730 | if (win == null) { |
| 2731 | return 0; |
| 2732 | } |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2733 | WindowStateAnimator winAnimator = win.mWinAnimator; |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 2734 | if (win.mRequestedWidth != requestedWidth |
| 2735 | || win.mRequestedHeight != requestedHeight) { |
| 2736 | win.mLayoutNeeded = true; |
| 2737 | win.mRequestedWidth = requestedWidth; |
| 2738 | win.mRequestedHeight = requestedHeight; |
| 2739 | } |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2740 | if (attrs != null && seq == win.mSeq) { |
| 2741 | win.mSystemUiVisibility = systemUiVisibility; |
| 2742 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2743 | |
| 2744 | if (attrs != null) { |
| 2745 | mPolicy.adjustWindowParamsLw(attrs); |
| 2746 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2747 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2748 | winAnimator.mSurfaceDestroyDeferred = |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2749 | (flags&WindowManagerImpl.RELAYOUT_DEFER_SURFACE_DESTROY) != 0; |
| 2750 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2751 | int attrChanges = 0; |
| 2752 | int flagChanges = 0; |
| 2753 | if (attrs != null) { |
Dianne Hackborn | 0e60db2 | 2011-09-01 11:17:57 -0700 | [diff] [blame] | 2754 | if (win.mAttrs.type != attrs.type) { |
| 2755 | throw new IllegalArgumentException( |
| 2756 | "Window type can not be changed after the window is added."); |
| 2757 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2758 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2759 | attrChanges = win.mAttrs.copyFrom(attrs); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2760 | if ((attrChanges & (WindowManager.LayoutParams.LAYOUT_CHANGED |
| 2761 | | WindowManager.LayoutParams.SYSTEM_UI_VISIBILITY_CHANGED)) != 0) { |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 2762 | win.mLayoutNeeded = true; |
| 2763 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2764 | } |
| 2765 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2766 | 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] | 2767 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2768 | win.mEnforceSizeCompat = (win.mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0; |
| 2769 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2770 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2771 | winAnimator.mAlpha = attrs.alpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | final boolean scaledWindow = |
| 2775 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2776 | |
| 2777 | if (scaledWindow) { |
| 2778 | // requested{Width|Height} Surface's physical size |
| 2779 | // attrs.{width|height} Size on screen |
| 2780 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2781 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2782 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2783 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2784 | } else { |
| 2785 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | boolean imMayMove = (flagChanges&( |
| 2789 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2790 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2792 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2793 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2794 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2795 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2796 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2797 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 2798 | wallpaperMayMove |= (flagChanges & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2799 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2800 | win.mRelayoutCalled = true; |
| 2801 | final int oldVisibility = win.mViewVisibility; |
| 2802 | win.mViewVisibility = viewVisibility; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 2803 | if (DEBUG_SCREEN_ON) { |
| 2804 | RuntimeException stack = new RuntimeException(); |
| 2805 | stack.fillInStackTrace(); |
| 2806 | Slog.i(TAG, "Relayout " + win + ": oldVis=" + oldVisibility |
| 2807 | + " newVis=" + viewVisibility, stack); |
| 2808 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2809 | if (viewVisibility == View.VISIBLE && |
| 2810 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2811 | toBeDisplayed = !win.isVisibleLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2812 | if (win.mExiting) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2813 | winAnimator.cancelExitAnimationForNextAnimationLocked(); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2814 | win.mExiting = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2815 | } |
| 2816 | if (win.mDestroying) { |
| 2817 | win.mDestroying = false; |
| 2818 | mDestroySurface.remove(win); |
| 2819 | } |
| 2820 | if (oldVisibility == View.GONE) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2821 | winAnimator.mEnterAnimationPending = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2822 | } |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2823 | if (toBeDisplayed) { |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 2824 | if (win.isDrawnLw() && okToDisplay()) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2825 | winAnimator.applyEnterAnimationLocked(); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2826 | } |
| 2827 | if ((win.mAttrs.flags |
| 2828 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2829 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2830 | "Relayout window turning screen on: " + win); |
| 2831 | win.mTurnOnScreen = true; |
| 2832 | } |
| 2833 | int diff = 0; |
| 2834 | if (win.mConfiguration != mCurConfiguration |
| 2835 | && (win.mConfiguration == null |
| 2836 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2837 | win.mConfiguration = mCurConfiguration; |
| 2838 | if (DEBUG_CONFIGURATION) { |
| 2839 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2840 | + win.mConfiguration + " / 0x" |
| 2841 | + Integer.toHexString(diff)); |
| 2842 | } |
| 2843 | outConfig.setTo(mCurConfiguration); |
| 2844 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2845 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2846 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2847 | // To change the format, we need to re-build the surface. |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2848 | winAnimator.destroySurfaceLocked(); |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2849 | toBeDisplayed = true; |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2850 | surfaceChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2851 | } |
| 2852 | try { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2853 | if (!win.mHasSurface) { |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2854 | surfaceChanged = true; |
| 2855 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2856 | Surface surface = winAnimator.createSurfaceLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2857 | if (surface != null) { |
| 2858 | outSurface.copyFrom(surface); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2859 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2860 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2861 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2862 | // For some reason there isn't a surface. Clear the |
| 2863 | // caller's object so they see the same state. |
| 2864 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2865 | } |
| 2866 | } catch (Exception e) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2867 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 2868 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2869 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2870 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2871 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2872 | Binder.restoreCallingIdentity(origId); |
| 2873 | return 0; |
| 2874 | } |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2875 | if (toBeDisplayed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2876 | focusMayChange = true; |
| 2877 | } |
| 2878 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2879 | && mInputMethodWindow == null) { |
| 2880 | mInputMethodWindow = win; |
| 2881 | imMayMove = true; |
| 2882 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2883 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2884 | && win.mAppToken != null |
| 2885 | && win.mAppToken.startingWindow != null) { |
| 2886 | // Special handling of starting window over the base |
| 2887 | // window of the app: propagate lock screen flags to it, |
| 2888 | // to provide the correct semantics while starting. |
| 2889 | final int mask = |
| 2890 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2891 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2892 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2893 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2894 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2895 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2896 | } else { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2897 | winAnimator.mEnterAnimationPending = false; |
| 2898 | if (winAnimator.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2899 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2900 | + ": mExiting=" + win.mExiting); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | // If we are not currently running the exit animation, we |
| 2902 | // need to see about starting one. |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2903 | if (!win.mExiting) { |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2904 | surfaceChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2905 | // Try starting an animation; if there isn't one, we |
| 2906 | // can destroy the surface right away. |
| 2907 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 2908 | if (win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2909 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2910 | } |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2911 | if (win.isWinVisibleLw() && |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2912 | winAnimator.applyAnimationLocked(transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2913 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2914 | win.mExiting = true; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2915 | } else if (win.mWinAnimator.isAnimating()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2916 | // Currently in a hide animation... turn this into |
| 2917 | // an exit. |
| 2918 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2919 | } else if (win == mWallpaperTarget) { |
| 2920 | // If the wallpaper is currently behind this |
| 2921 | // window, we need to change both of them inside |
| 2922 | // of a transaction to avoid artifacts. |
| 2923 | win.mExiting = true; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2924 | win.mWinAnimator.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2925 | } else { |
| 2926 | if (mInputMethodWindow == win) { |
| 2927 | mInputMethodWindow = null; |
| 2928 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2929 | winAnimator.destroySurfaceLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2930 | } |
| 2931 | } |
| 2932 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2933 | |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2934 | outSurface.release(); |
| 2935 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2936 | } |
| 2937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2938 | if (focusMayChange) { |
| 2939 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2940 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2941 | false /*updateInputWindows*/)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2942 | imMayMove = false; |
| 2943 | } |
| 2944 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2945 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2946 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2947 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2948 | // reassign them at this point if the IM window state gets shuffled |
| 2949 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2951 | if (imMayMove) { |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2952 | if (moveInputMethodWindowsIfNeededLocked(false) || toBeDisplayed) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2953 | // Little hack here -- we -should- be able to rely on the |
| 2954 | // function to return true if the IME has moved and needs |
| 2955 | // its layer recomputed. However, if the IME was hidden |
| 2956 | // and isn't actually moved in the list, its layer may be |
| 2957 | // 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] | 2958 | assignLayers = true; |
| 2959 | } |
| 2960 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2961 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2962 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2963 | assignLayers = true; |
| 2964 | } |
| 2965 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2966 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2967 | mLayoutNeeded = true; |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2968 | win.mGivenInsetsPending = (flags&WindowManagerImpl.RELAYOUT_INSETS_PENDING) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2969 | if (assignLayers) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2970 | assignLayersLocked(win.getWindowList()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2972 | configChanged = updateOrientationFromAppTokensLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2973 | performLayoutAndPlaceSurfacesLocked(); |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2974 | if (toBeDisplayed && win.mIsWallpaper) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2975 | DisplayInfo displayInfo = getDefaultDisplayInfo(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 2976 | updateWallpaperOffsetLocked(win, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2977 | displayInfo.appWidth, displayInfo.appHeight, false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2978 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2979 | if (win.mAppToken != null) { |
| 2980 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2981 | } |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2982 | outFrame.set(win.mCompatFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2983 | outContentInsets.set(win.mContentInsets); |
| 2984 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2985 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2987 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2988 | + ", requestedHeight=" + requestedHeight |
| 2989 | + ", viewVisibility=" + viewVisibility |
| 2990 | + "\nRelayout returning frame=" + outFrame |
| 2991 | + ", surface=" + outSurface); |
| 2992 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2993 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2994 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2995 | |
| 2996 | inTouchMode = mInTouchMode; |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 2997 | animating = mAnimator.mAnimating; |
| 2998 | if (animating && !mRelayoutWhileAnimating.contains(win)) { |
| 2999 | mRelayoutWhileAnimating.add(win); |
| 3000 | } |
| 3001 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 3002 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3003 | } |
| 3004 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3005 | if (configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3006 | sendNewConfiguration(); |
| 3007 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3008 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3009 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3010 | |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 3011 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_RES_IN_TOUCH_MODE : 0) |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 3012 | | (toBeDisplayed ? WindowManagerImpl.RELAYOUT_RES_FIRST_TIME : 0) |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 3013 | | (surfaceChanged ? WindowManagerImpl.RELAYOUT_RES_SURFACE_CHANGED : 0) |
| 3014 | | (animating ? WindowManagerImpl.RELAYOUT_RES_ANIMATING : 0); |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 3015 | } |
| 3016 | |
| 3017 | public void performDeferredDestroyWindow(Session session, IWindow client) { |
| 3018 | long origId = Binder.clearCallingIdentity(); |
| 3019 | |
| 3020 | try { |
| 3021 | synchronized(mWindowMap) { |
| 3022 | WindowState win = windowForClientLocked(session, client, false); |
| 3023 | if (win == null) { |
| 3024 | return; |
| 3025 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 3026 | win.mWinAnimator.destroyDeferredSurfaceLocked(); |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 3027 | } |
| 3028 | } finally { |
| 3029 | Binder.restoreCallingIdentity(origId); |
| 3030 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3031 | } |
| 3032 | |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3033 | public boolean outOfMemoryWindow(Session session, IWindow client) { |
| 3034 | long origId = Binder.clearCallingIdentity(); |
| 3035 | |
| 3036 | try { |
| 3037 | synchronized(mWindowMap) { |
| 3038 | WindowState win = windowForClientLocked(session, client, false); |
| 3039 | if (win == null) { |
| 3040 | return false; |
| 3041 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 3042 | return reclaimSomeSurfaceMemoryLocked(win.mWinAnimator, "from-client", false); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3043 | } |
| 3044 | } finally { |
| 3045 | Binder.restoreCallingIdentity(origId); |
| 3046 | } |
| 3047 | } |
| 3048 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3049 | public void finishDrawingWindow(Session session, IWindow client) { |
| 3050 | final long origId = Binder.clearCallingIdentity(); |
| 3051 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3052 | WindowState win = windowForClientLocked(session, client, false); |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 3053 | if (win != null && win.mWinAnimator.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 3054 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 3055 | adjustWallpaperWindowsLocked(); |
| 3056 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3057 | mLayoutNeeded = true; |
| 3058 | performLayoutAndPlaceSurfacesLocked(); |
| 3059 | } |
| 3060 | } |
| 3061 | Binder.restoreCallingIdentity(origId); |
| 3062 | } |
| 3063 | |
Svetoslav Ganov | 7961be7 | 2011-06-21 12:31:56 -0700 | [diff] [blame] | 3064 | public float getWindowCompatibilityScale(IBinder windowToken) { |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 3065 | if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO, |
| 3066 | "getWindowCompatibilityScale()")) { |
| 3067 | throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission."); |
| 3068 | } |
Svetoslav Ganov | 7961be7 | 2011-06-21 12:31:56 -0700 | [diff] [blame] | 3069 | synchronized (mWindowMap) { |
| 3070 | WindowState windowState = mWindowMap.get(windowToken); |
| 3071 | return (windowState != null) ? windowState.mGlobalScale : 1.0f; |
| 3072 | } |
| 3073 | } |
| 3074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3075 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 3076 | 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] | 3077 | + (lp != null ? lp.packageName : null) |
| 3078 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 3079 | if (lp != null && lp.windowAnimations != 0) { |
| 3080 | // If this is a system resource, don't try to load it from the |
| 3081 | // application resources. It is nice to avoid loading application |
| 3082 | // resources if we can. |
| 3083 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 3084 | int resId = lp.windowAnimations; |
| 3085 | if ((resId&0xFF000000) == 0x01000000) { |
| 3086 | packageName = "android"; |
| 3087 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3088 | 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] | 3089 | + packageName); |
| 3090 | return AttributeCache.instance().get(packageName, resId, |
| 3091 | com.android.internal.R.styleable.WindowAnimation); |
| 3092 | } |
| 3093 | return null; |
| 3094 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3095 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3096 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 3097 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3098 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 3099 | if (packageName != null) { |
| 3100 | if ((resId&0xFF000000) == 0x01000000) { |
| 3101 | packageName = "android"; |
| 3102 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3103 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3104 | + packageName); |
| 3105 | return AttributeCache.instance().get(packageName, resId, |
| 3106 | com.android.internal.R.styleable.WindowAnimation); |
| 3107 | } |
| 3108 | return null; |
| 3109 | } |
| 3110 | |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 3111 | Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3112 | int anim = 0; |
| 3113 | Context context = mContext; |
| 3114 | if (animAttr >= 0) { |
| 3115 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 3116 | if (ent != null) { |
| 3117 | context = ent.context; |
| 3118 | anim = ent.array.getResourceId(animAttr, 0); |
| 3119 | } |
| 3120 | } |
| 3121 | if (anim != 0) { |
| 3122 | return AnimationUtils.loadAnimation(context, anim); |
| 3123 | } |
| 3124 | return null; |
| 3125 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3126 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3127 | private Animation loadAnimation(String packageName, int resId) { |
| 3128 | int anim = 0; |
| 3129 | Context context = mContext; |
| 3130 | if (resId >= 0) { |
| 3131 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 3132 | if (ent != null) { |
| 3133 | context = ent.context; |
| 3134 | anim = resId; |
| 3135 | } |
| 3136 | } |
| 3137 | if (anim != 0) { |
| 3138 | return AnimationUtils.loadAnimation(context, anim); |
| 3139 | } |
| 3140 | return null; |
| 3141 | } |
| 3142 | |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3143 | private Animation createExitAnimationLocked(int transit, int duration) { |
| 3144 | if (transit == WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN || |
| 3145 | transit == WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE) { |
| 3146 | // If we are on top of the wallpaper, we need an animation that |
| 3147 | // correctly handles the wallpaper staying static behind all of |
| 3148 | // the animated elements. To do this, will just have the existing |
| 3149 | // element fade out. |
| 3150 | Animation a = new AlphaAnimation(1, 0); |
| 3151 | a.setDetachWallpaper(true); |
| 3152 | a.setDuration(duration); |
| 3153 | return a; |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3154 | } |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 3155 | // For normal animations, the exiting element just holds in place. |
| 3156 | Animation a = new AlphaAnimation(1, 1); |
| 3157 | a.setDuration(duration); |
| 3158 | return a; |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | /** |
| 3162 | * Compute the pivot point for an animation that is scaling from a small |
| 3163 | * rect on screen to a larger rect. The pivot point varies depending on |
| 3164 | * the distance between the inner and outer edges on both sides. This |
| 3165 | * function computes the pivot point for one dimension. |
| 3166 | * @param startPos Offset from left/top edge of outer rectangle to |
| 3167 | * left/top edge of inner rectangle. |
| 3168 | * @param finalScale The scaling factor between the size of the outer |
| 3169 | * and inner rectangles. |
| 3170 | */ |
| 3171 | private static float computePivot(int startPos, float finalScale) { |
| 3172 | final float denom = finalScale-1; |
| 3173 | if (Math.abs(denom) < .0001f) { |
| 3174 | return startPos; |
| 3175 | } |
| 3176 | return -startPos / denom; |
| 3177 | } |
| 3178 | |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3179 | private Animation createScaleUpAnimationLocked(int transit, boolean enter) { |
| 3180 | Animation a; |
| 3181 | // Pick the desired duration. If this is an inter-activity transition, |
| 3182 | // it is the standard duration for that. Otherwise we use the longer |
| 3183 | // task transition duration. |
| 3184 | int duration; |
| 3185 | switch (transit) { |
| 3186 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3187 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3188 | duration = mContext.getResources().getInteger( |
| 3189 | com.android.internal.R.integer.config_shortAnimTime); |
| 3190 | break; |
| 3191 | default: |
Winson Chung | dc6f79b | 2012-04-17 17:27:31 -0700 | [diff] [blame] | 3192 | duration = 300; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3193 | break; |
| 3194 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3195 | // TODO(multidisplay): For now assume all app animation is on main display. |
| 3196 | final DisplayInfo displayInfo = getDefaultDisplayInfo(); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3197 | if (enter) { |
| 3198 | // Entering app zooms out from the center of the initial rect. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3199 | float scaleW = mNextAppTransitionStartWidth / (float) displayInfo.appWidth; |
| 3200 | float scaleH = mNextAppTransitionStartHeight / (float) displayInfo.appHeight; |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3201 | Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1, |
| 3202 | computePivot(mNextAppTransitionStartX, scaleW), |
| 3203 | computePivot(mNextAppTransitionStartY, scaleH)); |
| 3204 | scale.setDuration(duration); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3205 | AnimationSet set = new AnimationSet(true); |
| 3206 | Animation alpha = new AlphaAnimation(0, 1); |
| 3207 | scale.setDuration(duration); |
| 3208 | set.addAnimation(scale); |
| 3209 | alpha.setDuration(duration); |
| 3210 | set.addAnimation(alpha); |
Craig Mautner | a803371 | 2012-06-12 15:50:45 -0700 | [diff] [blame] | 3211 | set.setDetachWallpaper(true); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3212 | a = set; |
| 3213 | } else { |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3214 | a = createExitAnimationLocked(transit, duration); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3215 | } |
| 3216 | a.setFillAfter(true); |
| 3217 | final Interpolator interpolator = AnimationUtils.loadInterpolator(mContext, |
Winson Chung | dc6f79b | 2012-04-17 17:27:31 -0700 | [diff] [blame] | 3218 | com.android.internal.R.interpolator.decelerate_cubic); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3219 | a.setInterpolator(interpolator); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3220 | a.initialize(displayInfo.appWidth, displayInfo.appHeight, |
| 3221 | displayInfo.appWidth, displayInfo.appHeight); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3222 | return a; |
| 3223 | } |
| 3224 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3225 | private Animation createThumbnailAnimationLocked(int transit, |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3226 | boolean enter, boolean thumb, boolean delayed) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3227 | Animation a; |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3228 | final int thumbWidthI = mNextAppTransitionThumbnail.getWidth(); |
| 3229 | final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1; |
| 3230 | final int thumbHeightI = mNextAppTransitionThumbnail.getHeight(); |
| 3231 | final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3232 | // Pick the desired duration. If this is an inter-activity transition, |
| 3233 | // it is the standard duration for that. Otherwise we use the longer |
| 3234 | // task transition duration. |
| 3235 | int duration; |
Michael Jurka | c016aaa | 2012-06-05 17:22:24 -0700 | [diff] [blame] | 3236 | int delayDuration = delayed ? 270 : 0; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3237 | switch (transit) { |
| 3238 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3239 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3240 | duration = mContext.getResources().getInteger( |
| 3241 | com.android.internal.R.integer.config_shortAnimTime); |
| 3242 | break; |
| 3243 | default: |
Michael Jurka | c016aaa | 2012-06-05 17:22:24 -0700 | [diff] [blame] | 3244 | duration = delayed ? 250 : 300; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3245 | break; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3246 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3247 | // TOOD(multidisplay): For now assume all app animation is on the main screen. |
| 3248 | DisplayInfo displayInfo = getDefaultDisplayInfo(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3249 | if (thumb) { |
| 3250 | // Animation for zooming thumbnail from its initial size to |
| 3251 | // filling the screen. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3252 | float scaleW = displayInfo.appWidth/thumbWidth; |
| 3253 | float scaleH = displayInfo.appHeight/thumbHeight; |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3254 | |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3255 | Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH, |
| 3256 | computePivot(mNextAppTransitionStartX, 1/scaleW), |
| 3257 | computePivot(mNextAppTransitionStartY, 1/scaleH)); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3258 | AnimationSet set = new AnimationSet(true); |
| 3259 | Animation alpha = new AlphaAnimation(1, 0); |
| 3260 | scale.setDuration(duration); |
Michael Jurka | c016aaa | 2012-06-05 17:22:24 -0700 | [diff] [blame] | 3261 | scale.setInterpolator( |
| 3262 | new DecelerateInterpolator(THUMBNAIL_ANIMATION_DECELERATE_FACTOR)); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3263 | set.addAnimation(scale); |
| 3264 | alpha.setDuration(duration); |
| 3265 | set.addAnimation(alpha); |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3266 | set.setFillBefore(true); |
| 3267 | if (delayDuration > 0) { |
| 3268 | set.setStartOffset(delayDuration); |
| 3269 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3270 | a = set; |
| 3271 | } else if (enter) { |
| 3272 | // Entering app zooms out from the center of the thumbnail. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3273 | float scaleW = thumbWidth / displayInfo.appWidth; |
| 3274 | float scaleH = thumbHeight / displayInfo.appHeight; |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3275 | Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1, |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3276 | computePivot(mNextAppTransitionStartX, scaleW), |
| 3277 | computePivot(mNextAppTransitionStartY, scaleH)); |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3278 | scale.setDuration(duration); |
Michael Jurka | c016aaa | 2012-06-05 17:22:24 -0700 | [diff] [blame] | 3279 | scale.setInterpolator( |
| 3280 | new DecelerateInterpolator(THUMBNAIL_ANIMATION_DECELERATE_FACTOR)); |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3281 | scale.setFillBefore(true); |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3282 | if (delayDuration > 0) { |
Michael Jurka | d5895a7 | 2012-05-12 13:24:58 -0700 | [diff] [blame] | 3283 | scale.setStartOffset(delayDuration); |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3284 | } |
Michael Jurka | d5895a7 | 2012-05-12 13:24:58 -0700 | [diff] [blame] | 3285 | a = scale; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3286 | } else { |
Michael Jurka | d5895a7 | 2012-05-12 13:24:58 -0700 | [diff] [blame] | 3287 | if (delayed) { |
| 3288 | a = new AlphaAnimation(1, 0); |
| 3289 | a.setStartOffset(0); |
Michael Jurka | b9a38c5 | 2012-06-14 11:57:50 -0700 | [diff] [blame] | 3290 | a.setDuration(delayDuration - 120); |
Michael Jurka | d5895a7 | 2012-05-12 13:24:58 -0700 | [diff] [blame] | 3291 | a.setBackgroundColor(0xFF000000); |
| 3292 | } else { |
| 3293 | a = createExitAnimationLocked(transit, duration); |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3294 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3295 | } |
| 3296 | a.setFillAfter(true); |
| 3297 | final Interpolator interpolator = AnimationUtils.loadInterpolator(mContext, |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3298 | com.android.internal.R.interpolator.decelerate_quad); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3299 | a.setInterpolator(interpolator); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3300 | a.initialize(displayInfo.appWidth, displayInfo.appHeight, |
| 3301 | displayInfo.appWidth, displayInfo.appHeight); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3302 | return a; |
| 3303 | } |
| 3304 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3305 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3306 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3307 | // Only apply an animation if the display isn't frozen. If it is |
| 3308 | // frozen, there is no reason to animate and it can cause strange |
| 3309 | // artifacts when we unfreeze the display if some different animation |
| 3310 | // is running. |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 3311 | if (okToDisplay()) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3312 | Animation a; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3313 | boolean initialized = false; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3314 | if (mNextAppTransitionType == ActivityOptions.ANIM_CUSTOM) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3315 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 3316 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Daniel Sandler | ab886f5 | 2012-06-04 14:36:25 -0400 | [diff] [blame] | 3317 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, |
| 3318 | "applyAnimation: wtoken=" + wtoken |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 3319 | + " anim=" + a + " nextAppTransition=ANIM_CUSTOM" |
| 3320 | + " transit=" + transit + " Callers " + Debug.getCallers(3)); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3321 | } else if (mNextAppTransitionType == ActivityOptions.ANIM_SCALE_UP) { |
| 3322 | a = createScaleUpAnimationLocked(transit, enter); |
| 3323 | initialized = true; |
Daniel Sandler | ab886f5 | 2012-06-04 14:36:25 -0400 | [diff] [blame] | 3324 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, |
| 3325 | "applyAnimation: wtoken=" + wtoken |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 3326 | + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP" |
| 3327 | + " transit=" + transit + " Callers " + Debug.getCallers(3)); |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3328 | } else if (mNextAppTransitionType == ActivityOptions.ANIM_THUMBNAIL || |
| 3329 | mNextAppTransitionType == ActivityOptions.ANIM_THUMBNAIL_DELAYED) { |
| 3330 | boolean delayed = (mNextAppTransitionType == ActivityOptions.ANIM_THUMBNAIL_DELAYED); |
| 3331 | a = createThumbnailAnimationLocked(transit, enter, false, delayed); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3332 | initialized = true; |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3333 | |
Daniel Sandler | ab886f5 | 2012-06-04 14:36:25 -0400 | [diff] [blame] | 3334 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) { |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3335 | String animName = delayed ? "ANIM_THUMBNAIL_DELAYED" : "ANIM_THUMBNAIL"; |
| 3336 | Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
| 3337 | + " anim=" + a + " nextAppTransition=" + animName |
| 3338 | + " transit=" + transit + " Callers " + Debug.getCallers(3)); |
| 3339 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3340 | } else { |
| 3341 | int animAttr = 0; |
| 3342 | switch (transit) { |
| 3343 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3344 | animAttr = enter |
| 3345 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 3346 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 3347 | break; |
| 3348 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3349 | animAttr = enter |
| 3350 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 3351 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 3352 | break; |
| 3353 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 3354 | animAttr = enter |
| 3355 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 3356 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 3357 | break; |
| 3358 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 3359 | animAttr = enter |
| 3360 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 3361 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 3362 | break; |
| 3363 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 3364 | animAttr = enter |
| 3365 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 3366 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 3367 | break; |
| 3368 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 3369 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 3370 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3371 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 3372 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3373 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3374 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3375 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 3376 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3377 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3378 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3379 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3380 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 3381 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 3382 | break; |
| 3383 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 3384 | animAttr = enter |
| 3385 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 3386 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 3387 | break; |
| 3388 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 3389 | animAttr = enter |
| 3390 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 3391 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3392 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3393 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3394 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Daniel Sandler | ab886f5 | 2012-06-04 14:36:25 -0400 | [diff] [blame] | 3395 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, |
| 3396 | "applyAnimation: wtoken=" + wtoken |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3397 | + " anim=" + a |
| 3398 | + " animAttr=0x" + Integer.toHexString(animAttr) |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 3399 | + " transit=" + transit + " Callers " + Debug.getCallers(3)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3400 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3401 | if (a != null) { |
| 3402 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3403 | RuntimeException e = null; |
| 3404 | if (!HIDE_STACK_CRAWLS) { |
| 3405 | e = new RuntimeException(); |
| 3406 | e.fillInStackTrace(); |
| 3407 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3408 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3409 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 3410 | wtoken.mAppAnimator.setAnimation(a, initialized); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3411 | } |
| 3412 | } else { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 3413 | wtoken.mAppAnimator.clearAnimation(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3414 | } |
| 3415 | |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 3416 | return wtoken.mAppAnimator.animation != null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3417 | } |
| 3418 | |
| 3419 | // ------------------------------------------------------------- |
| 3420 | // Application Window Tokens |
| 3421 | // ------------------------------------------------------------- |
| 3422 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3423 | public void validateAppTokens(List<IBinder> tokens) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3424 | int v = tokens.size()-1; |
| 3425 | int m = mAppTokens.size()-1; |
| 3426 | while (v >= 0 && m >= 0) { |
| 3427 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3428 | if (wtoken.removed) { |
| 3429 | m--; |
| 3430 | continue; |
| 3431 | } |
| 3432 | if (tokens.get(v) != wtoken.token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3433 | 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] | 3434 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 3435 | } |
| 3436 | v--; |
| 3437 | m--; |
| 3438 | } |
| 3439 | while (v >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3440 | 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] | 3441 | v--; |
| 3442 | } |
| 3443 | while (m >= 0) { |
| 3444 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3445 | if (!wtoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3446 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3447 | } |
| 3448 | m--; |
| 3449 | } |
| 3450 | } |
| 3451 | |
| 3452 | boolean checkCallingPermission(String permission, String func) { |
| 3453 | // Quick check: if the calling permission is me, it's all okay. |
| 3454 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3455 | return true; |
| 3456 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3457 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3458 | if (mContext.checkCallingPermission(permission) |
| 3459 | == PackageManager.PERMISSION_GRANTED) { |
| 3460 | return true; |
| 3461 | } |
| 3462 | String msg = "Permission Denial: " + func + " from pid=" |
| 3463 | + Binder.getCallingPid() |
| 3464 | + ", uid=" + Binder.getCallingUid() |
| 3465 | + " requires " + permission; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3466 | Slog.w(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3467 | return false; |
| 3468 | } |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 3469 | |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 3470 | boolean okToDisplay() { |
| 3471 | return !mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOnFully(); |
| 3472 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3473 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3474 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3475 | WindowToken wtoken = mTokenMap.get(token); |
| 3476 | if (wtoken == null) { |
| 3477 | return null; |
| 3478 | } |
| 3479 | return wtoken.appWindowToken; |
| 3480 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3481 | |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 3482 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3483 | public void addWindowToken(IBinder token, int type) { |
| 3484 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3485 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3486 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3488 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3489 | synchronized(mWindowMap) { |
| 3490 | WindowToken wtoken = mTokenMap.get(token); |
| 3491 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3492 | 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] | 3493 | return; |
| 3494 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3495 | wtoken = new WindowToken(this, token, type, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3496 | mTokenMap.put(token, wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3497 | if (type == TYPE_WALLPAPER) { |
| 3498 | mWallpaperTokens.add(wtoken); |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 3499 | updateLayoutToAnimWallpaperTokens(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3500 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3501 | } |
| 3502 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3503 | |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 3504 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3505 | public void removeWindowToken(IBinder token) { |
| 3506 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3507 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3508 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3509 | } |
| 3510 | |
| 3511 | final long origId = Binder.clearCallingIdentity(); |
| 3512 | synchronized(mWindowMap) { |
| 3513 | WindowToken wtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3514 | if (wtoken != null) { |
| 3515 | boolean delayed = false; |
| 3516 | if (!wtoken.hidden) { |
| 3517 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3518 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3519 | final int N = wtoken.windows.size(); |
| 3520 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3521 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3522 | for (int i=0; i<N; i++) { |
| 3523 | WindowState win = wtoken.windows.get(i); |
| 3524 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 3525 | if (win.mWinAnimator.isAnimating()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3526 | delayed = true; |
| 3527 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3529 | if (win.isVisibleNow()) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3530 | win.mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, |
| 3531 | false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3532 | changed = true; |
| 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | if (changed) { |
| 3537 | mLayoutNeeded = true; |
| 3538 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3539 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, |
| 3540 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3541 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3542 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3543 | if (delayed) { |
| 3544 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3545 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3546 | mWallpaperTokens.remove(wtoken); |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 3547 | updateLayoutToAnimWallpaperTokens(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3548 | } |
| 3549 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3550 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 3551 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3552 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3553 | 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] | 3554 | } |
| 3555 | } |
| 3556 | Binder.restoreCallingIdentity(origId); |
| 3557 | } |
| 3558 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 3559 | /** |
| 3560 | * Find the location to insert a new AppWindowToken into the window-ordered app token list. |
| 3561 | * Note that mAppTokens.size() == mAnimatingAppTokens.size() + 1. |
| 3562 | * @param addPos The location the token was inserted into in mAppTokens. |
| 3563 | * @param wtoken The token to insert. |
| 3564 | */ |
| 3565 | private void addAppTokenToAnimating(final int addPos, final AppWindowToken wtoken) { |
| 3566 | if (addPos == 0 || addPos == mAnimatingAppTokens.size()) { |
| 3567 | // It was inserted into the beginning or end of mAppTokens. Honor that. |
| 3568 | mAnimatingAppTokens.add(addPos, wtoken); |
| 3569 | return; |
| 3570 | } |
| 3571 | // Find the item immediately above the mAppTokens insertion point and put the token |
| 3572 | // immediately below that one in mAnimatingAppTokens. |
| 3573 | final AppWindowToken aboveAnchor = mAppTokens.get(addPos + 1); |
| 3574 | mAnimatingAppTokens.add(mAnimatingAppTokens.indexOf(aboveAnchor), wtoken); |
| 3575 | } |
| 3576 | |
| 3577 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3578 | public void addAppToken(int addPos, IApplicationToken token, |
| 3579 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3580 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3581 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3582 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3583 | } |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 3584 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3585 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3586 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3587 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3588 | // here we would run the chance of introducing a deadlock between the window manager |
| 3589 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3590 | // (which holds locks while querying the application token). |
| 3591 | long inputDispatchingTimeoutNanos; |
| 3592 | try { |
| 3593 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3594 | } catch (RemoteException ex) { |
| 3595 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3596 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3597 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3599 | synchronized(mWindowMap) { |
| 3600 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3601 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3602 | 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] | 3603 | return; |
| 3604 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3605 | wtoken = new AppWindowToken(this, token); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3606 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3607 | wtoken.groupId = groupId; |
| 3608 | wtoken.appFullscreen = fullscreen; |
| 3609 | wtoken.requestedOrientation = requestedOrientation; |
Craig Mautner | 06a94f7 | 2012-05-29 10:46:00 -0700 | [diff] [blame] | 3610 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken |
| 3611 | + " at " + addPos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3612 | mAppTokens.add(addPos, wtoken); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 3613 | addAppTokenToAnimating(addPos, wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3614 | mTokenMap.put(token.asBinder(), wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3615 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3616 | // Application tokens start out hidden. |
| 3617 | wtoken.hidden = true; |
| 3618 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3619 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3620 | //dump(); |
| 3621 | } |
| 3622 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3623 | |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 3624 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3625 | public void setAppGroupId(IBinder token, int groupId) { |
| 3626 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 3627 | "setAppGroupId()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3628 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3629 | } |
| 3630 | |
| 3631 | synchronized(mWindowMap) { |
| 3632 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3633 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3634 | 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] | 3635 | return; |
| 3636 | } |
| 3637 | wtoken.groupId = groupId; |
| 3638 | } |
| 3639 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3640 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | public int getOrientationFromWindowsLocked() { |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3642 | if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) { |
| 3643 | // If the display is frozen, some activities may be in the middle |
| 3644 | // of restarting, and thus have removed their old window. If the |
| 3645 | // window has the flag to hide the lock screen, then the lock screen |
| 3646 | // can re-appear and inflict its own orientation on us. Keep the |
| 3647 | // orientation stable until this all settles down. |
| 3648 | return mLastWindowForcedOrientation; |
| 3649 | } |
| 3650 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3651 | // TODO(multidisplay): Change to the correct display. |
| 3652 | final WindowList windows = getDefaultWindowList(); |
| 3653 | int pos = windows.size() - 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3654 | while (pos >= 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3655 | WindowState wtoken = windows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3656 | pos--; |
| 3657 | if (wtoken.mAppToken != null) { |
| 3658 | // We hit an application window. so the orientation will be determined by the |
| 3659 | // app window. No point in continuing further. |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3660 | return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3661 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3662 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3663 | continue; |
| 3664 | } |
| 3665 | int req = wtoken.mAttrs.screenOrientation; |
| 3666 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3667 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3668 | continue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3669 | } |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 3670 | |
| 3671 | return (mLastWindowForcedOrientation=req); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3672 | } |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3673 | return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3674 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3675 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3676 | public int getOrientationFromAppTokensLocked() { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3677 | int curGroup = 0; |
| 3678 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3679 | boolean findingBehind = false; |
| 3680 | boolean haveGroup = false; |
| 3681 | boolean lastFullscreen = false; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 3682 | for (int pos = mAppTokens.size() - 1; pos >= 0; pos--) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3683 | AppWindowToken wtoken = mAppTokens.get(pos); |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3684 | |
| 3685 | if (DEBUG_APP_ORIENTATION) Slog.v(TAG, "Checking app orientation: " + wtoken); |
| 3686 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3687 | // if we're about to tear down this window and not seek for |
| 3688 | // the behind activity, don't use it for orientation |
| 3689 | if (!findingBehind |
| 3690 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3691 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping " + wtoken |
| 3692 | + " -- going to hide"); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3693 | continue; |
| 3694 | } |
| 3695 | |
p13451 | 0445bc6 | 2012-04-18 15:13:26 +0900 | [diff] [blame] | 3696 | if (haveGroup == true && curGroup != wtoken.groupId) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3697 | // If we have hit a new application group, and the bottom |
| 3698 | // of the previous group didn't explicitly say to use |
| 3699 | // the orientation behind it, and the last app was |
| 3700 | // full screen, then we'll stick with the |
| 3701 | // user's orientation. |
| 3702 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3703 | && lastFullscreen) { |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3704 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + wtoken |
| 3705 | + " -- end of group, return " + lastOrientation); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3706 | return lastOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3707 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3708 | } |
p13451 | 0445bc6 | 2012-04-18 15:13:26 +0900 | [diff] [blame] | 3709 | |
| 3710 | // We ignore any hidden applications on the top. |
| 3711 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| 3712 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping " + wtoken |
| 3713 | + " -- hidden on top"); |
| 3714 | continue; |
| 3715 | } |
| 3716 | |
| 3717 | if (!haveGroup) { |
| 3718 | haveGroup = true; |
| 3719 | curGroup = wtoken.groupId; |
| 3720 | lastOrientation = wtoken.requestedOrientation; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 3721 | } |
p13451 | 0445bc6 | 2012-04-18 15:13:26 +0900 | [diff] [blame] | 3722 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3723 | int or = wtoken.requestedOrientation; |
| 3724 | // If this application is fullscreen, and didn't explicitly say |
| 3725 | // to use the orientation behind it, then just take whatever |
| 3726 | // orientation it has and ignores whatever is under it. |
| 3727 | lastFullscreen = wtoken.appFullscreen; |
| 3728 | if (lastFullscreen |
| 3729 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3730 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + wtoken |
| 3731 | + " -- full screen, return " + or); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3732 | return or; |
| 3733 | } |
| 3734 | // If this application has requested an explicit orientation, |
| 3735 | // then use it. |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3736 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3737 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3738 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + wtoken |
| 3739 | + " -- explicitly set, return " + or); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3740 | return or; |
| 3741 | } |
| 3742 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3743 | } |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3744 | if (DEBUG_ORIENTATION) Slog.v(TAG, "No app is requesting an orientation"); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3745 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3746 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3747 | |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 3748 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3749 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3750 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3751 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3752 | "updateOrientationFromAppTokens()")) { |
| 3753 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3754 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3755 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3756 | Configuration config = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3757 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3758 | |
| 3759 | synchronized(mWindowMap) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 3760 | config = updateOrientationFromAppTokensLocked(currentConfig, |
| 3761 | freezeThisOneIfNeeded); |
| 3762 | } |
| 3763 | |
| 3764 | Binder.restoreCallingIdentity(ident); |
| 3765 | return config; |
| 3766 | } |
| 3767 | |
| 3768 | private Configuration updateOrientationFromAppTokensLocked( |
| 3769 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| 3770 | Configuration config = null; |
| 3771 | |
| 3772 | if (updateOrientationFromAppTokensLocked(false)) { |
| 3773 | if (freezeThisOneIfNeeded != null) { |
| 3774 | AppWindowToken wtoken = findAppWindowToken( |
| 3775 | freezeThisOneIfNeeded); |
| 3776 | if (wtoken != null) { |
| 3777 | startAppFreezingScreenLocked(wtoken, |
| 3778 | ActivityInfo.CONFIG_ORIENTATION); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3779 | } |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 3780 | } |
| 3781 | config = computeNewConfigurationLocked(); |
| 3782 | |
| 3783 | } else if (currentConfig != null) { |
| 3784 | // No obvious action we need to take, but if our current |
| 3785 | // state mismatches the activity manager's, update it, |
| 3786 | // disregarding font scale, which should remain set to |
| 3787 | // the value of the previous configuration. |
| 3788 | mTempConfiguration.setToDefaults(); |
| 3789 | mTempConfiguration.fontScale = currentConfig.fontScale; |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 3790 | if (computeScreenConfigurationLocked(mTempConfiguration)) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 3791 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3792 | mWaitingForConfig = true; |
| 3793 | mLayoutNeeded = true; |
| 3794 | startFreezingDisplayLocked(false); |
| 3795 | config = new Configuration(mTempConfiguration); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3796 | } |
| 3797 | } |
| 3798 | } |
| 3799 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3800 | return config; |
| 3801 | } |
| 3802 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3803 | /* |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3804 | * Determine the new desired orientation of the display, returning |
| 3805 | * a non-null new Configuration if it has changed from the current |
| 3806 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3807 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3808 | * SCREEN. This will typically be done for you if you call |
| 3809 | * sendNewConfiguration(). |
| 3810 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3811 | * The orientation is computed from non-application windows first. If none of |
| 3812 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3813 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3814 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3815 | * android.os.IBinder) |
| 3816 | */ |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3817 | boolean updateOrientationFromAppTokensLocked(boolean inTransaction) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3818 | long ident = Binder.clearCallingIdentity(); |
| 3819 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3820 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3821 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3822 | if (req != mForcedAppOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3823 | mForcedAppOrientation = req; |
| 3824 | //send a message to Policy indicating orientation change to take |
| 3825 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3826 | mPolicy.setCurrentOrientationLw(req); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 3827 | if (updateRotationUncheckedLocked(inTransaction)) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 3828 | // changed |
| 3829 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3830 | } |
| 3831 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3832 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 3833 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3834 | } finally { |
| 3835 | Binder.restoreCallingIdentity(ident); |
| 3836 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3837 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3838 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3839 | int computeForcedAppOrientationLocked() { |
| 3840 | int req = getOrientationFromWindowsLocked(); |
| 3841 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3842 | req = getOrientationFromAppTokensLocked(); |
| 3843 | } |
| 3844 | return req; |
| 3845 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3846 | |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 3847 | @Override |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3848 | public void setNewConfiguration(Configuration config) { |
| 3849 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3850 | "setNewConfiguration()")) { |
| 3851 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3852 | } |
| 3853 | |
| 3854 | synchronized(mWindowMap) { |
| 3855 | mCurConfiguration = new Configuration(config); |
| 3856 | mWaitingForConfig = false; |
| 3857 | performLayoutAndPlaceSurfacesLocked(); |
| 3858 | } |
| 3859 | } |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 3860 | |
| 3861 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3862 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3863 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3864 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3865 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3866 | } |
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 | synchronized(mWindowMap) { |
| 3869 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3870 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3871 | 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] | 3872 | return; |
| 3873 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3874 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3875 | wtoken.requestedOrientation = requestedOrientation; |
| 3876 | } |
| 3877 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3878 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3879 | public int getAppOrientation(IApplicationToken token) { |
| 3880 | synchronized(mWindowMap) { |
| 3881 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3882 | if (wtoken == null) { |
| 3883 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3884 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3885 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3886 | return wtoken.requestedOrientation; |
| 3887 | } |
| 3888 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3889 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3890 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3891 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3892 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3893 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | synchronized(mWindowMap) { |
| 3897 | boolean changed = false; |
| 3898 | if (token == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3899 | 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] | 3900 | changed = mFocusedApp != null; |
| 3901 | mFocusedApp = null; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3902 | if (changed) { |
| 3903 | mInputMonitor.setFocusedAppLw(null); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3904 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3905 | } else { |
| 3906 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3907 | if (newFocus == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3908 | 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] | 3909 | return; |
| 3910 | } |
| 3911 | changed = mFocusedApp != newFocus; |
| 3912 | mFocusedApp = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3913 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3914 | if (changed) { |
| 3915 | mInputMonitor.setFocusedAppLw(newFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3916 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | if (moveFocusNow && changed) { |
| 3920 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3921 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3922 | Binder.restoreCallingIdentity(origId); |
| 3923 | } |
| 3924 | } |
| 3925 | } |
| 3926 | |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3927 | public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3928 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3929 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3930 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3931 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3932 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3933 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3934 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3935 | TAG, "Prepare app transition: transit=" + transit |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 3936 | + " mNextAppTransition=" + mNextAppTransition |
Craig Mautner | 1d961d4 | 2012-05-27 12:02:11 -0700 | [diff] [blame] | 3937 | + " alwaysKeepCurrent=" + alwaysKeepCurrent |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 3938 | + " Callers=" + Debug.getCallers(3)); |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 3939 | if (okToDisplay()) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3940 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3941 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3942 | mNextAppTransition = transit; |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3943 | } else if (!alwaysKeepCurrent) { |
| 3944 | if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3945 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3946 | // Opening a new task always supersedes a close for the anim. |
| 3947 | mNextAppTransition = transit; |
| 3948 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3949 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3950 | // Opening a new activity always supersedes a close for the anim. |
| 3951 | mNextAppTransition = transit; |
| 3952 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3953 | } |
| 3954 | mAppTransitionReady = false; |
| 3955 | mAppTransitionTimeout = false; |
| 3956 | mStartingIconInTransition = false; |
| 3957 | mSkipAppTransitionAnimation = false; |
| 3958 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3959 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3960 | 5000); |
| 3961 | } |
| 3962 | } |
| 3963 | } |
| 3964 | |
| 3965 | public int getPendingAppTransition() { |
| 3966 | return mNextAppTransition; |
| 3967 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3968 | |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 3969 | private void scheduleAnimationCallback(IRemoteCallback cb) { |
| 3970 | if (cb != null) { |
| 3971 | mH.sendMessage(mH.obtainMessage(H.DO_ANIMATION_CALLBACK, cb)); |
| 3972 | } |
| 3973 | } |
| 3974 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3975 | public void overridePendingAppTransition(String packageName, |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 3976 | int enterAnim, int exitAnim, IRemoteCallback startedCallback) { |
| 3977 | synchronized(mWindowMap) { |
| 3978 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 3979 | mNextAppTransitionType = ActivityOptions.ANIM_CUSTOM; |
| 3980 | mNextAppTransitionPackage = packageName; |
| 3981 | mNextAppTransitionThumbnail = null; |
| 3982 | mNextAppTransitionEnter = enterAnim; |
| 3983 | mNextAppTransitionExit = exitAnim; |
| 3984 | scheduleAnimationCallback(mNextAppTransitionCallback); |
| 3985 | mNextAppTransitionCallback = startedCallback; |
| 3986 | } else { |
| 3987 | scheduleAnimationCallback(startedCallback); |
| 3988 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3989 | } |
| 3990 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3991 | |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3992 | public void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth, |
| 3993 | int startHeight) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 3994 | synchronized(mWindowMap) { |
| 3995 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 3996 | mNextAppTransitionType = ActivityOptions.ANIM_SCALE_UP; |
| 3997 | mNextAppTransitionPackage = null; |
| 3998 | mNextAppTransitionThumbnail = null; |
| 3999 | mNextAppTransitionStartX = startX; |
| 4000 | mNextAppTransitionStartY = startY; |
| 4001 | mNextAppTransitionStartWidth = startWidth; |
| 4002 | mNextAppTransitionStartHeight = startHeight; |
| 4003 | scheduleAnimationCallback(mNextAppTransitionCallback); |
| 4004 | mNextAppTransitionCallback = null; |
| 4005 | } |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 4006 | } |
| 4007 | } |
| 4008 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4009 | public void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 4010 | int startY, IRemoteCallback startedCallback, boolean delayed) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 4011 | synchronized(mWindowMap) { |
| 4012 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 4013 | mNextAppTransitionType = delayed |
| 4014 | ? ActivityOptions.ANIM_THUMBNAIL_DELAYED : ActivityOptions.ANIM_THUMBNAIL; |
| 4015 | mNextAppTransitionPackage = null; |
| 4016 | mNextAppTransitionThumbnail = srcThumb; |
| 4017 | mNextAppTransitionDelayed = delayed; |
| 4018 | mNextAppTransitionStartX = startX; |
| 4019 | mNextAppTransitionStartY = startY; |
| 4020 | scheduleAnimationCallback(mNextAppTransitionCallback); |
| 4021 | mNextAppTransitionCallback = startedCallback; |
| 4022 | } else { |
| 4023 | scheduleAnimationCallback(startedCallback); |
| 4024 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4025 | } |
| 4026 | } |
| 4027 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4028 | public void executeAppTransition() { |
| 4029 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4030 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4031 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4032 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4033 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4034 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4035 | if (DEBUG_APP_TRANSITIONS) { |
| 4036 | RuntimeException e = new RuntimeException("here"); |
| 4037 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4038 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4039 | + mNextAppTransition, e); |
| 4040 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4041 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4042 | mAppTransitionReady = true; |
| 4043 | final long origId = Binder.clearCallingIdentity(); |
| 4044 | performLayoutAndPlaceSurfacesLocked(); |
| 4045 | Binder.restoreCallingIdentity(origId); |
| 4046 | } |
| 4047 | } |
| 4048 | } |
| 4049 | |
| 4050 | public void setAppStartingWindow(IBinder token, String pkg, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4051 | int theme, CompatibilityInfo compatInfo, |
| 4052 | CharSequence nonLocalizedLabel, int labelRes, int icon, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 4053 | int windowFlags, IBinder transferFrom, boolean createIfNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4054 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4055 | "setAppStartingWindow()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4056 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4057 | } |
| 4058 | |
| 4059 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4060 | if (DEBUG_STARTING_WINDOW) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4061 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 4062 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4063 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4064 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4065 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4066 | 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] | 4067 | return; |
| 4068 | } |
| 4069 | |
| 4070 | // If the display is frozen, we won't do anything until the |
| 4071 | // actual window is displayed so there is no reason to put in |
| 4072 | // the starting window. |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 4073 | if (!okToDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4074 | return; |
| 4075 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4076 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4077 | if (wtoken.startingData != null) { |
| 4078 | return; |
| 4079 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4080 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4081 | if (transferFrom != null) { |
| 4082 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 4083 | if (ttoken != null) { |
| 4084 | WindowState startingWindow = ttoken.startingWindow; |
| 4085 | if (startingWindow != null) { |
| 4086 | if (mStartingIconInTransition) { |
| 4087 | // In this case, the starting icon has already |
| 4088 | // been displayed, so start letting windows get |
| 4089 | // shown immediately without any more transitions. |
| 4090 | mSkipAppTransitionAnimation = true; |
| 4091 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4092 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4093 | "Moving existing starting from " + ttoken |
| 4094 | + " to " + wtoken); |
| 4095 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4096 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4097 | // Transfer the starting window over to the new |
| 4098 | // token. |
| 4099 | wtoken.startingData = ttoken.startingData; |
| 4100 | wtoken.startingView = ttoken.startingView; |
Craig Mautner | f412095 | 2012-06-21 18:25:39 -0700 | [diff] [blame] | 4101 | wtoken.startingDisplayed = ttoken.startingDisplayed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4102 | wtoken.startingWindow = startingWindow; |
Craig Mautner | f412095 | 2012-06-21 18:25:39 -0700 | [diff] [blame] | 4103 | wtoken.reportedVisible = ttoken.reportedVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4104 | ttoken.startingData = null; |
| 4105 | ttoken.startingView = null; |
| 4106 | ttoken.startingWindow = null; |
| 4107 | ttoken.startingMoved = true; |
| 4108 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 4109 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4110 | startingWindow.mAppToken = wtoken; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4111 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) { |
| 4112 | Slog.v(TAG, "Removing starting window: " + startingWindow); |
| 4113 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4114 | startingWindow.getWindowList().remove(startingWindow); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4115 | mWindowsChanged = true; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4116 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, |
| 4117 | "Removing starting " + startingWindow + " from " + ttoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4118 | ttoken.windows.remove(startingWindow); |
| 4119 | ttoken.allAppWindows.remove(startingWindow); |
| 4120 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4121 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4122 | // Propagate other interesting state between the |
| 4123 | // tokens. If the old token is displayed, we should |
| 4124 | // immediately force the new one to be displayed. If |
| 4125 | // it is animating, we need to move that animation to |
| 4126 | // the new one. |
| 4127 | if (ttoken.allDrawn) { |
| 4128 | wtoken.allDrawn = true; |
| 4129 | } |
| 4130 | if (ttoken.firstWindowDrawn) { |
| 4131 | wtoken.firstWindowDrawn = true; |
| 4132 | } |
| 4133 | if (!ttoken.hidden) { |
| 4134 | wtoken.hidden = false; |
| 4135 | wtoken.hiddenRequested = false; |
| 4136 | wtoken.willBeHidden = false; |
| 4137 | } |
| 4138 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 4139 | wtoken.clientHidden = ttoken.clientHidden; |
| 4140 | wtoken.sendAppVisibilityToClients(); |
| 4141 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4142 | final AppWindowAnimator tAppAnimator = ttoken.mAppAnimator; |
| 4143 | final AppWindowAnimator wAppAnimator = wtoken.mAppAnimator; |
| 4144 | if (tAppAnimator.animation != null) { |
| 4145 | wAppAnimator.animation = tAppAnimator.animation; |
| 4146 | wAppAnimator.animating = tAppAnimator.animating; |
| 4147 | wAppAnimator.animLayerAdjustment = tAppAnimator.animLayerAdjustment; |
| 4148 | tAppAnimator.animation = null; |
| 4149 | tAppAnimator.animLayerAdjustment = 0; |
| 4150 | wAppAnimator.updateLayers(); |
| 4151 | tAppAnimator.updateLayers(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4152 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4153 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4154 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4155 | true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4156 | mLayoutNeeded = true; |
| 4157 | performLayoutAndPlaceSurfacesLocked(); |
| 4158 | Binder.restoreCallingIdentity(origId); |
| 4159 | return; |
| 4160 | } else if (ttoken.startingData != null) { |
| 4161 | // The previous app was getting ready to show a |
| 4162 | // starting window, but hasn't yet done so. Steal it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4163 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4164 | "Moving pending starting from " + ttoken |
| 4165 | + " to " + wtoken); |
| 4166 | wtoken.startingData = ttoken.startingData; |
| 4167 | ttoken.startingData = null; |
| 4168 | ttoken.startingMoved = true; |
| 4169 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 4170 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 4171 | // want to process the message ASAP, before any other queued |
| 4172 | // messages. |
| 4173 | mH.sendMessageAtFrontOfQueue(m); |
| 4174 | return; |
| 4175 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4176 | final AppWindowAnimator tAppAnimator = ttoken.mAppAnimator; |
| 4177 | final AppWindowAnimator wAppAnimator = wtoken.mAppAnimator; |
| 4178 | if (tAppAnimator.thumbnail != null) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4179 | // The old token is animating with a thumbnail, transfer |
| 4180 | // that to the new token. |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4181 | if (wAppAnimator.thumbnail != null) { |
| 4182 | wAppAnimator.thumbnail.destroy(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4183 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4184 | wAppAnimator.thumbnail = tAppAnimator.thumbnail; |
| 4185 | wAppAnimator.thumbnailX = tAppAnimator.thumbnailX; |
| 4186 | wAppAnimator.thumbnailY = tAppAnimator.thumbnailY; |
| 4187 | wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer; |
| 4188 | wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation; |
| 4189 | tAppAnimator.thumbnail = null; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4190 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4191 | } |
| 4192 | } |
| 4193 | |
| 4194 | // There is no existing starting window, and the caller doesn't |
| 4195 | // want us to create one, so that's it! |
| 4196 | if (!createIfNeeded) { |
| 4197 | return; |
| 4198 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4199 | |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 4200 | // If this is a translucent window, then don't |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 4201 | // show a starting window -- the current effect (a full-screen |
| 4202 | // opaque starting window that fades away to the real contents |
| 4203 | // when it is ready) does not work for this. |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4204 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Checking theme of starting window: 0x" |
| 4205 | + Integer.toHexString(theme)); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 4206 | if (theme != 0) { |
| 4207 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 4208 | com.android.internal.R.styleable.Window); |
Dianne Hackborn | 0b80019 | 2012-06-21 15:29:36 -0700 | [diff] [blame] | 4209 | if (ent == null) { |
| 4210 | // Whoops! App doesn't exist. Um. Okay. We'll just |
| 4211 | // pretend like we didn't see that. |
| 4212 | return; |
| 4213 | } |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4214 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Translucent=" |
| 4215 | + ent.array.getBoolean( |
| 4216 | com.android.internal.R.styleable.Window_windowIsTranslucent, false) |
| 4217 | + " Floating=" |
| 4218 | + ent.array.getBoolean( |
| 4219 | com.android.internal.R.styleable.Window_windowIsFloating, false) |
| 4220 | + " ShowWallpaper=" |
| 4221 | + ent.array.getBoolean( |
| 4222 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 4223 | if (ent.array.getBoolean( |
| 4224 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 4225 | return; |
| 4226 | } |
| 4227 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 4228 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 4229 | return; |
| 4230 | } |
| 4231 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 4232 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 4233 | if (mWallpaperTarget == null) { |
| 4234 | // If this theme is requesting a wallpaper, and the wallpaper |
| 4235 | // is not curently visible, then this effectively serves as |
| 4236 | // an opaque window and our starting window transition animation |
| 4237 | // can still work. We just need to make sure the starting window |
| 4238 | // is also showing the wallpaper. |
| 4239 | windowFlags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 4240 | } else { |
| 4241 | return; |
| 4242 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 4243 | } |
| 4244 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4245 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4246 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Creating StartingData"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4247 | mStartingIconInTransition = true; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4248 | wtoken.startingData = new StartingData(pkg, theme, compatInfo, nonLocalizedLabel, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 4249 | labelRes, icon, windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4250 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 4251 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 4252 | // want to process the message ASAP, before any other queued |
| 4253 | // messages. |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4254 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Enqueueing ADD_STARTING"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4255 | mH.sendMessageAtFrontOfQueue(m); |
| 4256 | } |
| 4257 | } |
| 4258 | |
| 4259 | public void setAppWillBeHidden(IBinder token) { |
| 4260 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4261 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4262 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | AppWindowToken wtoken; |
| 4266 | |
| 4267 | synchronized(mWindowMap) { |
| 4268 | wtoken = findAppWindowToken(token); |
| 4269 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4270 | 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] | 4271 | return; |
| 4272 | } |
| 4273 | wtoken.willBeHidden = true; |
| 4274 | } |
| 4275 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4276 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4277 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 4278 | boolean visible, int transit, boolean performLayout) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4279 | boolean delayed = false; |
| 4280 | |
| 4281 | if (wtoken.clientHidden == visible) { |
| 4282 | wtoken.clientHidden = !visible; |
| 4283 | wtoken.sendAppVisibilityToClients(); |
| 4284 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4286 | wtoken.willBeHidden = false; |
| 4287 | if (wtoken.hidden == visible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4288 | boolean changed = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4289 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4290 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 4291 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4292 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4293 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4294 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4295 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
Craig Mautner | fbf378c | 2012-04-23 17:24:21 -0700 | [diff] [blame] | 4296 | if (wtoken.mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4297 | wtoken.mAppAnimator.animation = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4298 | } |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 4299 | if (applyAnimationLocked(wtoken, lp, transit, visible)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4300 | delayed = runningAppAnimation = true; |
| 4301 | } |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 4302 | changed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4303 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4304 | |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 4305 | final int N = wtoken.allAppWindows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4306 | for (int i=0; i<N; i++) { |
| 4307 | WindowState win = wtoken.allAppWindows.get(i); |
| 4308 | if (win == wtoken.startingWindow) { |
| 4309 | continue; |
| 4310 | } |
| 4311 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4312 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4313 | //win.dump(" "); |
| 4314 | if (visible) { |
| 4315 | if (!win.isVisibleNow()) { |
| 4316 | if (!runningAppAnimation) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 4317 | win.mWinAnimator.applyAnimationLocked( |
| 4318 | WindowManagerPolicy.TRANSIT_ENTER, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4319 | } |
| 4320 | changed = true; |
| 4321 | } |
| 4322 | } else if (win.isVisibleNow()) { |
| 4323 | if (!runningAppAnimation) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 4324 | win.mWinAnimator.applyAnimationLocked( |
| 4325 | WindowManagerPolicy.TRANSIT_EXIT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4326 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4327 | changed = true; |
| 4328 | } |
| 4329 | } |
| 4330 | |
| 4331 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 4332 | if (!visible) { |
| 4333 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4334 | } else { |
| 4335 | // If we are being set visible, and the starting window is |
| 4336 | // not yet displayed, then make sure it doesn't get displayed. |
| 4337 | WindowState swin = wtoken.startingWindow; |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 4338 | if (swin != null && !swin.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4339 | swin.mPolicyVisibility = false; |
| 4340 | swin.mPolicyVisibilityAfterAnim = false; |
| 4341 | } |
| 4342 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4343 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4344 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4345 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 4346 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4347 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4348 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4349 | mLayoutNeeded = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4350 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4351 | if (performLayout) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4352 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4353 | false /*updateInputWindows*/); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4354 | performLayoutAndPlaceSurfacesLocked(); |
| 4355 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4356 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4357 | } |
| 4358 | } |
| 4359 | |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4360 | if (wtoken.mAppAnimator.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4361 | delayed = true; |
| 4362 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4363 | |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 4364 | for (int i = wtoken.allAppWindows.size() - 1; i >= 0 && !delayed; i--) { |
| 4365 | if (wtoken.allAppWindows.get(i).mWinAnimator.isWindowAnimating()) { |
| 4366 | delayed = true; |
| 4367 | } |
| 4368 | } |
| 4369 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4370 | return delayed; |
| 4371 | } |
| 4372 | |
| 4373 | public void setAppVisibility(IBinder token, boolean visible) { |
| 4374 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4375 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4376 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4377 | } |
| 4378 | |
| 4379 | AppWindowToken wtoken; |
| 4380 | |
| 4381 | synchronized(mWindowMap) { |
| 4382 | wtoken = findAppWindowToken(token); |
| 4383 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4384 | 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] | 4385 | return; |
| 4386 | } |
| 4387 | |
| 4388 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4389 | RuntimeException e = null; |
| 4390 | if (!HIDE_STACK_CRAWLS) { |
| 4391 | e = new RuntimeException(); |
| 4392 | e.fillInStackTrace(); |
| 4393 | } |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 4394 | Slog.v(TAG, "setAppVisibility(" + token + ", visible=" + visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4395 | + "): mNextAppTransition=" + mNextAppTransition |
| 4396 | + " hidden=" + wtoken.hidden |
| 4397 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 4398 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4400 | // If we are preparing an app transition, then delay changing |
| 4401 | // the visibility of this token until we execute that transition. |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 4402 | if (okToDisplay() && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4403 | // Already in requested state, don't do anything more. |
| 4404 | if (wtoken.hiddenRequested != visible) { |
| 4405 | return; |
| 4406 | } |
| 4407 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4408 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4409 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4410 | TAG, "Setting dummy animation on: " + wtoken); |
Craig Mautner | f412095 | 2012-06-21 18:25:39 -0700 | [diff] [blame] | 4411 | if (!wtoken.startingDisplayed) { |
| 4412 | wtoken.mAppAnimator.setDummyAnimation(); |
| 4413 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4414 | mOpeningApps.remove(wtoken); |
| 4415 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4416 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4417 | wtoken.inPendingTransaction = true; |
| 4418 | if (visible) { |
| 4419 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4420 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4421 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4422 | // If the token is currently hidden (should be the |
| 4423 | // common case), then we need to set up to wait for |
| 4424 | // its windows to be ready. |
| 4425 | if (wtoken.hidden) { |
| 4426 | wtoken.allDrawn = false; |
| 4427 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4428 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4429 | if (wtoken.clientHidden) { |
| 4430 | // In the case where we are making an app visible |
| 4431 | // but holding off for a transition, we still need |
| 4432 | // to tell the client to make its windows visible so |
| 4433 | // they get drawn. Otherwise, we will wait on |
| 4434 | // performing the transition until all windows have |
| 4435 | // been drawn, they never will be, and we are sad. |
| 4436 | wtoken.clientHidden = false; |
| 4437 | wtoken.sendAppVisibilityToClients(); |
| 4438 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4439 | } |
| 4440 | } else { |
| 4441 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4442 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4443 | // If the token is currently visible (should be the |
| 4444 | // common case), then set up to wait for it to be hidden. |
| 4445 | if (!wtoken.hidden) { |
| 4446 | wtoken.waitingToHide = true; |
| 4447 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4448 | } |
| 4449 | return; |
| 4450 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4451 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4452 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4453 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 4454 | true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4455 | wtoken.updateReportedVisibilityLocked(); |
| 4456 | Binder.restoreCallingIdentity(origId); |
| 4457 | } |
| 4458 | } |
| 4459 | |
| 4460 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4461 | boolean unfreezeSurfaceNow, boolean force) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4462 | if (wtoken.mAppAnimator.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4463 | 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] | 4464 | + " force=" + force); |
| 4465 | final int N = wtoken.allAppWindows.size(); |
| 4466 | boolean unfrozeWindows = false; |
| 4467 | for (int i=0; i<N; i++) { |
| 4468 | WindowState w = wtoken.allAppWindows.get(i); |
| 4469 | if (w.mAppFreezing) { |
| 4470 | w.mAppFreezing = false; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 4471 | if (w.mHasSurface && !w.mOrientationChanging) { |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 4472 | if (DEBUG_ORIENTATION) Slog.v(TAG, "set mOrientationChanging of " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4473 | w.mOrientationChanging = true; |
Craig Mautner | 3255a28 | 2012-04-16 15:42:47 -0700 | [diff] [blame] | 4474 | mInnerFields.mOrientationChangeComplete = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4475 | } |
| 4476 | unfrozeWindows = true; |
| 4477 | } |
| 4478 | } |
| 4479 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4480 | if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4481 | wtoken.mAppAnimator.freezingScreen = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4482 | mAppsFreezingScreen--; |
| 4483 | } |
| 4484 | if (unfreezeSurfaceNow) { |
| 4485 | if (unfrozeWindows) { |
| 4486 | mLayoutNeeded = true; |
| 4487 | performLayoutAndPlaceSurfacesLocked(); |
| 4488 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4489 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4490 | } |
| 4491 | } |
| 4492 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4494 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4495 | int configChanges) { |
| 4496 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4497 | RuntimeException e = null; |
| 4498 | if (!HIDE_STACK_CRAWLS) { |
| 4499 | e = new RuntimeException(); |
| 4500 | e.fillInStackTrace(); |
| 4501 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4502 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4503 | + ": hidden=" + wtoken.hidden + " freezing=" |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4504 | + wtoken.mAppAnimator.freezingScreen, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4505 | } |
| 4506 | if (!wtoken.hiddenRequested) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4507 | if (!wtoken.mAppAnimator.freezingScreen) { |
| 4508 | wtoken.mAppAnimator.freezingScreen = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4509 | mAppsFreezingScreen++; |
| 4510 | if (mAppsFreezingScreen == 1) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4511 | startFreezingDisplayLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4512 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 4513 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 4514 | 5000); |
| 4515 | } |
| 4516 | } |
| 4517 | final int N = wtoken.allAppWindows.size(); |
| 4518 | for (int i=0; i<N; i++) { |
| 4519 | WindowState w = wtoken.allAppWindows.get(i); |
| 4520 | w.mAppFreezing = true; |
| 4521 | } |
| 4522 | } |
| 4523 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4525 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 4526 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4527 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4528 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4529 | } |
| 4530 | |
| 4531 | synchronized(mWindowMap) { |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 4532 | if (configChanges == 0 && okToDisplay()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4533 | 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] | 4534 | return; |
| 4535 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4537 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4538 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4539 | 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] | 4540 | return; |
| 4541 | } |
| 4542 | final long origId = Binder.clearCallingIdentity(); |
| 4543 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 4544 | Binder.restoreCallingIdentity(origId); |
| 4545 | } |
| 4546 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4548 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 4549 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4550 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4551 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4552 | } |
| 4553 | |
| 4554 | synchronized(mWindowMap) { |
| 4555 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4556 | if (wtoken == null || wtoken.appToken == null) { |
| 4557 | return; |
| 4558 | } |
| 4559 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4560 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4561 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.mAppAnimator.freezingScreen); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4562 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4563 | Binder.restoreCallingIdentity(origId); |
| 4564 | } |
| 4565 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4567 | public void removeAppToken(IBinder token) { |
| 4568 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4569 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4570 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4571 | } |
| 4572 | |
| 4573 | AppWindowToken wtoken = null; |
| 4574 | AppWindowToken startingToken = null; |
| 4575 | boolean delayed = false; |
| 4576 | |
| 4577 | final long origId = Binder.clearCallingIdentity(); |
| 4578 | synchronized(mWindowMap) { |
| 4579 | WindowToken basewtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4580 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4581 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4582 | delayed = setTokenVisibilityLocked(wtoken, null, false, |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 4583 | WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4584 | wtoken.inPendingTransaction = false; |
| 4585 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4586 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4587 | if (mClosingApps.contains(wtoken)) { |
| 4588 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4589 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4590 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4591 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4592 | delayed = true; |
| 4593 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4594 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4595 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4596 | + " animation=" + wtoken.mAppAnimator.animation |
| 4597 | + " animating=" + wtoken.mAppAnimator.animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4598 | if (delayed) { |
| 4599 | // 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] | 4600 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4601 | "removeAppToken make exiting: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4602 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4603 | } else { |
| 4604 | // Make sure there is no animation running on this token, |
| 4605 | // so any windows associated with it will be removed as |
| 4606 | // soon as their animations are complete |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4607 | wtoken.mAppAnimator.clearAnimation(); |
| 4608 | wtoken.mAppAnimator.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4609 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4610 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4611 | "removeAppToken: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4612 | mAppTokens.remove(wtoken); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4613 | mAnimatingAppTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4614 | wtoken.removed = true; |
| 4615 | if (wtoken.startingData != null) { |
| 4616 | startingToken = wtoken; |
| 4617 | } |
| 4618 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4619 | if (mFocusedApp == wtoken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4620 | 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] | 4621 | mFocusedApp = null; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4622 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4623 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4624 | } |
| 4625 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4626 | 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] | 4627 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4629 | if (!delayed && wtoken != null) { |
| 4630 | wtoken.updateReportedVisibilityLocked(); |
| 4631 | } |
| 4632 | } |
| 4633 | Binder.restoreCallingIdentity(origId); |
| 4634 | |
| 4635 | if (startingToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4636 | 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] | 4637 | + startingToken + ": app token removed"); |
| 4638 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4639 | mH.sendMessage(m); |
| 4640 | } |
| 4641 | } |
| 4642 | |
| 4643 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4644 | final int NW = token.windows.size(); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4645 | if (NW > 0) { |
| 4646 | mWindowsChanged = true; |
| 4647 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4648 | for (int i=0; i<NW; i++) { |
| 4649 | WindowState win = token.windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4650 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4651 | win.getWindowList().remove(win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4652 | int j = win.mChildWindows.size(); |
| 4653 | while (j > 0) { |
| 4654 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4655 | WindowState cwin = win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4656 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4657 | "Tmp removing child window " + cwin); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4658 | cwin.getWindowList().remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4659 | } |
| 4660 | } |
| 4661 | return NW > 0; |
| 4662 | } |
| 4663 | |
| 4664 | void dumpAppTokensLocked() { |
| 4665 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4666 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4667 | } |
| 4668 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4669 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4670 | void dumpAnimatingAppTokensLocked() { |
| 4671 | for (int i=mAnimatingAppTokens.size()-1; i>=0; i--) { |
| 4672 | Slog.v(TAG, " #" + i + ": " + mAnimatingAppTokens.get(i).token); |
| 4673 | } |
| 4674 | } |
| 4675 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4676 | void dumpWindowsLocked() { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4677 | int i = 0; |
| 4678 | final AllWindowsIterator iterator = new AllWindowsIterator(REVERSE_ITERATOR); |
| 4679 | while (iterator.hasNext()) { |
| 4680 | final WindowState w = iterator.next(); |
| 4681 | Slog.v(TAG, " #" + i++ + ": " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4682 | } |
| 4683 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4684 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4685 | private int findWindowOffsetLocked(WindowList windows, int tokenPos) { |
| 4686 | final int NW = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4687 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4688 | if (tokenPos >= mAnimatingAppTokens.size()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4689 | int i = NW; |
| 4690 | while (i > 0) { |
| 4691 | i--; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4692 | WindowState win = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4693 | if (win.getAppToken() != null) { |
| 4694 | return i+1; |
| 4695 | } |
| 4696 | } |
| 4697 | } |
| 4698 | |
| 4699 | while (tokenPos > 0) { |
| 4700 | // Find the first app token below the new position that has |
| 4701 | // a window displayed. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4702 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4703 | 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] | 4704 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4705 | if (wtoken.sendingToBottom) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4706 | if (DEBUG_REORDER) Slog.v(TAG, |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4707 | "Skipping token -- currently sending to bottom"); |
| 4708 | tokenPos--; |
| 4709 | continue; |
| 4710 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4711 | int i = wtoken.windows.size(); |
| 4712 | while (i > 0) { |
| 4713 | i--; |
| 4714 | WindowState win = wtoken.windows.get(i); |
| 4715 | int j = win.mChildWindows.size(); |
| 4716 | while (j > 0) { |
| 4717 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4718 | WindowState cwin = win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4719 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4720 | for (int pos=NW-1; pos>=0; pos--) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4721 | if (windows.get(pos) == cwin) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4722 | if (DEBUG_REORDER) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4723 | "Found child win @" + (pos+1)); |
| 4724 | return pos+1; |
| 4725 | } |
| 4726 | } |
| 4727 | } |
| 4728 | } |
| 4729 | for (int pos=NW-1; pos>=0; pos--) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4730 | if (windows.get(pos) == win) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4731 | 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] | 4732 | return pos+1; |
| 4733 | } |
| 4734 | } |
| 4735 | } |
| 4736 | tokenPos--; |
| 4737 | } |
| 4738 | |
| 4739 | return 0; |
| 4740 | } |
| 4741 | |
| 4742 | private final int reAddWindowLocked(int index, WindowState win) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4743 | final WindowList windows = win.getWindowList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4744 | final int NCW = win.mChildWindows.size(); |
| 4745 | boolean added = false; |
| 4746 | for (int j=0; j<NCW; j++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4747 | WindowState cwin = win.mChildWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4748 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4749 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4750 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4751 | win.mRebuilding = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4752 | windows.add(index, win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4753 | index++; |
| 4754 | added = true; |
| 4755 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4756 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4757 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4758 | cwin.mRebuilding = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4759 | windows.add(index, cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4760 | index++; |
| 4761 | } |
| 4762 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4763 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4764 | + index + ": " + win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4765 | win.mRebuilding = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4766 | windows.add(index, win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4767 | index++; |
| 4768 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4769 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4770 | return index; |
| 4771 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4772 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4773 | private final int reAddAppWindowsLocked(final DisplayContent displayContent, int index, |
| 4774 | WindowToken token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4775 | final int NW = token.windows.size(); |
| 4776 | for (int i=0; i<NW; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4777 | final WindowState win = token.windows.get(i); |
| 4778 | if (win.mDisplayContent == displayContent) { |
| 4779 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4780 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4781 | } |
| 4782 | return index; |
| 4783 | } |
| 4784 | |
| 4785 | public void moveAppToken(int index, IBinder token) { |
| 4786 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4787 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4788 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4789 | } |
| 4790 | |
| 4791 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4792 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4793 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4794 | final AppWindowToken wtoken = findAppWindowToken(token); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4795 | final int oldIndex = mAppTokens.indexOf(wtoken); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4796 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4797 | "Start moving token " + wtoken + " initially at " |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4798 | + oldIndex); |
| 4799 | if (oldIndex > index && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET |
| 4800 | && !mAppTransitionRunning) { |
| 4801 | // animation towards back has not started, copy old list for duration of animation. |
| 4802 | mAnimatingAppTokens.clear(); |
| 4803 | mAnimatingAppTokens.addAll(mAppTokens); |
| 4804 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4805 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4806 | 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] | 4807 | + token + " (" + wtoken + ")"); |
| 4808 | return; |
| 4809 | } |
| 4810 | mAppTokens.add(index, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4811 | if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4812 | 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] | 4813 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4814 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET && !mAppTransitionRunning) { |
| 4815 | // Not animating, bring animating app list in line with mAppTokens. |
| 4816 | mAnimatingAppTokens.clear(); |
| 4817 | mAnimatingAppTokens.addAll(mAppTokens); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4818 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4819 | // Bring window ordering, window focus and input window in line with new app token |
| 4820 | final long origId = Binder.clearCallingIdentity(); |
| 4821 | 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] | 4822 | if (DEBUG_REORDER) dumpWindowsLocked(); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4823 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| 4824 | if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:"); |
| 4825 | if (DEBUG_REORDER) dumpWindowsLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4826 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 4827 | while(iterator.hasNext()) { |
| 4828 | final DisplayContent displayContent = iterator.next(); |
| 4829 | final WindowList windows = displayContent.getWindowList(); |
| 4830 | final int pos = findWindowOffsetLocked(windows, index); |
| 4831 | reAddAppWindowsLocked(displayContent, pos, wtoken); |
| 4832 | } |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4833 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
| 4834 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4835 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4836 | false /*updateInputWindows*/); |
| 4837 | mLayoutNeeded = true; |
| 4838 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 4839 | performLayoutAndPlaceSurfacesLocked(); |
| 4840 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| 4841 | } |
| 4842 | Binder.restoreCallingIdentity(origId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4843 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4844 | } |
| 4845 | } |
| 4846 | |
| 4847 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4848 | // XXX This should be done more efficiently! |
| 4849 | // (take advantage of the fact that both lists should be |
| 4850 | // ordered in the same way.) |
| 4851 | int N = tokens.size(); |
| 4852 | for (int i=0; i<N; i++) { |
| 4853 | IBinder token = tokens.get(i); |
| 4854 | final AppWindowToken wtoken = findAppWindowToken(token); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4855 | if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4856 | "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4857 | if (!mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4858 | 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] | 4859 | + token + " (" + wtoken + ")"); |
| 4860 | i--; |
| 4861 | N--; |
| 4862 | } |
| 4863 | } |
| 4864 | } |
| 4865 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4866 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4867 | boolean updateFocusAndLayout) { |
| 4868 | // First remove all of the windows from the list. |
| 4869 | tmpRemoveAppWindowsLocked(wtoken); |
| 4870 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4871 | // And now add them back at the correct place. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4872 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 4873 | while (iterator.hasNext()) { |
| 4874 | final DisplayContent displayContent = iterator.next(); |
| 4875 | final WindowList windows = displayContent.getWindowList(); |
| 4876 | final int pos = findWindowOffsetLocked(windows, tokenPos); |
| 4877 | reAddAppWindowsLocked(displayContent, pos, wtoken); |
| 4878 | |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 4879 | if (updateFocusAndLayout && !updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4880 | false /*updateInputWindows*/)) { |
| 4881 | assignLayersLocked(windows); |
| 4882 | } |
| 4883 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4884 | |
| 4885 | if (updateFocusAndLayout) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4886 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4887 | |
| 4888 | // Note that the above updateFocusedWindowLocked conditional used to sit here. |
| 4889 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4890 | mLayoutNeeded = true; |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4891 | if (!mInLayout) { |
| 4892 | performLayoutAndPlaceSurfacesLocked(); |
| 4893 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4894 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4895 | } |
| 4896 | } |
| 4897 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4898 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4899 | // First remove all of the windows from the list. |
| 4900 | final int N = tokens.size(); |
| 4901 | int i; |
| 4902 | for (i=0; i<N; i++) { |
| 4903 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4904 | if (token != null) { |
| 4905 | tmpRemoveAppWindowsLocked(token); |
| 4906 | } |
| 4907 | } |
| 4908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4909 | // And now add them back at the correct place. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4910 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 4911 | while (iterator.hasNext()) { |
| 4912 | final DisplayContent displayContent = iterator.next(); |
| 4913 | final WindowList windows = displayContent.getWindowList(); |
| 4914 | // Where to start adding? |
| 4915 | int pos = findWindowOffsetLocked(windows, tokenPos); |
| 4916 | for (i=0; i<N; i++) { |
| 4917 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4918 | if (token != null) { |
| 4919 | pos = reAddAppWindowsLocked(displayContent, pos, token); |
| 4920 | } |
| 4921 | } |
| 4922 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4923 | false /*updateInputWindows*/)) { |
| 4924 | assignLayersLocked(windows); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4925 | } |
| 4926 | } |
| 4927 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4928 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4929 | |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 4930 | // Note that the above updateFocusedWindowLocked used to sit here. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4931 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4932 | mLayoutNeeded = true; |
| 4933 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4934 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4935 | |
| 4936 | //dump(); |
| 4937 | } |
| 4938 | |
| 4939 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4940 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4941 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4942 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4943 | } |
| 4944 | |
| 4945 | final long origId = Binder.clearCallingIdentity(); |
| 4946 | synchronized(mWindowMap) { |
| 4947 | removeAppTokensLocked(tokens); |
| 4948 | final int N = tokens.size(); |
| 4949 | for (int i=0; i<N; i++) { |
| 4950 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4951 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4952 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4953 | "Adding next to top: " + wt); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4954 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4955 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4956 | wt.sendingToBottom = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4957 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4958 | } |
| 4959 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4960 | |
Craig Mautner | 06a94f7 | 2012-05-29 10:46:00 -0700 | [diff] [blame] | 4961 | if (!mAppTransitionRunning) { |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4962 | mAnimatingAppTokens.clear(); |
| 4963 | mAnimatingAppTokens.addAll(mAppTokens); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4964 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4965 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4966 | } |
| 4967 | Binder.restoreCallingIdentity(origId); |
| 4968 | } |
| 4969 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4970 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4971 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4972 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4973 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4974 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4975 | } |
| 4976 | |
| 4977 | final long origId = Binder.clearCallingIdentity(); |
| 4978 | synchronized(mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4979 | final int N = tokens.size(); |
Craig Mautner | 06a94f7 | 2012-05-29 10:46:00 -0700 | [diff] [blame] | 4980 | if (N > 0 && !mAppTransitionRunning) { |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4981 | // animating towards back, hang onto old list for duration of animation. |
| 4982 | mAnimatingAppTokens.clear(); |
| 4983 | mAnimatingAppTokens.addAll(mAppTokens); |
| 4984 | } |
| 4985 | removeAppTokensLocked(tokens); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4986 | int pos = 0; |
| 4987 | for (int i=0; i<N; i++) { |
| 4988 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4989 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4990 | if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4991 | "Adding next to bottom: " + wt + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4992 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4993 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4994 | wt.sendingToBottom = true; |
| 4995 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4996 | pos++; |
| 4997 | } |
| 4998 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4999 | |
Craig Mautner | 06a94f7 | 2012-05-29 10:46:00 -0700 | [diff] [blame] | 5000 | if (!mAppTransitionRunning) { |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 5001 | mAnimatingAppTokens.clear(); |
| 5002 | mAnimatingAppTokens.addAll(mAppTokens); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 5003 | moveAppWindowsLocked(tokens, 0); |
| 5004 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5005 | } |
| 5006 | Binder.restoreCallingIdentity(origId); |
| 5007 | } |
| 5008 | |
| 5009 | // ------------------------------------------------------------- |
| 5010 | // Misc IWindowSession methods |
| 5011 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5012 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 5013 | private boolean shouldAllowDisableKeyguard() |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 5014 | { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 5015 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 5016 | // called before DevicePolicyManagerService has started. |
| 5017 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 5018 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 5019 | Context.DEVICE_POLICY_SERVICE); |
| 5020 | if (dpm != null) { |
| 5021 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 5022 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 5023 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 5024 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 5025 | } |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 5026 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 5027 | } |
| 5028 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5029 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 5030 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5031 | != PackageManager.PERMISSION_GRANTED) { |
| 5032 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 5033 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 5034 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 5035 | synchronized (mKeyguardTokenWatcher) { |
| 5036 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 5037 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5038 | } |
| 5039 | |
| 5040 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 5041 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5042 | != PackageManager.PERMISSION_GRANTED) { |
| 5043 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 5044 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5045 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 5046 | synchronized (mKeyguardTokenWatcher) { |
| 5047 | mKeyguardTokenWatcher.release(token); |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 5048 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 5049 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 5050 | // If we are the last one to reenable the keyguard wait until |
| 5051 | // we have actually finished reenabling until returning. |
| 5052 | // It is possible that reenableKeyguard() can be called before |
| 5053 | // the previous disableKeyguard() is handled, in which case |
| 5054 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 5055 | // be called. In that case mKeyguardDisabled will be false here |
| 5056 | // and we have nothing to wait for. |
| 5057 | while (mKeyguardDisabled) { |
| 5058 | try { |
| 5059 | mKeyguardTokenWatcher.wait(); |
| 5060 | } catch (InterruptedException e) { |
| 5061 | Thread.currentThread().interrupt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5062 | } |
| 5063 | } |
| 5064 | } |
| 5065 | } |
| 5066 | } |
| 5067 | |
| 5068 | /** |
| 5069 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 5070 | */ |
| 5071 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 5072 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5073 | != PackageManager.PERMISSION_GRANTED) { |
| 5074 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 5075 | } |
| 5076 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 5077 | public void onKeyguardExitResult(boolean success) { |
| 5078 | try { |
| 5079 | callback.onKeyguardExitResult(success); |
| 5080 | } catch (RemoteException e) { |
| 5081 | // Client has died, we don't care. |
| 5082 | } |
| 5083 | } |
| 5084 | }); |
| 5085 | } |
| 5086 | |
| 5087 | public boolean inKeyguardRestrictedInputMode() { |
| 5088 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 5089 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5090 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5091 | public boolean isKeyguardLocked() { |
| 5092 | return mPolicy.isKeyguardLocked(); |
| 5093 | } |
| 5094 | |
| 5095 | public boolean isKeyguardSecure() { |
| 5096 | return mPolicy.isKeyguardSecure(); |
| 5097 | } |
| 5098 | |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5099 | public void dismissKeyguard() { |
| 5100 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| 5101 | != PackageManager.PERMISSION_GRANTED) { |
| 5102 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 5103 | } |
| 5104 | synchronized(mWindowMap) { |
| 5105 | mPolicy.dismissKeyguardLw(); |
| 5106 | } |
| 5107 | } |
| 5108 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 5109 | public void closeSystemDialogs(String reason) { |
| 5110 | synchronized(mWindowMap) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5111 | final AllWindowsIterator iterator = new AllWindowsIterator(); |
| 5112 | while (iterator.hasNext()) { |
| 5113 | final WindowState w = iterator.next(); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 5114 | if (w.mHasSurface) { |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 5115 | try { |
| 5116 | w.mClient.closeSystemDialogs(reason); |
| 5117 | } catch (RemoteException e) { |
| 5118 | } |
| 5119 | } |
| 5120 | } |
| 5121 | } |
| 5122 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5123 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5124 | static float fixScale(float scale) { |
| 5125 | if (scale < 0) scale = 0; |
| 5126 | else if (scale > 20) scale = 20; |
| 5127 | return Math.abs(scale); |
| 5128 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5130 | public void setAnimationScale(int which, float scale) { |
| 5131 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 5132 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5133 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5134 | } |
| 5135 | |
| 5136 | if (scale < 0) scale = 0; |
| 5137 | else if (scale > 20) scale = 20; |
| 5138 | scale = Math.abs(scale); |
| 5139 | switch (which) { |
| 5140 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 5141 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 5142 | case 2: mAnimatorDurationScale = fixScale(scale); break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5143 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5145 | // Persist setting |
| 5146 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 5147 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5148 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5149 | public void setAnimationScales(float[] scales) { |
| 5150 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 5151 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5152 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5153 | } |
| 5154 | |
| 5155 | if (scales != null) { |
| 5156 | if (scales.length >= 1) { |
| 5157 | mWindowAnimationScale = fixScale(scales[0]); |
| 5158 | } |
| 5159 | if (scales.length >= 2) { |
| 5160 | mTransitionAnimationScale = fixScale(scales[1]); |
| 5161 | } |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 5162 | if (scales.length >= 3) { |
| 5163 | mAnimatorDurationScale = fixScale(scales[2]); |
| 5164 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5165 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5167 | // Persist setting |
| 5168 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 5169 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5171 | public float getAnimationScale(int which) { |
| 5172 | switch (which) { |
| 5173 | case 0: return mWindowAnimationScale; |
| 5174 | case 1: return mTransitionAnimationScale; |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 5175 | case 2: return mAnimatorDurationScale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5176 | } |
| 5177 | return 0; |
| 5178 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5180 | public float[] getAnimationScales() { |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 5181 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale, |
| 5182 | mAnimatorDurationScale }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5183 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5184 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5185 | // Called by window manager policy. Not exposed externally. |
| 5186 | @Override |
| 5187 | public int getLidState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5188 | int sw = mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, |
| 5189 | InputManagerService.SW_LID); |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5190 | if (sw > 0) { |
Jeff Brown | 27fd342 | 2012-04-09 11:05:16 -0700 | [diff] [blame] | 5191 | // Switch state: AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL. |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5192 | return LID_CLOSED; |
Jeff Brown | 27fd342 | 2012-04-09 11:05:16 -0700 | [diff] [blame] | 5193 | } else if (sw == 0) { |
| 5194 | // Switch state: AKEY_STATE_UP. |
| 5195 | return LID_OPEN; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5196 | } else { |
Jeff Brown | 27fd342 | 2012-04-09 11:05:16 -0700 | [diff] [blame] | 5197 | // Switch state: AKEY_STATE_UNKNOWN. |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5198 | return LID_ABSENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5199 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5200 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5201 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5202 | // Called by window manager policy. Not exposed externally. |
| 5203 | @Override |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 5204 | public InputChannel monitorInput(String inputChannelName) { |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 5205 | return mInputManager.monitorInput(inputChannelName); |
| 5206 | } |
| 5207 | |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 5208 | // Called by window manager policy. Not exposed externally. |
| 5209 | @Override |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 5210 | public void switchKeyboardLayout(int deviceId, int direction) { |
| 5211 | mInputManager.switchKeyboardLayout(deviceId, direction); |
| 5212 | } |
| 5213 | |
| 5214 | // Called by window manager policy. Not exposed externally. |
| 5215 | @Override |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 5216 | public void shutdown() { |
| 5217 | ShutdownThread.shutdown(mContext, true); |
| 5218 | } |
| 5219 | |
| 5220 | // Called by window manager policy. Not exposed externally. |
| 5221 | @Override |
| 5222 | public void rebootSafeMode() { |
| 5223 | ShutdownThread.rebootSafeMode(mContext, true); |
| 5224 | } |
| 5225 | |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 5226 | public void setInputFilter(IInputFilter filter) { |
| 5227 | if (!checkCallingPermission(android.Manifest.permission.FILTER_EVENTS, "setInputFilter()")) { |
| 5228 | throw new SecurityException("Requires FILTER_EVENTS permission"); |
| 5229 | } |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 5230 | mInputManager.setInputFilter(filter); |
| 5231 | } |
| 5232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5233 | public void enableScreenAfterBoot() { |
| 5234 | synchronized(mWindowMap) { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5235 | if (DEBUG_BOOT) { |
| 5236 | RuntimeException here = new RuntimeException("here"); |
| 5237 | here.fillInStackTrace(); |
| 5238 | Slog.i(TAG, "enableScreenAfterBoot: mDisplayEnabled=" + mDisplayEnabled |
| 5239 | + " mForceDisplayEnabled=" + mForceDisplayEnabled |
| 5240 | + " mShowingBootMessages=" + mShowingBootMessages |
| 5241 | + " mSystemBooted=" + mSystemBooted, here); |
| 5242 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5243 | if (mSystemBooted) { |
| 5244 | return; |
| 5245 | } |
| 5246 | mSystemBooted = true; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5247 | hideBootMessagesLocked(); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5248 | // If the screen still doesn't come up after 30 seconds, give |
| 5249 | // up and turn it on. |
| 5250 | Message msg = mH.obtainMessage(H.BOOT_TIMEOUT); |
| 5251 | mH.sendMessageDelayed(msg, 30*1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5252 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5253 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5254 | mPolicy.systemBooted(); |
| 5255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5256 | performEnableScreen(); |
| 5257 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5258 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5259 | void enableScreenIfNeededLocked() { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5260 | if (DEBUG_BOOT) { |
| 5261 | RuntimeException here = new RuntimeException("here"); |
| 5262 | here.fillInStackTrace(); |
| 5263 | Slog.i(TAG, "enableScreenIfNeededLocked: mDisplayEnabled=" + mDisplayEnabled |
| 5264 | + " mForceDisplayEnabled=" + mForceDisplayEnabled |
| 5265 | + " mShowingBootMessages=" + mShowingBootMessages |
| 5266 | + " mSystemBooted=" + mSystemBooted, here); |
| 5267 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5268 | if (mDisplayEnabled) { |
| 5269 | return; |
| 5270 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5271 | if (!mSystemBooted && !mShowingBootMessages) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5272 | return; |
| 5273 | } |
| 5274 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 5275 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5276 | |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5277 | public void performBootTimeout() { |
| 5278 | synchronized(mWindowMap) { |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 5279 | if (mDisplayEnabled || mHeadless) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5280 | return; |
| 5281 | } |
| 5282 | Slog.w(TAG, "***** BOOT TIMEOUT: forcing display enabled"); |
| 5283 | mForceDisplayEnabled = true; |
| 5284 | } |
| 5285 | performEnableScreen(); |
| 5286 | } |
| 5287 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5288 | public void performEnableScreen() { |
| 5289 | synchronized(mWindowMap) { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5290 | if (DEBUG_BOOT) { |
| 5291 | RuntimeException here = new RuntimeException("here"); |
| 5292 | here.fillInStackTrace(); |
| 5293 | Slog.i(TAG, "performEnableScreen: mDisplayEnabled=" + mDisplayEnabled |
| 5294 | + " mForceDisplayEnabled=" + mForceDisplayEnabled |
| 5295 | + " mShowingBootMessages=" + mShowingBootMessages |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 5296 | + " mSystemBooted=" + mSystemBooted |
| 5297 | + " mOnlyCore=" + mOnlyCore, here); |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5298 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5299 | if (mDisplayEnabled) { |
| 5300 | return; |
| 5301 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5302 | if (!mSystemBooted && !mShowingBootMessages) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5303 | return; |
| 5304 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5305 | |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5306 | if (!mForceDisplayEnabled) { |
| 5307 | // Don't enable the screen until all existing windows |
| 5308 | // have been drawn. |
| 5309 | boolean haveBootMsg = false; |
| 5310 | boolean haveApp = false; |
Justin Mattson | 4233f26 | 2012-04-09 18:23:16 -0700 | [diff] [blame] | 5311 | // if the wallpaper service is disabled on the device, we're never going to have |
| 5312 | // wallpaper, don't bother waiting for it |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5313 | boolean haveWallpaper = false; |
Justin Mattson | 4233f26 | 2012-04-09 18:23:16 -0700 | [diff] [blame] | 5314 | boolean wallpaperEnabled = mContext.getResources().getBoolean( |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 5315 | com.android.internal.R.bool.config_enableWallpaperService) |
| 5316 | && !mOnlyCore; |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5317 | boolean haveKeyguard = true; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5318 | // TODO(multidisplay): Expand to all displays? |
| 5319 | final WindowList windows = getDefaultWindowList(); |
| 5320 | final int N = windows.size(); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5321 | for (int i=0; i<N; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5322 | WindowState w = windows.get(i); |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5323 | if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 5324 | // Only if there is a keyguard attached to the window manager |
| 5325 | // will we consider ourselves as having a keyguard. If it |
| 5326 | // isn't attached, we don't know if it wants to be shown or |
| 5327 | // hidden. If it is attached, we will say we have a keyguard |
| 5328 | // if the window doesn't want to be visible, because in that |
| 5329 | // case it explicitly doesn't want to be shown so we should |
| 5330 | // not delay turning the screen on for it. |
| 5331 | boolean vis = w.mViewVisibility == View.VISIBLE |
| 5332 | && w.mPolicyVisibility; |
| 5333 | haveKeyguard = !vis; |
| 5334 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5335 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| 5336 | return; |
| 5337 | } |
| 5338 | if (w.isDrawnLw()) { |
| 5339 | if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_BOOT_PROGRESS) { |
| 5340 | haveBootMsg = true; |
| 5341 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION) { |
| 5342 | haveApp = true; |
| 5343 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER) { |
| 5344 | haveWallpaper = true; |
| 5345 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 5346 | haveKeyguard = true; |
| 5347 | } |
| 5348 | } |
| 5349 | } |
| 5350 | |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5351 | if (DEBUG_SCREEN_ON || DEBUG_BOOT) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5352 | Slog.i(TAG, "******** booted=" + mSystemBooted + " msg=" + mShowingBootMessages |
| 5353 | + " haveBoot=" + haveBootMsg + " haveApp=" + haveApp |
Justin Mattson | 4233f26 | 2012-04-09 18:23:16 -0700 | [diff] [blame] | 5354 | + " haveWall=" + haveWallpaper + " wallEnabled=" + wallpaperEnabled |
| 5355 | + " haveKeyguard=" + haveKeyguard); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5356 | } |
| 5357 | |
| 5358 | // If we are turning on the screen to show the boot message, |
| 5359 | // don't do it until the boot message is actually displayed. |
| 5360 | if (!mSystemBooted && !haveBootMsg) { |
| 5361 | return; |
| 5362 | } |
| 5363 | |
| 5364 | // If we are turning on the screen after the boot is completed |
| 5365 | // normally, don't do so until we have the application and |
| 5366 | // wallpaper. |
Justin Mattson | 4233f26 | 2012-04-09 18:23:16 -0700 | [diff] [blame] | 5367 | if (mSystemBooted && ((!haveApp && !haveKeyguard) || |
| 5368 | (wallpaperEnabled && !haveWallpaper))) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5369 | return; |
| 5370 | } |
| 5371 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5372 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5373 | mDisplayEnabled = true; |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5374 | if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG, "******************** ENABLING SCREEN!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5375 | if (false) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5376 | StringWriter sw = new StringWriter(); |
| 5377 | PrintWriter pw = new PrintWriter(sw); |
| 5378 | this.dump(null, pw, null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5379 | Slog.i(TAG, sw.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5380 | } |
| 5381 | try { |
| 5382 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 5383 | if (surfaceFlinger != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5384 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5385 | Parcel data = Parcel.obtain(); |
| 5386 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
Jeff Brown | c042ee2 | 2012-05-08 13:03:42 -0700 | [diff] [blame] | 5387 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, // BOOT_FINISHED |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5388 | data, null, 0); |
| 5389 | data.recycle(); |
| 5390 | } |
| 5391 | } catch (RemoteException ex) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5392 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5393 | } |
Jeff Brown | 08a746a | 2012-06-24 12:14:49 -0700 | [diff] [blame] | 5394 | |
| 5395 | // Enable input dispatch. |
| 5396 | mInputMonitor.setEventDispatchingLw(mEventDispatchingEnabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5397 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5398 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5399 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5400 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5401 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5402 | updateRotationUnchecked(false, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5403 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5404 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5405 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 5406 | boolean first = false; |
| 5407 | synchronized(mWindowMap) { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5408 | if (DEBUG_BOOT) { |
| 5409 | RuntimeException here = new RuntimeException("here"); |
| 5410 | here.fillInStackTrace(); |
| 5411 | Slog.i(TAG, "showBootMessage: msg=" + msg + " always=" + always |
| 5412 | + " mAllowBootMessages=" + mAllowBootMessages |
| 5413 | + " mShowingBootMessages=" + mShowingBootMessages |
| 5414 | + " mSystemBooted=" + mSystemBooted, here); |
| 5415 | } |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 5416 | if (!mAllowBootMessages) { |
| 5417 | return; |
| 5418 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5419 | if (!mShowingBootMessages) { |
| 5420 | if (!always) { |
| 5421 | return; |
| 5422 | } |
| 5423 | first = true; |
| 5424 | } |
| 5425 | if (mSystemBooted) { |
| 5426 | return; |
| 5427 | } |
| 5428 | mShowingBootMessages = true; |
| 5429 | mPolicy.showBootMessage(msg, always); |
| 5430 | } |
| 5431 | if (first) { |
| 5432 | performEnableScreen(); |
| 5433 | } |
| 5434 | } |
| 5435 | |
| 5436 | public void hideBootMessagesLocked() { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5437 | if (DEBUG_BOOT) { |
| 5438 | RuntimeException here = new RuntimeException("here"); |
| 5439 | here.fillInStackTrace(); |
| 5440 | Slog.i(TAG, "hideBootMessagesLocked: mDisplayEnabled=" + mDisplayEnabled |
| 5441 | + " mForceDisplayEnabled=" + mForceDisplayEnabled |
| 5442 | + " mShowingBootMessages=" + mShowingBootMessages |
| 5443 | + " mSystemBooted=" + mSystemBooted, here); |
| 5444 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5445 | if (mShowingBootMessages) { |
| 5446 | mShowingBootMessages = false; |
| 5447 | mPolicy.hideBootMessages(); |
| 5448 | } |
| 5449 | } |
| 5450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5451 | public void setInTouchMode(boolean mode) { |
| 5452 | synchronized(mWindowMap) { |
| 5453 | mInTouchMode = mode; |
| 5454 | } |
| 5455 | } |
| 5456 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5457 | // TODO: more accounting of which pid(s) turned it on, keep count, |
| 5458 | // only allow disables from pids which have count on, etc. |
Craig Mautner | 0447a81 | 2012-05-22 16:01:31 -0700 | [diff] [blame] | 5459 | @Override |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5460 | public void showStrictModeViolation(boolean on) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5461 | if (mHeadless) return; |
Craig Mautner | 0447a81 | 2012-05-22 16:01:31 -0700 | [diff] [blame] | 5462 | mH.sendMessage(mH.obtainMessage(H.SHOW_STRICT_MODE_VIOLATION, on ? 1 : 0, 0)); |
| 5463 | } |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5464 | |
Craig Mautner | 0447a81 | 2012-05-22 16:01:31 -0700 | [diff] [blame] | 5465 | private void showStrictModeViolation(int arg) { |
| 5466 | final boolean on = arg != 0; |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5467 | int pid = Binder.getCallingPid(); |
| 5468 | synchronized(mWindowMap) { |
| 5469 | // Ignoring requests to enable the red border from clients |
| 5470 | // which aren't on screen. (e.g. Broadcast Receivers in |
| 5471 | // the background..) |
| 5472 | if (on) { |
| 5473 | boolean isVisible = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5474 | final AllWindowsIterator iterator = new AllWindowsIterator(); |
| 5475 | while (iterator.hasNext()) { |
| 5476 | final WindowState ws = iterator.next(); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5477 | if (ws.mSession.mPid == pid && ws.isVisibleLw()) { |
| 5478 | isVisible = true; |
| 5479 | break; |
| 5480 | } |
| 5481 | } |
| 5482 | if (!isVisible) { |
| 5483 | return; |
| 5484 | } |
| 5485 | } |
| 5486 | |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 5487 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 5488 | ">>> OPEN TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5489 | Surface.openTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5490 | try { |
| 5491 | if (mStrictModeFlash == null) { |
| 5492 | mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession); |
| 5493 | } |
| 5494 | mStrictModeFlash.setVisibility(on); |
| 5495 | } finally { |
| 5496 | Surface.closeTransaction(); |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 5497 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 5498 | "<<< CLOSE TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5499 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5500 | } |
| 5501 | } |
| 5502 | |
Brad Fitzpatrick | c1a968a | 2010-11-24 08:56:40 -0800 | [diff] [blame] | 5503 | public void setStrictModeVisualIndicatorPreference(String value) { |
| 5504 | SystemProperties.set(StrictMode.VISUAL_PROPERTY, value); |
| 5505 | } |
| 5506 | |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5507 | /** |
| 5508 | * Takes a snapshot of the screen. In landscape mode this grabs the whole screen. |
| 5509 | * In portrait mode, it grabs the upper region of the screen based on the vertical dimension |
| 5510 | * of the target image. |
| 5511 | * |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5512 | * @param displayId the Display to take a screenshot of. |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5513 | * @param width the width of the target bitmap |
| 5514 | * @param height the height of the target bitmap |
| 5515 | */ |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5516 | public Bitmap screenshotApplications(IBinder appToken, int displayId, int width, int height) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5517 | if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER, |
| 5518 | "screenshotApplications()")) { |
| 5519 | throw new SecurityException("Requires READ_FRAME_BUFFER permission"); |
| 5520 | } |
| 5521 | |
| 5522 | Bitmap rawss; |
| 5523 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5524 | int maxLayer = 0; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5525 | final Rect frame = new Rect(); |
| 5526 | |
| 5527 | float scale; |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5528 | int dw, dh; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5529 | int rot; |
| 5530 | |
| 5531 | synchronized(mWindowMap) { |
| 5532 | long ident = Binder.clearCallingIdentity(); |
| 5533 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5534 | final DisplayContent displayContent = getDisplayContent(displayId); |
| 5535 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 5536 | dw = displayInfo.logicalWidth; |
| 5537 | dh = displayInfo.logicalHeight; |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5538 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5539 | int aboveAppLayer = mPolicy.windowTypeToLayerLw( |
| 5540 | WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER |
| 5541 | + TYPE_LAYER_OFFSET; |
| 5542 | aboveAppLayer += TYPE_LAYER_MULTIPLIER; |
| 5543 | |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5544 | boolean isImeTarget = mInputMethodTarget != null |
| 5545 | && mInputMethodTarget.mAppToken != null |
| 5546 | && mInputMethodTarget.mAppToken.appToken != null |
| 5547 | && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken; |
| 5548 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5549 | // Figure out the part of the screen that is actually the app. |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5550 | boolean including = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5551 | final WindowList windows = displayContent.getWindowList(); |
| 5552 | for (int i = windows.size() - 1; i >= 0; i--) { |
| 5553 | WindowState ws = windows.get(i); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 5554 | if (!ws.mHasSurface) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5555 | continue; |
| 5556 | } |
| 5557 | if (ws.mLayer >= aboveAppLayer) { |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5558 | continue; |
| 5559 | } |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5560 | // When we will skip windows: when we are not including |
| 5561 | // ones behind a window we didn't skip, and we are actually |
| 5562 | // taking a screenshot of a specific app. |
| 5563 | if (!including && appToken != null) { |
| 5564 | // Also, we can possibly skip this window if it is not |
| 5565 | // an IME target or the application for the screenshot |
| 5566 | // is not the current IME target. |
| 5567 | if (!ws.mIsImWindow || !isImeTarget) { |
| 5568 | // And finally, this window is of no interest if it |
| 5569 | // is not associated with the screenshot app. |
| 5570 | if (ws.mAppToken == null || ws.mAppToken.token != appToken) { |
| 5571 | continue; |
| 5572 | } |
| 5573 | } |
| 5574 | } |
| 5575 | |
| 5576 | // We keep on including windows until we go past a full-screen |
| 5577 | // window. |
| 5578 | including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh); |
| 5579 | |
Craig Mautner | 8816568 | 2012-05-31 14:25:31 -0700 | [diff] [blame] | 5580 | if (maxLayer < ws.mWinAnimator.mSurfaceLayer) { |
| 5581 | maxLayer = ws.mWinAnimator.mSurfaceLayer; |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5582 | } |
Jim Miller | 2aded18 | 2011-03-08 15:32:42 -0800 | [diff] [blame] | 5583 | |
| 5584 | // Don't include wallpaper in bounds calculation |
| 5585 | if (!ws.mIsWallpaper) { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 5586 | final Rect wf = ws.mFrame; |
Jim Miller | 2aded18 | 2011-03-08 15:32:42 -0800 | [diff] [blame] | 5587 | final Rect cr = ws.mContentInsets; |
| 5588 | int left = wf.left + cr.left; |
| 5589 | int top = wf.top + cr.top; |
| 5590 | int right = wf.right - cr.right; |
| 5591 | int bottom = wf.bottom - cr.bottom; |
| 5592 | frame.union(left, top, right, bottom); |
| 5593 | } |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5594 | } |
| 5595 | Binder.restoreCallingIdentity(ident); |
| 5596 | |
Dianne Hackborn | dd962ee | 2011-02-02 11:11:50 -0800 | [diff] [blame] | 5597 | // Constrain frame to the screen size. |
| 5598 | frame.intersect(0, 0, dw, dh); |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5599 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5600 | if (frame.isEmpty() || maxLayer == 0) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5601 | return null; |
| 5602 | } |
| 5603 | |
| 5604 | // The screenshot API does not apply the current screen rotation. |
| 5605 | rot = mDisplay.getRotation(); |
| 5606 | int fw = frame.width(); |
| 5607 | int fh = frame.height(); |
| 5608 | |
Jim Miller | 28637ba | 2011-07-06 19:57:05 -0700 | [diff] [blame] | 5609 | // Constrain thumbnail to smaller of screen width or height. Assumes aspect |
| 5610 | // of thumbnail is the same as the screen (in landscape) or square. |
Michael Jurka | bfd24ac | 2011-11-13 13:50:38 -0800 | [diff] [blame] | 5611 | float targetWidthScale = width / (float) fw; |
| 5612 | float targetHeightScale = height / (float) fh; |
Jim Miller | 28637ba | 2011-07-06 19:57:05 -0700 | [diff] [blame] | 5613 | if (dw <= dh) { |
Michael Jurka | bfd24ac | 2011-11-13 13:50:38 -0800 | [diff] [blame] | 5614 | scale = targetWidthScale; |
| 5615 | // If aspect of thumbnail is the same as the screen (in landscape), |
| 5616 | // select the slightly larger value so we fill the entire bitmap |
| 5617 | if (targetHeightScale > scale && (int) (targetHeightScale * fw) == width) { |
| 5618 | scale = targetHeightScale; |
| 5619 | } |
Jim Miller | 28637ba | 2011-07-06 19:57:05 -0700 | [diff] [blame] | 5620 | } else { |
Michael Jurka | bfd24ac | 2011-11-13 13:50:38 -0800 | [diff] [blame] | 5621 | scale = targetHeightScale; |
| 5622 | // If aspect of thumbnail is the same as the screen (in landscape), |
| 5623 | // select the slightly larger value so we fill the entire bitmap |
| 5624 | if (targetWidthScale > scale && (int) (targetWidthScale * fh) == height) { |
| 5625 | scale = targetWidthScale; |
| 5626 | } |
Jim Miller | 28637ba | 2011-07-06 19:57:05 -0700 | [diff] [blame] | 5627 | } |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5628 | |
| 5629 | // The screen shot will contain the entire screen. |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5630 | dw = (int)(dw*scale); |
| 5631 | dh = (int)(dh*scale); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5632 | if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) { |
| 5633 | int tmp = dw; |
| 5634 | dw = dh; |
| 5635 | dh = tmp; |
| 5636 | rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90; |
| 5637 | } |
Dianne Hackborn | cfb9f2b | 2011-08-24 10:51:49 -0700 | [diff] [blame] | 5638 | if (DEBUG_SCREENSHOT) { |
| 5639 | Slog.i(TAG, "Screenshot: " + dw + "x" + dh + " from 0 to " + maxLayer); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5640 | for (int i = 0; i < windows.size(); i++) { |
| 5641 | WindowState win = windows.get(i); |
| 5642 | Slog.i(TAG, win + ": " + win.mLayer |
| 5643 | + " animLayer=" + win.mWinAnimator.mAnimLayer |
| 5644 | + " surfaceLayer=" + win.mWinAnimator.mSurfaceLayer); |
Dianne Hackborn | cfb9f2b | 2011-08-24 10:51:49 -0700 | [diff] [blame] | 5645 | } |
| 5646 | } |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5647 | rawss = Surface.screenshot(dw, dh, 0, maxLayer); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5648 | } |
| 5649 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5650 | if (rawss == null) { |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 5651 | Slog.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh |
Dianne Hackborn | 88b03bd | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5652 | + ") to layer " + maxLayer); |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5653 | return null; |
| 5654 | } |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5655 | |
| 5656 | Bitmap bm = Bitmap.createBitmap(width, height, rawss.getConfig()); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5657 | Matrix matrix = new Matrix(); |
| 5658 | ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix); |
Michael Jurka | 4accb6a | 2012-03-26 09:18:46 -0700 | [diff] [blame] | 5659 | matrix.postTranslate(-FloatMath.ceil(frame.left*scale), -FloatMath.ceil(frame.top*scale)); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5660 | Canvas canvas = new Canvas(bm); |
| 5661 | canvas.drawBitmap(rawss, matrix, null); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 5662 | canvas.setBitmap(null); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5663 | |
| 5664 | rawss.recycle(); |
| 5665 | return bm; |
| 5666 | } |
| 5667 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5668 | /** |
| 5669 | * Freeze rotation changes. (Enable "rotation lock".) |
| 5670 | * Persists across reboots. |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5671 | * @param rotation The desired rotation to freeze to, or -1 to use the |
| 5672 | * current rotation. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5673 | */ |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5674 | public void freezeRotation(int rotation) { |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5675 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5676 | "freezeRotation()")) { |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5677 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5678 | } |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5679 | if (rotation < -1 || rotation > Surface.ROTATION_270) { |
| 5680 | throw new IllegalArgumentException("Rotation argument must be -1 or a valid " |
| 5681 | + "rotation constant."); |
| 5682 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5683 | |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5684 | if (DEBUG_ORIENTATION) Slog.v(TAG, "freezeRotation: mRotation=" + mRotation); |
| 5685 | |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5686 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, |
| 5687 | rotation == -1 ? mRotation : rotation); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5688 | updateRotationUnchecked(false, false); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5689 | } |
| 5690 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5691 | /** |
| 5692 | * Thaw rotation changes. (Disable "rotation lock".) |
| 5693 | * Persists across reboots. |
| 5694 | */ |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5695 | public void thawRotation() { |
| 5696 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5697 | "thawRotation()")) { |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5698 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5699 | } |
| 5700 | |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5701 | if (DEBUG_ORIENTATION) Slog.v(TAG, "thawRotation: mRotation=" + mRotation); |
| 5702 | |
| 5703 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 777); // rot not used |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5704 | updateRotationUnchecked(false, false); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5705 | } |
| 5706 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5707 | /** |
| 5708 | * Recalculate the current rotation. |
| 5709 | * |
| 5710 | * Called by the window manager policy whenever the state of the system changes |
| 5711 | * such that the current rotation might need to be updated, such as when the |
| 5712 | * device is docked or rotated into a new posture. |
| 5713 | */ |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5714 | public void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 5715 | updateRotationUnchecked(alwaysSendConfiguration, forceRelayout); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5716 | } |
| 5717 | |
| 5718 | /** |
| 5719 | * Temporarily pauses rotation changes until resumed. |
| 5720 | * |
| 5721 | * This can be used to prevent rotation changes from occurring while the user is |
| 5722 | * performing certain operations, such as drag and drop. |
| 5723 | * |
| 5724 | * This call nests and must be matched by an equal number of calls to {@link #resumeRotation}. |
| 5725 | */ |
| 5726 | void pauseRotationLocked() { |
| 5727 | mDeferredRotationPauseCount += 1; |
| 5728 | } |
| 5729 | |
| 5730 | /** |
| 5731 | * Resumes normal rotation changes after being paused. |
| 5732 | */ |
| 5733 | void resumeRotationLocked() { |
| 5734 | if (mDeferredRotationPauseCount > 0) { |
| 5735 | mDeferredRotationPauseCount -= 1; |
| 5736 | if (mDeferredRotationPauseCount == 0) { |
| 5737 | boolean changed = updateRotationUncheckedLocked(false); |
| 5738 | if (changed) { |
| 5739 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 5740 | } |
| 5741 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5742 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5743 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5744 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5745 | public void updateRotationUnchecked(boolean alwaysSendConfiguration, boolean forceRelayout) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5746 | if(DEBUG_ORIENTATION) Slog.v(TAG, "updateRotationUnchecked(" |
| 5747 | + "alwaysSendConfiguration=" + alwaysSendConfiguration + ")"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5748 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5749 | long origId = Binder.clearCallingIdentity(); |
| 5750 | boolean changed; |
| 5751 | synchronized(mWindowMap) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5752 | changed = updateRotationUncheckedLocked(false); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5753 | if (!changed || forceRelayout) { |
| 5754 | mLayoutNeeded = true; |
| 5755 | performLayoutAndPlaceSurfacesLocked(); |
| 5756 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5757 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5758 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5759 | if (changed || alwaysSendConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5760 | sendNewConfiguration(); |
| 5761 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5762 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5763 | Binder.restoreCallingIdentity(origId); |
| 5764 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5765 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5766 | // TODO(multidisplay): Rotate any display? |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5767 | /** |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5768 | * Updates the current rotation. |
| 5769 | * |
| 5770 | * Returns true if the rotation has been changed. In this case YOU |
| 5771 | * MUST CALL sendNewConfiguration() TO UNFREEZE THE SCREEN. |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5772 | */ |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5773 | public boolean updateRotationUncheckedLocked(boolean inTransaction) { |
| 5774 | if (mDeferredRotationPauseCount > 0) { |
| 5775 | // Rotation updates have been paused temporarily. Defer the update until |
| 5776 | // updates have been resumed. |
| 5777 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation, rotation is paused."); |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 5778 | return false; |
| 5779 | } |
| 5780 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 5781 | if (mAnimator.mScreenRotationAnimation != null && |
| 5782 | mAnimator.mScreenRotationAnimation.isAnimating()) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5783 | // Rotation updates cannot be performed while the previous rotation change |
| 5784 | // animation is still in progress. Skip this update. We will try updating |
| 5785 | // again after the animation is finished and the display is unfrozen. |
| 5786 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation, animation in progress."); |
| 5787 | return false; |
| 5788 | } |
| 5789 | |
| 5790 | if (!mDisplayEnabled) { |
| 5791 | // No point choosing a rotation if the display is not enabled. |
| 5792 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation, display is not enabled."); |
| 5793 | return false; |
| 5794 | } |
| 5795 | |
| 5796 | // TODO: Implement forced rotation changes. |
| 5797 | // Set mAltOrientation to indicate that the application is receiving |
| 5798 | // an orientation that has different metrics than it expected. |
| 5799 | // eg. Portrait instead of Landscape. |
| 5800 | |
| 5801 | int rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, mRotation); |
| 5802 | boolean altOrientation = !mPolicy.rotationHasCompatibleMetricsLw( |
| 5803 | mForcedAppOrientation, rotation); |
| 5804 | |
| 5805 | if (DEBUG_ORIENTATION) { |
| 5806 | Slog.v(TAG, "Application requested orientation " |
| 5807 | + mForcedAppOrientation + ", got rotation " + rotation |
| 5808 | + " which has " + (altOrientation ? "incompatible" : "compatible") |
| 5809 | + " metrics"); |
| 5810 | } |
| 5811 | |
| 5812 | if (mRotation == rotation && mAltOrientation == altOrientation) { |
| 5813 | // No change. |
| 5814 | return false; |
| 5815 | } |
| 5816 | |
| 5817 | if (DEBUG_ORIENTATION) { |
| 5818 | Slog.v(TAG, |
| 5819 | "Rotation changed to " + rotation + (altOrientation ? " (alt)" : "") |
| 5820 | + " from " + mRotation + (mAltOrientation ? " (alt)" : "") |
| 5821 | + ", forceApp=" + mForcedAppOrientation); |
| 5822 | } |
| 5823 | |
| 5824 | mRotation = rotation; |
| 5825 | mAltOrientation = altOrientation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5826 | mPolicy.setRotationLw(mRotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5827 | |
| 5828 | mWindowsFreezingScreen = true; |
| 5829 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 5830 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 5831 | mWaitingForConfig = true; |
| 5832 | mLayoutNeeded = true; |
| 5833 | startFreezingDisplayLocked(inTransaction); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 5834 | mInputManager.setDisplayOrientation(0, rotation, Surface.ROTATION_0); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5835 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 5836 | // We need to update our screen size information to match the new |
| 5837 | // rotation. Note that this is redundant with the later call to |
| 5838 | // sendNewConfiguration() that must be called after this function |
| 5839 | // returns... however we need to do the screen size part of that |
| 5840 | // before then so we have the correct size to use when initializiation |
| 5841 | // the rotation animation for the new rotation. |
| 5842 | computeScreenConfigurationLocked(null); |
| 5843 | |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 5844 | if (!inTransaction) { |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 5845 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 5846 | ">>> OPEN TRANSACTION setRotationUnchecked"); |
| 5847 | Surface.openTransaction(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5848 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5849 | final DisplayContent displayContent = getDefaultDisplayContent(); |
| 5850 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 5851 | try { |
| 5852 | // NOTE: We disable the rotation in the emulator because |
| 5853 | // it doesn't support hardware OpenGL emulation yet. |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 5854 | if (CUSTOM_SCREEN_ROTATION && mAnimator.mScreenRotationAnimation != null |
| 5855 | && mAnimator.mScreenRotationAnimation.hasScreenshot()) { |
| 5856 | if (mAnimator.mScreenRotationAnimation.setRotation(rotation, mFxSession, |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 5857 | MAX_ANIMATION_DURATION, mTransitionAnimationScale, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5858 | displayInfo.logicalWidth, displayInfo.logicalHeight)) { |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 5859 | updateLayoutToAnimationLocked(); |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 5860 | } |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 5861 | } |
| 5862 | Surface.setOrientation(0, rotation); |
| 5863 | } finally { |
| 5864 | if (!inTransaction) { |
| 5865 | Surface.closeTransaction(); |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 5866 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 5867 | "<<< CLOSE TRANSACTION setRotationUnchecked"); |
| 5868 | } |
| 5869 | } |
| 5870 | |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 5871 | rebuildBlackFrame(); |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5872 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5873 | final WindowList windows = displayContent.getWindowList(); |
| 5874 | for (int i = windows.size() - 1; i >= 0; i--) { |
| 5875 | WindowState w = windows.get(i); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 5876 | if (w.mHasSurface) { |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 5877 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Set mOrientationChanging of " + w); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5878 | w.mOrientationChanging = true; |
Craig Mautner | 3255a28 | 2012-04-16 15:42:47 -0700 | [diff] [blame] | 5879 | mInnerFields.mOrientationChangeComplete = false; |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5880 | } |
| 5881 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5882 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 5883 | try { |
| 5884 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 5885 | } catch (RemoteException e) { |
| 5886 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5887 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5888 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5889 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5890 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5891 | public int getRotation() { |
| 5892 | return mRotation; |
| 5893 | } |
| 5894 | |
| 5895 | public int watchRotation(IRotationWatcher watcher) { |
| 5896 | final IBinder watcherBinder = watcher.asBinder(); |
| 5897 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 5898 | public void binderDied() { |
| 5899 | synchronized (mWindowMap) { |
| 5900 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 5901 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5902 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 5903 | if (removed != null) { |
| 5904 | removed.asBinder().unlinkToDeath(this, 0); |
| 5905 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5906 | i--; |
| 5907 | } |
| 5908 | } |
| 5909 | } |
| 5910 | } |
| 5911 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5912 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5913 | synchronized (mWindowMap) { |
| 5914 | try { |
| 5915 | watcher.asBinder().linkToDeath(dr, 0); |
| 5916 | mRotationWatchers.add(watcher); |
| 5917 | } catch (RemoteException e) { |
| 5918 | // Client died, no cleanup needed. |
| 5919 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5920 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5921 | return mRotation; |
| 5922 | } |
| 5923 | } |
| 5924 | |
| 5925 | /** |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 5926 | * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact |
| 5927 | * theme attribute) on devices that feature a physical options menu key attempt to position |
| 5928 | * their menu panel window along the edge of the screen nearest the physical menu key. |
| 5929 | * This lowers the travel distance between invoking the menu panel and selecting |
| 5930 | * a menu option. |
| 5931 | * |
| 5932 | * This method helps control where that menu is placed. Its current implementation makes |
| 5933 | * assumptions about the menu key and its relationship to the screen based on whether |
| 5934 | * the device's natural orientation is portrait (width < height) or landscape. |
| 5935 | * |
| 5936 | * The menu key is assumed to be located along the bottom edge of natural-portrait |
| 5937 | * devices and along the right edge of natural-landscape devices. If these assumptions |
| 5938 | * do not hold for the target device, this method should be changed to reflect that. |
| 5939 | * |
| 5940 | * @return A {@link Gravity} value for placing the options menu window |
| 5941 | */ |
| 5942 | public int getPreferredOptionsPanelGravity() { |
| 5943 | synchronized (mWindowMap) { |
| 5944 | final int rotation = getRotation(); |
| 5945 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5946 | // TODO(multidisplay): Assume that such devices physical keys are on the main screen. |
| 5947 | final DisplayContent displayContent = getDefaultDisplayContent(); |
| 5948 | if (displayContent.mInitialDisplayWidth < displayContent.mInitialDisplayHeight) { |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 5949 | // On devices with a natural orientation of portrait |
| 5950 | switch (rotation) { |
| 5951 | default: |
| 5952 | case Surface.ROTATION_0: |
| 5953 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 5954 | case Surface.ROTATION_90: |
Adam Powell | 67ed6c7 | 2011-08-28 13:21:56 -0700 | [diff] [blame] | 5955 | return Gravity.RIGHT | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 5956 | case Surface.ROTATION_180: |
Adam Powell | 67ed6c7 | 2011-08-28 13:21:56 -0700 | [diff] [blame] | 5957 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 5958 | case Surface.ROTATION_270: |
Fabrice Di Meglio | aac0d4e | 2012-07-19 19:21:26 -0700 | [diff] [blame] | 5959 | return Gravity.START | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 5960 | } |
| 5961 | } else { |
| 5962 | // On devices with a natural orientation of landscape |
| 5963 | switch (rotation) { |
| 5964 | default: |
| 5965 | case Surface.ROTATION_0: |
Adam Powell | 67ed6c7 | 2011-08-28 13:21:56 -0700 | [diff] [blame] | 5966 | return Gravity.RIGHT | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 5967 | case Surface.ROTATION_90: |
| 5968 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 5969 | case Surface.ROTATION_180: |
Fabrice Di Meglio | aac0d4e | 2012-07-19 19:21:26 -0700 | [diff] [blame] | 5970 | return Gravity.START | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 5971 | case Surface.ROTATION_270: |
Adam Powell | 67ed6c7 | 2011-08-28 13:21:56 -0700 | [diff] [blame] | 5972 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 5973 | } |
| 5974 | } |
| 5975 | } |
| 5976 | } |
| 5977 | |
| 5978 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5979 | * Starts the view server on the specified port. |
| 5980 | * |
| 5981 | * @param port The port to listener to. |
| 5982 | * |
| 5983 | * @return True if the server was successfully started, false otherwise. |
| 5984 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 5985 | * @see com.android.server.wm.ViewServer |
| 5986 | * @see com.android.server.wm.ViewServer#VIEW_SERVER_DEFAULT_PORT |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5987 | */ |
| 5988 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5989 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5990 | return false; |
| 5991 | } |
| 5992 | |
| 5993 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 5994 | return false; |
| 5995 | } |
| 5996 | |
| 5997 | if (port < 1024) { |
| 5998 | return false; |
| 5999 | } |
| 6000 | |
| 6001 | if (mViewServer != null) { |
| 6002 | if (!mViewServer.isRunning()) { |
| 6003 | try { |
| 6004 | return mViewServer.start(); |
| 6005 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6006 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6007 | } |
| 6008 | } |
| 6009 | return false; |
| 6010 | } |
| 6011 | |
| 6012 | try { |
| 6013 | mViewServer = new ViewServer(this, port); |
| 6014 | return mViewServer.start(); |
| 6015 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6016 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6017 | } |
| 6018 | return false; |
| 6019 | } |
| 6020 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6021 | private boolean isSystemSecure() { |
| 6022 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 6023 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 6024 | } |
| 6025 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6026 | /** |
| 6027 | * Stops the view server if it exists. |
| 6028 | * |
| 6029 | * @return True if the server stopped, false if it wasn't started or |
| 6030 | * couldn't be stopped. |
| 6031 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 6032 | * @see com.android.server.wm.ViewServer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6033 | */ |
| 6034 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6035 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6036 | return false; |
| 6037 | } |
| 6038 | |
| 6039 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 6040 | return false; |
| 6041 | } |
| 6042 | |
| 6043 | if (mViewServer != null) { |
| 6044 | return mViewServer.stop(); |
| 6045 | } |
| 6046 | return false; |
| 6047 | } |
| 6048 | |
| 6049 | /** |
| 6050 | * Indicates whether the view server is running. |
| 6051 | * |
| 6052 | * @return True if the server is running, false otherwise. |
| 6053 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 6054 | * @see com.android.server.wm.ViewServer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6055 | */ |
| 6056 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6057 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6058 | return false; |
| 6059 | } |
| 6060 | |
| 6061 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 6062 | return false; |
| 6063 | } |
| 6064 | |
| 6065 | return mViewServer != null && mViewServer.isRunning(); |
| 6066 | } |
| 6067 | |
| 6068 | /** |
| 6069 | * Lists all availble windows in the system. The listing is written in the |
| 6070 | * specified Socket's output stream with the following syntax: |
| 6071 | * windowHashCodeInHexadecimal windowName |
| 6072 | * Each line of the ouput represents a different window. |
| 6073 | * |
| 6074 | * @param client The remote client to send the listing to. |
| 6075 | * @return False if an error occured, true otherwise. |
| 6076 | */ |
| 6077 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6078 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6079 | return false; |
| 6080 | } |
| 6081 | |
| 6082 | boolean result = true; |
| 6083 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6084 | WindowList windows = new WindowList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6085 | synchronized (mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6086 | //noinspection unchecked |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6087 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 6088 | while(iterator.hasNext()) { |
| 6089 | windows.addAll(iterator.next().getWindowList()); |
| 6090 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6091 | } |
| 6092 | |
| 6093 | BufferedWriter out = null; |
| 6094 | |
| 6095 | // Any uncaught exception will crash the system process |
| 6096 | try { |
| 6097 | OutputStream clientStream = client.getOutputStream(); |
| 6098 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 6099 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6100 | final int count = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6101 | for (int i = 0; i < count; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6102 | final WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6103 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 6104 | out.write(' '); |
| 6105 | out.append(w.mAttrs.getTitle()); |
| 6106 | out.write('\n'); |
| 6107 | } |
| 6108 | |
| 6109 | out.write("DONE.\n"); |
| 6110 | out.flush(); |
| 6111 | } catch (Exception e) { |
| 6112 | result = false; |
| 6113 | } finally { |
| 6114 | if (out != null) { |
| 6115 | try { |
| 6116 | out.close(); |
| 6117 | } catch (IOException e) { |
| 6118 | result = false; |
| 6119 | } |
| 6120 | } |
| 6121 | } |
| 6122 | |
| 6123 | return result; |
| 6124 | } |
| 6125 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6126 | // TODO(multidisplay): Extend to multiple displays. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6127 | /** |
Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 6128 | * Returns the focused window in the following format: |
| 6129 | * windowHashCodeInHexadecimal windowName |
| 6130 | * |
| 6131 | * @param client The remote client to send the listing to. |
| 6132 | * @return False if an error occurred, true otherwise. |
| 6133 | */ |
| 6134 | boolean viewServerGetFocusedWindow(Socket client) { |
| 6135 | if (isSystemSecure()) { |
| 6136 | return false; |
| 6137 | } |
| 6138 | |
| 6139 | boolean result = true; |
| 6140 | |
| 6141 | WindowState focusedWindow = getFocusedWindow(); |
| 6142 | |
| 6143 | BufferedWriter out = null; |
| 6144 | |
| 6145 | // Any uncaught exception will crash the system process |
| 6146 | try { |
| 6147 | OutputStream clientStream = client.getOutputStream(); |
| 6148 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 6149 | |
| 6150 | if(focusedWindow != null) { |
| 6151 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 6152 | out.write(' '); |
| 6153 | out.append(focusedWindow.mAttrs.getTitle()); |
| 6154 | } |
| 6155 | out.write('\n'); |
| 6156 | out.flush(); |
| 6157 | } catch (Exception e) { |
| 6158 | result = false; |
| 6159 | } finally { |
| 6160 | if (out != null) { |
| 6161 | try { |
| 6162 | out.close(); |
| 6163 | } catch (IOException e) { |
| 6164 | result = false; |
| 6165 | } |
| 6166 | } |
| 6167 | } |
| 6168 | |
| 6169 | return result; |
| 6170 | } |
| 6171 | |
| 6172 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6173 | * Sends a command to a target window. The result of the command, if any, will be |
| 6174 | * written in the output stream of the specified socket. |
| 6175 | * |
| 6176 | * The parameters must follow this syntax: |
| 6177 | * windowHashcode extra |
| 6178 | * |
| 6179 | * Where XX is the length in characeters of the windowTitle. |
| 6180 | * |
| 6181 | * The first parameter is the target window. The window with the specified hashcode |
| 6182 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 6183 | * will be delivered to the target window and as parameters to the command itself. |
| 6184 | * |
| 6185 | * @param client The remote client to sent the result, if any, to. |
| 6186 | * @param command The command to execute. |
| 6187 | * @param parameters The command parameters. |
| 6188 | * |
| 6189 | * @return True if the command was successfully delivered, false otherwise. This does |
| 6190 | * not indicate whether the command itself was successful. |
| 6191 | */ |
| 6192 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6193 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6194 | return false; |
| 6195 | } |
| 6196 | |
| 6197 | boolean success = true; |
| 6198 | Parcel data = null; |
| 6199 | Parcel reply = null; |
| 6200 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 6201 | BufferedWriter out = null; |
| 6202 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6203 | // Any uncaught exception will crash the system process |
| 6204 | try { |
| 6205 | // Find the hashcode of the window |
| 6206 | int index = parameters.indexOf(' '); |
| 6207 | if (index == -1) { |
| 6208 | index = parameters.length(); |
| 6209 | } |
| 6210 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 6211 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6212 | |
| 6213 | // Extract the command's parameter after the window description |
| 6214 | if (index < parameters.length()) { |
| 6215 | parameters = parameters.substring(index + 1); |
| 6216 | } else { |
| 6217 | parameters = ""; |
| 6218 | } |
| 6219 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 6220 | final WindowState window = findWindow(hashCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6221 | if (window == null) { |
| 6222 | return false; |
| 6223 | } |
| 6224 | |
| 6225 | data = Parcel.obtain(); |
| 6226 | data.writeInterfaceToken("android.view.IWindow"); |
| 6227 | data.writeString(command); |
| 6228 | data.writeString(parameters); |
| 6229 | data.writeInt(1); |
| 6230 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 6231 | |
| 6232 | reply = Parcel.obtain(); |
| 6233 | |
| 6234 | final IBinder binder = window.mClient.asBinder(); |
| 6235 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 6236 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 6237 | |
| 6238 | reply.readException(); |
| 6239 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 6240 | if (!client.isOutputShutdown()) { |
| 6241 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 6242 | out.write("DONE\n"); |
| 6243 | out.flush(); |
| 6244 | } |
| 6245 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6246 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6247 | 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] | 6248 | success = false; |
| 6249 | } finally { |
| 6250 | if (data != null) { |
| 6251 | data.recycle(); |
| 6252 | } |
| 6253 | if (reply != null) { |
| 6254 | reply.recycle(); |
| 6255 | } |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 6256 | if (out != null) { |
| 6257 | try { |
| 6258 | out.close(); |
| 6259 | } catch (IOException e) { |
| 6260 | |
| 6261 | } |
| 6262 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6263 | } |
| 6264 | |
| 6265 | return success; |
| 6266 | } |
| 6267 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 6268 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 6269 | synchronized(mWindowMap) { |
| 6270 | mWindowChangeListeners.add(listener); |
| 6271 | } |
| 6272 | } |
| 6273 | |
| 6274 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 6275 | synchronized(mWindowMap) { |
| 6276 | mWindowChangeListeners.remove(listener); |
| 6277 | } |
| 6278 | } |
| 6279 | |
| 6280 | private void notifyWindowsChanged() { |
| 6281 | WindowChangeListener[] windowChangeListeners; |
| 6282 | synchronized(mWindowMap) { |
| 6283 | if(mWindowChangeListeners.isEmpty()) { |
| 6284 | return; |
| 6285 | } |
| 6286 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 6287 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 6288 | } |
| 6289 | int N = windowChangeListeners.length; |
| 6290 | for(int i = 0; i < N; i++) { |
| 6291 | windowChangeListeners[i].windowsChanged(); |
| 6292 | } |
| 6293 | } |
| 6294 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 6295 | private void notifyFocusChanged() { |
| 6296 | WindowChangeListener[] windowChangeListeners; |
| 6297 | synchronized(mWindowMap) { |
| 6298 | if(mWindowChangeListeners.isEmpty()) { |
| 6299 | return; |
| 6300 | } |
| 6301 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 6302 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 6303 | } |
| 6304 | int N = windowChangeListeners.length; |
| 6305 | for(int i = 0; i < N; i++) { |
| 6306 | windowChangeListeners[i].focusChanged(); |
| 6307 | } |
| 6308 | } |
| 6309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6310 | private WindowState findWindow(int hashCode) { |
| 6311 | if (hashCode == -1) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6312 | // TODO(multidisplay): Extend to multiple displays. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6313 | return getFocusedWindow(); |
| 6314 | } |
| 6315 | |
| 6316 | synchronized (mWindowMap) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6317 | final AllWindowsIterator iterator = new AllWindowsIterator(); |
| 6318 | while (iterator.hasNext()) { |
| 6319 | final WindowState w = iterator.next(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6320 | if (System.identityHashCode(w) == hashCode) { |
| 6321 | return w; |
| 6322 | } |
| 6323 | } |
| 6324 | } |
| 6325 | |
| 6326 | return null; |
| 6327 | } |
| 6328 | |
| 6329 | /* |
| 6330 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 6331 | * that to config-changed listeners if appropriate. |
| 6332 | */ |
| 6333 | void sendNewConfiguration() { |
| 6334 | try { |
| 6335 | mActivityManager.updateConfiguration(null); |
| 6336 | } catch (RemoteException e) { |
| 6337 | } |
| 6338 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6340 | public Configuration computeNewConfiguration() { |
| 6341 | synchronized (mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6342 | Configuration config = computeNewConfigurationLocked(); |
| 6343 | if (config == null && mWaitingForConfig) { |
| 6344 | // Nothing changed but we are waiting for something... stop that! |
| 6345 | mWaitingForConfig = false; |
| 6346 | performLayoutAndPlaceSurfacesLocked(); |
| 6347 | } |
| 6348 | return config; |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6349 | } |
| 6350 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6351 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6352 | Configuration computeNewConfigurationLocked() { |
| 6353 | Configuration config = new Configuration(); |
Dianne Hackborn | 09e5b9d | 2011-10-04 16:32:01 -0700 | [diff] [blame] | 6354 | config.fontScale = 0; |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6355 | if (!computeScreenConfigurationLocked(config)) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6356 | return null; |
| 6357 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6358 | return config; |
| 6359 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6360 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6361 | private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation, int dw, int dh) { |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 6362 | final int width = mPolicy.getConfigDisplayWidth(dw, dh, rotation); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6363 | if (width < displayInfo.smallestNominalAppWidth) { |
| 6364 | displayInfo.smallestNominalAppWidth = width; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 6365 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6366 | if (width > displayInfo.largestNominalAppWidth) { |
| 6367 | displayInfo.largestNominalAppWidth = width; |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 6368 | } |
| 6369 | final int height = mPolicy.getConfigDisplayHeight(dw, dh, rotation); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6370 | if (height < displayInfo.smallestNominalAppHeight) { |
| 6371 | displayInfo.smallestNominalAppHeight = height; |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 6372 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6373 | if (height > displayInfo.largestNominalAppHeight) { |
| 6374 | displayInfo.largestNominalAppHeight = height; |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 6375 | } |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 6376 | } |
| 6377 | |
Dianne Hackborn | 56b53b5 | 2011-11-10 11:19:57 -0800 | [diff] [blame] | 6378 | private int reduceConfigLayout(int curLayout, int rotation, float density, |
| 6379 | int dw, int dh) { |
| 6380 | // Get the app screen size at this rotation. |
| 6381 | int w = mPolicy.getNonDecorDisplayWidth(dw, dh, rotation); |
| 6382 | int h = mPolicy.getNonDecorDisplayHeight(dw, dh, rotation); |
| 6383 | |
| 6384 | // Compute the screen layout size class for this rotation. |
| 6385 | int screenLayoutSize; |
| 6386 | boolean screenLayoutLong; |
| 6387 | boolean screenLayoutCompatNeeded; |
| 6388 | int longSize = w; |
| 6389 | int shortSize = h; |
| 6390 | if (longSize < shortSize) { |
| 6391 | int tmp = longSize; |
| 6392 | longSize = shortSize; |
| 6393 | shortSize = tmp; |
| 6394 | } |
| 6395 | longSize = (int)(longSize/density); |
| 6396 | shortSize = (int)(shortSize/density); |
| 6397 | |
| 6398 | // These semi-magic numbers define our compatibility modes for |
| 6399 | // applications with different screens. These are guarantees to |
| 6400 | // app developers about the space they can expect for a particular |
| 6401 | // configuration. DO NOT CHANGE! |
| 6402 | if (longSize < 470) { |
| 6403 | // This is shorter than an HVGA normal density screen (which |
| 6404 | // is 480 pixels on its long side). |
| 6405 | screenLayoutSize = Configuration.SCREENLAYOUT_SIZE_SMALL; |
| 6406 | screenLayoutLong = false; |
| 6407 | screenLayoutCompatNeeded = false; |
| 6408 | } else { |
| 6409 | // What size is this screen screen? |
| 6410 | if (longSize >= 960 && shortSize >= 720) { |
| 6411 | // 1.5xVGA or larger screens at medium density are the point |
| 6412 | // at which we consider it to be an extra large screen. |
| 6413 | screenLayoutSize = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 6414 | } else if (longSize >= 640 && shortSize >= 480) { |
| 6415 | // VGA or larger screens at medium density are the point |
| 6416 | // at which we consider it to be a large screen. |
| 6417 | screenLayoutSize = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 6418 | } else { |
| 6419 | screenLayoutSize = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| 6420 | } |
| 6421 | |
| 6422 | // If this screen is wider than normal HVGA, or taller |
| 6423 | // than FWVGA, then for old apps we want to run in size |
| 6424 | // compatibility mode. |
| 6425 | if (shortSize > 321 || longSize > 570) { |
| 6426 | screenLayoutCompatNeeded = true; |
| 6427 | } else { |
| 6428 | screenLayoutCompatNeeded = false; |
| 6429 | } |
| 6430 | |
| 6431 | // Is this a long screen? |
| 6432 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 6433 | // Anything wider than WVGA (5:3) is considering to be long. |
| 6434 | screenLayoutLong = true; |
| 6435 | } else { |
| 6436 | screenLayoutLong = false; |
| 6437 | } |
| 6438 | } |
| 6439 | |
| 6440 | // Now reduce the last screenLayout to not be better than what we |
| 6441 | // have found. |
| 6442 | if (!screenLayoutLong) { |
| 6443 | curLayout = (curLayout&~Configuration.SCREENLAYOUT_LONG_MASK) |
| 6444 | | Configuration.SCREENLAYOUT_LONG_NO; |
| 6445 | } |
| 6446 | if (screenLayoutCompatNeeded) { |
| 6447 | curLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 6448 | } |
| 6449 | int curSize = curLayout&Configuration.SCREENLAYOUT_SIZE_MASK; |
| 6450 | if (screenLayoutSize < curSize) { |
| 6451 | curLayout = (curLayout&~Configuration.SCREENLAYOUT_SIZE_MASK) |
| 6452 | | screenLayoutSize; |
| 6453 | } |
| 6454 | return curLayout; |
| 6455 | } |
| 6456 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6457 | private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated, |
| 6458 | int dw, int dh, float density, Configuration outConfig) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6459 | // We need to determine the smallest width that will occur under normal |
| 6460 | // operation. To this, start with the base screen size and compute the |
| 6461 | // width under the different possible rotations. We need to un-rotate |
| 6462 | // the current screen dimensions before doing this. |
| 6463 | int unrotDw, unrotDh; |
| 6464 | if (rotated) { |
| 6465 | unrotDw = dh; |
| 6466 | unrotDh = dw; |
| 6467 | } else { |
| 6468 | unrotDw = dw; |
| 6469 | unrotDh = dh; |
| 6470 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6471 | displayInfo.smallestNominalAppWidth = 1<<30; |
| 6472 | displayInfo.smallestNominalAppHeight = 1<<30; |
| 6473 | displayInfo.largestNominalAppWidth = 0; |
| 6474 | displayInfo.largestNominalAppHeight = 0; |
| 6475 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_0, unrotDw, unrotDh); |
| 6476 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_90, unrotDh, unrotDw); |
| 6477 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_180, unrotDw, unrotDh); |
| 6478 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_270, unrotDh, unrotDw); |
Dianne Hackborn | 56b53b5 | 2011-11-10 11:19:57 -0800 | [diff] [blame] | 6479 | int sl = Configuration.SCREENLAYOUT_SIZE_XLARGE |
| 6480 | | Configuration.SCREENLAYOUT_LONG_YES; |
| 6481 | sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh); |
| 6482 | sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw); |
| 6483 | sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh); |
| 6484 | sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6485 | outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density); |
Dianne Hackborn | 56b53b5 | 2011-11-10 11:19:57 -0800 | [diff] [blame] | 6486 | outConfig.screenLayout = sl; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6487 | } |
| 6488 | |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 6489 | private int reduceCompatConfigWidthSize(int curSize, int rotation, DisplayMetrics dm, |
| 6490 | int dw, int dh) { |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 6491 | dm.noncompatWidthPixels = mPolicy.getNonDecorDisplayWidth(dw, dh, rotation); |
| 6492 | dm.noncompatHeightPixels = mPolicy.getNonDecorDisplayHeight(dw, dh, rotation); |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 6493 | float scale = CompatibilityInfo.computeCompatibleScaling(dm, null); |
Dianne Hackborn | 2b31d53 | 2011-06-23 11:58:50 -0700 | [diff] [blame] | 6494 | int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f); |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 6495 | if (curSize == 0 || size < curSize) { |
| 6496 | curSize = size; |
| 6497 | } |
| 6498 | return curSize; |
| 6499 | } |
| 6500 | |
| 6501 | private int computeCompatSmallestWidth(boolean rotated, DisplayMetrics dm, int dw, int dh) { |
| 6502 | mTmpDisplayMetrics.setTo(dm); |
| 6503 | dm = mTmpDisplayMetrics; |
| 6504 | int unrotDw, unrotDh; |
| 6505 | if (rotated) { |
| 6506 | unrotDw = dh; |
| 6507 | unrotDh = dw; |
| 6508 | } else { |
| 6509 | unrotDw = dw; |
| 6510 | unrotDh = dh; |
| 6511 | } |
| 6512 | int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, dm, unrotDw, unrotDh); |
| 6513 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, dm, unrotDh, unrotDw); |
| 6514 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, dm, unrotDw, unrotDh); |
| 6515 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, dm, unrotDh, unrotDw); |
| 6516 | return sw; |
| 6517 | } |
| 6518 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6519 | boolean computeScreenConfigurationLocked(Configuration config) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6520 | if (mDisplay == null) { |
| 6521 | return false; |
| 6522 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 6523 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6524 | // TODO(multidisplay): For now, apply Configuration to main screen only. |
| 6525 | final DisplayContent displayContent = getDefaultDisplayContent(); |
| 6526 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 6527 | // Use the effective "visual" dimensions based on current rotation |
| 6528 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 6529 | || mRotation == Surface.ROTATION_270); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6530 | final int realdw = rotated ? |
| 6531 | displayContent.mBaseDisplayHeight : displayContent.mBaseDisplayWidth; |
| 6532 | final int realdh = rotated ? |
| 6533 | displayContent.mBaseDisplayWidth : displayContent.mBaseDisplayHeight; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6534 | int dw = realdw; |
| 6535 | int dh = realdh; |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6536 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6537 | if (mAltOrientation) { |
| 6538 | if (realdw > realdh) { |
| 6539 | // Turn landscape into portrait. |
| 6540 | int maxw = (int)(realdh/1.3f); |
| 6541 | if (maxw < realdw) { |
| 6542 | dw = maxw; |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6543 | } |
| 6544 | } else { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6545 | // Turn portrait into landscape. |
| 6546 | int maxh = (int)(realdw/1.3f); |
| 6547 | if (maxh < realdh) { |
| 6548 | dh = maxh; |
| 6549 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6550 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6551 | } |
| 6552 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6553 | if (config != null) { |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6554 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 6555 | if (dw < dh) { |
| 6556 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 6557 | } else if (dw > dh) { |
| 6558 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 6559 | } |
| 6560 | config.orientation = orientation; |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6561 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6562 | |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 6563 | // Update application display metrics. |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 6564 | final int appWidth = mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation); |
| 6565 | final int appHeight = mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6566 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 6567 | synchronized(displayContent.mDisplaySizeLock) { |
| 6568 | displayInfo.rotation = mRotation; |
| 6569 | displayInfo.logicalWidth = dw; |
| 6570 | displayInfo.logicalHeight = dh; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 6571 | displayInfo.logicalDensityDpi = displayContent.mBaseDisplayDensity; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6572 | displayInfo.appWidth = appWidth; |
| 6573 | displayInfo.appHeight = appHeight; |
| 6574 | displayInfo.getLogicalMetrics(mRealDisplayMetrics, null); |
| 6575 | displayInfo.getAppMetrics(mDisplayMetrics, null); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 6576 | mDisplayManager.setDisplayInfo(displayContent.getDisplayId(), displayInfo); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6577 | |
| 6578 | mAnimator.setDisplayDimensions(dw, dh, appWidth, appHeight); |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 6579 | } |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 6580 | if (false) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6581 | Slog.i(TAG, "Set app display size: " + appWidth + " x " + appHeight); |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 6582 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6583 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6584 | final DisplayMetrics dm = mDisplayMetrics; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6585 | mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(dm, |
| 6586 | mCompatDisplayMetrics); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6587 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6588 | if (config != null) { |
| 6589 | config.screenWidthDp = (int)(mPolicy.getConfigDisplayWidth(dw, dh, mRotation) |
| 6590 | / dm.density); |
| 6591 | config.screenHeightDp = (int)(mPolicy.getConfigDisplayHeight(dw, dh, mRotation) |
| 6592 | / dm.density); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6593 | computeSizeRangesAndScreenLayout(displayInfo, rotated, dw, dh, dm.density, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6594 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6595 | config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale); |
| 6596 | config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale); |
| 6597 | config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, dm, dw, dh); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 6598 | config.densityDpi = displayContent.mBaseDisplayDensity; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 6599 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6600 | // Update the configuration based on available input devices, lid switch, |
| 6601 | // and platform configuration. |
| 6602 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
| 6603 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
| 6604 | config.navigation = Configuration.NAVIGATION_NONAV; |
| 6605 | |
| 6606 | int keyboardPresence = 0; |
| 6607 | int navigationPresence = 0; |
Craig Mautner | 1d961d4 | 2012-05-27 12:02:11 -0700 | [diff] [blame] | 6608 | final InputDevice[] devices = mInputManager.getInputDevices(); |
| 6609 | final int len = devices.length; |
| 6610 | for (int i = 0; i < len; i++) { |
| 6611 | InputDevice device = devices[i]; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6612 | if (!device.isVirtual()) { |
| 6613 | final int sources = device.getSources(); |
| 6614 | final int presenceFlag = device.isExternal() ? |
| 6615 | WindowManagerPolicy.PRESENCE_EXTERNAL : |
| 6616 | WindowManagerPolicy.PRESENCE_INTERNAL; |
| 6617 | |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 6618 | if (mIsTouchDevice) { |
Jeff Brown | 7e4ff4b | 2012-05-30 14:32:16 -0700 | [diff] [blame] | 6619 | if ((sources & InputDevice.SOURCE_TOUCHSCREEN) == |
| 6620 | InputDevice.SOURCE_TOUCHSCREEN) { |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 6621 | config.touchscreen = Configuration.TOUCHSCREEN_FINGER; |
| 6622 | } |
| 6623 | } else { |
| 6624 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6625 | } |
| 6626 | |
Jeff Brown | 7e4ff4b | 2012-05-30 14:32:16 -0700 | [diff] [blame] | 6627 | if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) { |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6628 | config.navigation = Configuration.NAVIGATION_TRACKBALL; |
| 6629 | navigationPresence |= presenceFlag; |
Jeff Brown | 7e4ff4b | 2012-05-30 14:32:16 -0700 | [diff] [blame] | 6630 | } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6631 | && config.navigation == Configuration.NAVIGATION_NONAV) { |
| 6632 | config.navigation = Configuration.NAVIGATION_DPAD; |
| 6633 | navigationPresence |= presenceFlag; |
| 6634 | } |
| 6635 | |
| 6636 | if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { |
| 6637 | config.keyboard = Configuration.KEYBOARD_QWERTY; |
| 6638 | keyboardPresence |= presenceFlag; |
| 6639 | } |
| 6640 | } |
| 6641 | } |
| 6642 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6643 | // Determine whether a hard keyboard is available and enabled. |
| 6644 | boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; |
| 6645 | if (hardKeyboardAvailable != mHardKeyboardAvailable) { |
| 6646 | mHardKeyboardAvailable = hardKeyboardAvailable; |
| 6647 | mHardKeyboardEnabled = hardKeyboardAvailable; |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6648 | mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 6649 | mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 6650 | } |
| 6651 | if (!mHardKeyboardEnabled) { |
| 6652 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
| 6653 | } |
| 6654 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6655 | // Let the policy update hidden states. |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6656 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 6657 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 6658 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6659 | mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence); |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 6660 | } |
Jeff Brown | 597eec8 | 2011-01-31 17:12:25 -0800 | [diff] [blame] | 6661 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6662 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6663 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6664 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 6665 | public boolean isHardKeyboardAvailable() { |
| 6666 | synchronized (mWindowMap) { |
| 6667 | return mHardKeyboardAvailable; |
| 6668 | } |
| 6669 | } |
| 6670 | |
| 6671 | public boolean isHardKeyboardEnabled() { |
| 6672 | synchronized (mWindowMap) { |
| 6673 | return mHardKeyboardEnabled; |
| 6674 | } |
| 6675 | } |
| 6676 | |
| 6677 | public void setHardKeyboardEnabled(boolean enabled) { |
| 6678 | synchronized (mWindowMap) { |
| 6679 | if (mHardKeyboardEnabled != enabled) { |
| 6680 | mHardKeyboardEnabled = enabled; |
| 6681 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 6682 | } |
| 6683 | } |
| 6684 | } |
| 6685 | |
| 6686 | public void setOnHardKeyboardStatusChangeListener( |
| 6687 | OnHardKeyboardStatusChangeListener listener) { |
| 6688 | synchronized (mWindowMap) { |
| 6689 | mHardKeyboardStatusChangeListener = listener; |
| 6690 | } |
| 6691 | } |
| 6692 | |
| 6693 | void notifyHardKeyboardStatusChange() { |
| 6694 | final boolean available, enabled; |
| 6695 | final OnHardKeyboardStatusChangeListener listener; |
| 6696 | synchronized (mWindowMap) { |
| 6697 | listener = mHardKeyboardStatusChangeListener; |
| 6698 | available = mHardKeyboardAvailable; |
| 6699 | enabled = mHardKeyboardEnabled; |
| 6700 | } |
| 6701 | if (listener != null) { |
| 6702 | listener.onHardKeyboardStatusChange(available, enabled); |
| 6703 | } |
| 6704 | } |
| 6705 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6706 | // ------------------------------------------------------------- |
| 6707 | // Drag and drop |
| 6708 | // ------------------------------------------------------------- |
| 6709 | |
| 6710 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6711 | int flags, int width, int height, Surface outSurface) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6712 | if (DEBUG_DRAG) { |
| 6713 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6714 | + " flags=" + Integer.toHexString(flags) + " win=" + window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6715 | + " asbinder=" + window.asBinder()); |
| 6716 | } |
| 6717 | |
| 6718 | final int callerPid = Binder.getCallingPid(); |
| 6719 | final long origId = Binder.clearCallingIdentity(); |
| 6720 | IBinder token = null; |
| 6721 | |
| 6722 | try { |
| 6723 | synchronized (mWindowMap) { |
| 6724 | try { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6725 | if (mDragState == null) { |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 6726 | Surface surface = new Surface(session, callerPid, "drag surface", |
| 6727 | Display.DEFAULT_DISPLAY, |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6728 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 6729 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DRAG " |
| 6730 | + surface + ": CREATE"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6731 | outSurface.copyFrom(surface); |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 6732 | final IBinder winBinder = window.asBinder(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6733 | token = new Binder(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 6734 | mDragState = new DragState(this, token, surface, /*flags*/ 0, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6735 | token = mDragState.mToken = new Binder(); |
| 6736 | |
| 6737 | // 5 second timeout for this window to actually begin the drag |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 6738 | mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder); |
| 6739 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6740 | mH.sendMessageDelayed(msg, 5000); |
| 6741 | } else { |
| 6742 | Slog.w(TAG, "Drag already in progress"); |
| 6743 | } |
| 6744 | } catch (Surface.OutOfResourcesException e) { |
| 6745 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 6746 | if (mDragState != null) { |
| 6747 | mDragState.reset(); |
| 6748 | mDragState = null; |
| 6749 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6750 | } |
| 6751 | } |
| 6752 | } finally { |
| 6753 | Binder.restoreCallingIdentity(origId); |
| 6754 | } |
| 6755 | |
| 6756 | return token; |
| 6757 | } |
| 6758 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6759 | // ------------------------------------------------------------- |
| 6760 | // Input Events and Focus Management |
| 6761 | // ------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6762 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 6763 | final InputMonitor mInputMonitor = new InputMonitor(this); |
Jeff Brown | 08a746a | 2012-06-24 12:14:49 -0700 | [diff] [blame] | 6764 | private boolean mEventDispatchingEnabled; |
| 6765 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6766 | public void pauseKeyDispatching(IBinder _token) { |
| 6767 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6768 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6769 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6770 | } |
| 6771 | |
| 6772 | synchronized (mWindowMap) { |
| 6773 | WindowToken token = mTokenMap.get(_token); |
| 6774 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6775 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6776 | } |
| 6777 | } |
| 6778 | } |
| 6779 | |
| 6780 | public void resumeKeyDispatching(IBinder _token) { |
| 6781 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6782 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6783 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6784 | } |
| 6785 | |
| 6786 | synchronized (mWindowMap) { |
| 6787 | WindowToken token = mTokenMap.get(_token); |
| 6788 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6789 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6790 | } |
| 6791 | } |
| 6792 | } |
| 6793 | |
| 6794 | public void setEventDispatching(boolean enabled) { |
| 6795 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
Craig Mautner | 3d7b7d5 | 2012-05-24 11:28:26 -0700 | [diff] [blame] | 6796 | "setEventDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6797 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6798 | } |
| 6799 | |
| 6800 | synchronized (mWindowMap) { |
Jeff Brown | 08a746a | 2012-06-24 12:14:49 -0700 | [diff] [blame] | 6801 | mEventDispatchingEnabled = enabled; |
| 6802 | if (mDisplayEnabled) { |
| 6803 | mInputMonitor.setEventDispatchingLw(enabled); |
| 6804 | } |
Craig Mautner | 3d7b7d5 | 2012-05-24 11:28:26 -0700 | [diff] [blame] | 6805 | sendScreenStatusToClientsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6806 | } |
| 6807 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6808 | |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 6809 | public IBinder getFocusedWindowToken() { |
| 6810 | if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO, |
| 6811 | "getFocusedWindowToken()")) { |
| 6812 | throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission."); |
| 6813 | } |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 6814 | synchronized (mWindowMap) { |
| 6815 | WindowState windowState = getFocusedWindowLocked(); |
| 6816 | if (windowState != null) { |
| 6817 | return windowState.mClient.asBinder(); |
| 6818 | } |
| 6819 | return null; |
| 6820 | } |
| 6821 | } |
| 6822 | |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 6823 | public boolean getWindowFrame(IBinder token, Rect outBounds) { |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 6824 | if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO, |
| 6825 | "getWindowFrame()")) { |
| 6826 | throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission."); |
| 6827 | } |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 6828 | synchronized (mWindowMap) { |
| 6829 | WindowState windowState = mWindowMap.get(token); |
| 6830 | if (windowState != null) { |
| 6831 | outBounds.set(windowState.getFrameLw()); |
| 6832 | return true; |
| 6833 | } |
| 6834 | } |
| 6835 | return false; |
| 6836 | } |
| 6837 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6838 | private WindowState getFocusedWindow() { |
| 6839 | synchronized (mWindowMap) { |
| 6840 | return getFocusedWindowLocked(); |
| 6841 | } |
| 6842 | } |
| 6843 | |
| 6844 | private WindowState getFocusedWindowLocked() { |
| 6845 | return mCurrentFocus; |
| 6846 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6847 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6848 | public boolean detectSafeMode() { |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 6849 | if (!mInputMonitor.waitForInputDevicesReady( |
| 6850 | INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) { |
| 6851 | Slog.w(TAG, "Devices still not ready after waiting " |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 6852 | + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS |
| 6853 | + " milliseconds before attempting to detect safe mode."); |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 6854 | } |
| 6855 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 6856 | int menuState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, |
| 6857 | KeyEvent.KEYCODE_MENU); |
| 6858 | int sState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, KeyEvent.KEYCODE_S); |
| 6859 | int dpadState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, |
| 6860 | KeyEvent.KEYCODE_DPAD_CENTER); |
| 6861 | int trackballState = mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6862 | InputManagerService.BTN_MOUSE); |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 6863 | int volumeDownState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, |
| 6864 | KeyEvent.KEYCODE_VOLUME_DOWN); |
| 6865 | mSafeMode = menuState > 0 || sState > 0 || dpadState > 0 || trackballState > 0 |
| 6866 | || volumeDownState > 0; |
Dianne Hackborn | 19caadc | 2012-04-20 17:49:10 -0700 | [diff] [blame] | 6867 | try { |
| 6868 | if (SystemProperties.getInt(ShutdownThread.REBOOT_SAFEMODE_PROPERTY, 0) != 0) { |
| 6869 | mSafeMode = true; |
| 6870 | SystemProperties.set(ShutdownThread.REBOOT_SAFEMODE_PROPERTY, ""); |
| 6871 | } |
| 6872 | } catch (IllegalArgumentException e) { |
| 6873 | } |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 6874 | if (mSafeMode) { |
| 6875 | Log.i(TAG, "SAFE MODE ENABLED (menu=" + menuState + " s=" + sState |
| 6876 | + " dpad=" + dpadState + " trackball=" + trackballState + ")"); |
| 6877 | } else { |
| 6878 | Log.i(TAG, "SAFE MODE not enabled"); |
| 6879 | } |
| 6880 | mPolicy.setSafeMode(mSafeMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6881 | return mSafeMode; |
| 6882 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6883 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6884 | public void displayReady() { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6885 | displayReady(Display.DEFAULT_DISPLAY); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 6886 | |
| 6887 | synchronized(mWindowMap) { |
| 6888 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 6889 | mDisplay = wm.getDefaultDisplay(); |
| 6890 | mIsTouchDevice = mContext.getPackageManager().hasSystemFeature( |
| 6891 | PackageManager.FEATURE_TOUCHSCREEN); |
| 6892 | |
| 6893 | final DisplayInfo displayInfo = getDefaultDisplayInfo(); |
| 6894 | mAnimator.setDisplayDimensions(displayInfo.logicalWidth, displayInfo.logicalHeight, |
| 6895 | displayInfo.appWidth, displayInfo.appHeight); |
| 6896 | |
| 6897 | DisplayDeviceInfo info = new DisplayDeviceInfo(); |
| 6898 | mDisplayManager.getDefaultExternalDisplayDeviceInfo(info); |
| 6899 | |
| 6900 | final DisplayContent displayContent = getDefaultDisplayContent(); |
| 6901 | mInputManager.setDisplaySize(Display.DEFAULT_DISPLAY, |
| 6902 | displayContent.mInitialDisplayWidth, displayContent.mInitialDisplayHeight, |
| 6903 | info.width, info.height); |
| 6904 | mInputManager.setDisplayOrientation(Display.DEFAULT_DISPLAY, |
| 6905 | mDisplay.getRotation(), Surface.ROTATION_0); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 6906 | mPolicy.setInitialDisplaySize(mDisplay, displayContent.mInitialDisplayWidth, |
| 6907 | displayContent.mInitialDisplayHeight, displayContent.mInitialDisplayDensity); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 6908 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6909 | } |
| 6910 | |
| 6911 | public void displayReady(int displayId) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6912 | synchronized(mWindowMap) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6913 | final DisplayContent displayContent = getDisplayContent(displayId); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 6914 | final DisplayInfo displayInfo; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6915 | synchronized(displayContent.mDisplaySizeLock) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6916 | // Bootstrap the default logical display from the display manager. |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 6917 | displayInfo = displayContent.getDisplayInfo(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6918 | mDisplayManager.getDisplayInfo(displayId, displayInfo); |
| 6919 | displayContent.mInitialDisplayWidth = displayInfo.logicalWidth; |
| 6920 | displayContent.mInitialDisplayHeight = displayInfo.logicalHeight; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 6921 | displayContent.mInitialDisplayDensity = displayInfo.logicalDensityDpi; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6922 | displayContent.mBaseDisplayWidth = displayContent.mInitialDisplayWidth; |
| 6923 | displayContent.mBaseDisplayHeight = displayContent.mInitialDisplayHeight; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 6924 | displayContent.mBaseDisplayDensity = displayContent.mInitialDisplayDensity; |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 6925 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6926 | } |
| 6927 | |
| 6928 | try { |
| 6929 | mActivityManager.updateConfiguration(null); |
| 6930 | } catch (RemoteException e) { |
| 6931 | } |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 6932 | |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 6933 | synchronized (mWindowMap) { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 6934 | readForcedDisplaySizeAndDensityLocked(getDisplayContent(displayId)); |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 6935 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6936 | } |
| 6937 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6938 | public void systemReady() { |
| 6939 | mPolicy.systemReady(); |
| 6940 | } |
| 6941 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6942 | // TODO(multidisplay): Call isScreenOn for each display. |
Craig Mautner | 3d7b7d5 | 2012-05-24 11:28:26 -0700 | [diff] [blame] | 6943 | private void sendScreenStatusToClientsLocked() { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6944 | final boolean on = mPowerManager.isScreenOn(); |
| 6945 | final AllWindowsIterator iterator = new AllWindowsIterator(); |
| 6946 | while (iterator.hasNext()) { |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 6947 | try { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6948 | iterator.next().mClient.dispatchScreenState(on); |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 6949 | } catch (RemoteException e) { |
| 6950 | // Ignored |
| 6951 | } |
| 6952 | } |
| 6953 | } |
| 6954 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6955 | // ------------------------------------------------------------- |
| 6956 | // Async Handler |
| 6957 | // ------------------------------------------------------------- |
| 6958 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 6959 | final class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6960 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 6961 | public static final int REPORT_LOSING_FOCUS = 3; |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 6962 | public static final int DO_TRAVERSAL = 4; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6963 | public static final int ADD_STARTING = 5; |
| 6964 | public static final int REMOVE_STARTING = 6; |
| 6965 | public static final int FINISHED_STARTING = 7; |
| 6966 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 6967 | public static final int REPORT_APPLICATION_TOKEN_DRAWN = 9; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6968 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 6969 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 6970 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 6971 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 6972 | public static final int FORCE_GC = 15; |
| 6973 | public static final int ENABLE_SCREEN = 16; |
| 6974 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6975 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 6976 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6977 | public static final int DRAG_START_TIMEOUT = 20; |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6978 | public static final int DRAG_END_TIMEOUT = 21; |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 6979 | public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 6980 | public static final int BOOT_TIMEOUT = 23; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 6981 | public static final int WAITING_FOR_DRAWN_TIMEOUT = 24; |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 6982 | public static final int UPDATE_ANIM_PARAMETERS = 25; |
Craig Mautner | 0447a81 | 2012-05-22 16:01:31 -0700 | [diff] [blame] | 6983 | public static final int SHOW_STRICT_MODE_VIOLATION = 26; |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 6984 | public static final int DO_ANIMATION_CALLBACK = 27; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6985 | |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 6986 | public static final int ANIMATOR_WHAT_OFFSET = 100000; |
| 6987 | public static final int SET_TRANSPARENT_REGION = ANIMATOR_WHAT_OFFSET + 1; |
Craig Mautner | 12670b5 | 2012-07-03 19:15:35 -0700 | [diff] [blame] | 6988 | public static final int CLEAR_PENDING_ACTIONS = ANIMATOR_WHAT_OFFSET + 2; |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 6989 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6990 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6991 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6992 | public H() { |
| 6993 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6994 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6995 | @Override |
| 6996 | public void handleMessage(Message msg) { |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 6997 | if (DEBUG_WINDOW_TRACE) { |
| 6998 | Slog.v(TAG, "handleMessage: entry what=" + msg.what); |
| 6999 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7000 | switch (msg.what) { |
| 7001 | case REPORT_FOCUS_CHANGE: { |
| 7002 | WindowState lastFocus; |
| 7003 | WindowState newFocus; |
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 | synchronized(mWindowMap) { |
| 7006 | lastFocus = mLastFocus; |
| 7007 | newFocus = mCurrentFocus; |
| 7008 | if (lastFocus == newFocus) { |
| 7009 | // Focus is not changing, so nothing to do. |
| 7010 | return; |
| 7011 | } |
| 7012 | mLastFocus = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7013 | //Slog.i(TAG, "Focus moving from " + lastFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7014 | // + " to " + newFocus); |
| 7015 | if (newFocus != null && lastFocus != null |
| 7016 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7017 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7018 | mLosingFocus.add(lastFocus); |
| 7019 | lastFocus = null; |
| 7020 | } |
| 7021 | } |
| 7022 | |
| 7023 | if (lastFocus != newFocus) { |
| 7024 | //System.out.println("Changing focus from " + lastFocus |
| 7025 | // + " to " + newFocus); |
| 7026 | if (newFocus != null) { |
| 7027 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7028 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7029 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 7030 | } catch (RemoteException e) { |
| 7031 | // Ignore if process has died. |
| 7032 | } |
Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 7033 | notifyFocusChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7034 | } |
| 7035 | |
| 7036 | if (lastFocus != null) { |
| 7037 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7038 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7039 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 7040 | } catch (RemoteException e) { |
| 7041 | // Ignore if process has died. |
| 7042 | } |
| 7043 | } |
| 7044 | } |
| 7045 | } break; |
| 7046 | |
| 7047 | case REPORT_LOSING_FOCUS: { |
| 7048 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7049 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7050 | synchronized(mWindowMap) { |
| 7051 | losers = mLosingFocus; |
| 7052 | mLosingFocus = new ArrayList<WindowState>(); |
| 7053 | } |
| 7054 | |
| 7055 | final int N = losers.size(); |
| 7056 | for (int i=0; i<N; i++) { |
| 7057 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7058 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7059 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 7060 | } catch (RemoteException e) { |
| 7061 | // Ignore if process has died. |
| 7062 | } |
| 7063 | } |
| 7064 | } break; |
| 7065 | |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 7066 | case DO_TRAVERSAL: { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7067 | synchronized(mWindowMap) { |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 7068 | mTraversalScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7069 | performLayoutAndPlaceSurfacesLocked(); |
| 7070 | } |
| 7071 | } break; |
| 7072 | |
| 7073 | case ADD_STARTING: { |
| 7074 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7075 | final StartingData sd = wtoken.startingData; |
| 7076 | |
| 7077 | if (sd == null) { |
| 7078 | // Animation has been canceled... do nothing. |
| 7079 | return; |
| 7080 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7081 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7082 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7083 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7084 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7085 | View view = null; |
| 7086 | try { |
| 7087 | view = mPolicy.addStartingWindow( |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 7088 | wtoken.token, sd.pkg, sd.theme, sd.compatInfo, |
| 7089 | sd.nonLocalizedLabel, sd.labelRes, sd.icon, sd.windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7090 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7091 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7092 | } |
| 7093 | |
| 7094 | if (view != null) { |
| 7095 | boolean abort = false; |
| 7096 | |
| 7097 | synchronized(mWindowMap) { |
| 7098 | if (wtoken.removed || wtoken.startingData == null) { |
| 7099 | // If the window was successfully added, then |
| 7100 | // we need to remove it. |
| 7101 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7102 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7103 | "Aborted starting " + wtoken |
| 7104 | + ": removed=" + wtoken.removed |
| 7105 | + " startingData=" + wtoken.startingData); |
| 7106 | wtoken.startingWindow = null; |
| 7107 | wtoken.startingData = null; |
| 7108 | abort = true; |
| 7109 | } |
| 7110 | } else { |
| 7111 | wtoken.startingView = view; |
| 7112 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7113 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7114 | "Added starting " + wtoken |
| 7115 | + ": startingWindow=" |
| 7116 | + wtoken.startingWindow + " startingView=" |
| 7117 | + wtoken.startingView); |
| 7118 | } |
| 7119 | |
| 7120 | if (abort) { |
| 7121 | try { |
| 7122 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 7123 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7124 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7125 | } |
| 7126 | } |
| 7127 | } |
| 7128 | } break; |
| 7129 | |
| 7130 | case REMOVE_STARTING: { |
| 7131 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7132 | IBinder token = null; |
| 7133 | View view = null; |
| 7134 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7135 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7136 | + wtoken + ": startingWindow=" |
| 7137 | + wtoken.startingWindow + " startingView=" |
| 7138 | + wtoken.startingView); |
| 7139 | if (wtoken.startingWindow != null) { |
| 7140 | view = wtoken.startingView; |
| 7141 | token = wtoken.token; |
| 7142 | wtoken.startingData = null; |
| 7143 | wtoken.startingView = null; |
| 7144 | wtoken.startingWindow = null; |
Craig Mautner | 38b2478 | 2012-07-02 16:21:28 -0700 | [diff] [blame] | 7145 | wtoken.startingDisplayed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7146 | } |
| 7147 | } |
| 7148 | if (view != null) { |
| 7149 | try { |
| 7150 | mPolicy.removeStartingWindow(token, view); |
| 7151 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7152 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7153 | } |
| 7154 | } |
| 7155 | } break; |
| 7156 | |
| 7157 | case FINISHED_STARTING: { |
| 7158 | IBinder token = null; |
| 7159 | View view = null; |
| 7160 | while (true) { |
| 7161 | synchronized (mWindowMap) { |
| 7162 | final int N = mFinishedStarting.size(); |
| 7163 | if (N <= 0) { |
| 7164 | break; |
| 7165 | } |
| 7166 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 7167 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7168 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7169 | "Finished starting " + wtoken |
| 7170 | + ": startingWindow=" + wtoken.startingWindow |
| 7171 | + " startingView=" + wtoken.startingView); |
| 7172 | |
| 7173 | if (wtoken.startingWindow == null) { |
| 7174 | continue; |
| 7175 | } |
| 7176 | |
| 7177 | view = wtoken.startingView; |
| 7178 | token = wtoken.token; |
| 7179 | wtoken.startingData = null; |
| 7180 | wtoken.startingView = null; |
| 7181 | wtoken.startingWindow = null; |
Craig Mautner | 38b2478 | 2012-07-02 16:21:28 -0700 | [diff] [blame] | 7182 | wtoken.startingDisplayed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7183 | } |
| 7184 | |
| 7185 | try { |
| 7186 | mPolicy.removeStartingWindow(token, view); |
| 7187 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7188 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7189 | } |
| 7190 | } |
| 7191 | } break; |
| 7192 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 7193 | case REPORT_APPLICATION_TOKEN_DRAWN: { |
| 7194 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7195 | |
| 7196 | try { |
| 7197 | if (DEBUG_VISIBILITY) Slog.v( |
| 7198 | TAG, "Reporting drawn in " + wtoken); |
| 7199 | wtoken.appToken.windowsDrawn(); |
| 7200 | } catch (RemoteException ex) { |
| 7201 | } |
| 7202 | } break; |
| 7203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7204 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 7205 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7206 | |
| 7207 | boolean nowVisible = msg.arg1 != 0; |
| 7208 | boolean nowGone = msg.arg2 != 0; |
| 7209 | |
| 7210 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7211 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7212 | TAG, "Reporting visible in " + wtoken |
| 7213 | + " visible=" + nowVisible |
| 7214 | + " gone=" + nowGone); |
| 7215 | if (nowVisible) { |
| 7216 | wtoken.appToken.windowsVisible(); |
| 7217 | } else { |
| 7218 | wtoken.appToken.windowsGone(); |
| 7219 | } |
| 7220 | } catch (RemoteException ex) { |
| 7221 | } |
| 7222 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7223 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7224 | case WINDOW_FREEZE_TIMEOUT: { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7225 | // TODO(multidisplay): Can non-default displays rotate? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7226 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7227 | Slog.w(TAG, "Window freeze timeout expired."); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7228 | final WindowList windows = getDefaultWindowList(); |
| 7229 | int i = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7230 | while (i > 0) { |
| 7231 | i--; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7232 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7233 | if (w.mOrientationChanging) { |
| 7234 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7235 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7236 | } |
| 7237 | } |
| 7238 | performLayoutAndPlaceSurfacesLocked(); |
| 7239 | } |
| 7240 | break; |
| 7241 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7243 | case HOLD_SCREEN_CHANGED: { |
| 7244 | Session oldHold; |
| 7245 | Session newHold; |
| 7246 | synchronized (mWindowMap) { |
| 7247 | oldHold = mLastReportedHold; |
| 7248 | newHold = (Session)msg.obj; |
| 7249 | mLastReportedHold = newHold; |
| 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 | if (oldHold != newHold) { |
| 7253 | try { |
| 7254 | if (oldHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7255 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7256 | "window", |
| 7257 | BatteryStats.WAKE_TYPE_WINDOW); |
| 7258 | } |
| 7259 | if (newHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7260 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7261 | "window", |
| 7262 | BatteryStats.WAKE_TYPE_WINDOW); |
| 7263 | } |
| 7264 | } catch (RemoteException e) { |
| 7265 | } |
| 7266 | } |
| 7267 | break; |
| 7268 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7270 | case APP_TRANSITION_TIMEOUT: { |
| 7271 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7272 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7273 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7274 | "*** APP TRANSITION TIMEOUT"); |
| 7275 | mAppTransitionReady = true; |
| 7276 | mAppTransitionTimeout = true; |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 7277 | mAnimatingAppTokens.clear(); |
| 7278 | mAnimatingAppTokens.addAll(mAppTokens); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7279 | performLayoutAndPlaceSurfacesLocked(); |
| 7280 | } |
| 7281 | } |
| 7282 | break; |
| 7283 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7285 | case PERSIST_ANIMATION_SCALE: { |
| 7286 | Settings.System.putFloat(mContext.getContentResolver(), |
| 7287 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 7288 | Settings.System.putFloat(mContext.getContentResolver(), |
| 7289 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 7290 | Settings.System.putFloat(mContext.getContentResolver(), |
| 7291 | Settings.System.ANIMATOR_DURATION_SCALE, mAnimatorDurationScale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7292 | break; |
| 7293 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7295 | case FORCE_GC: { |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 7296 | synchronized (mWindowMap) { |
| 7297 | synchronized (mAnimator) { |
| 7298 | // Since we're holding both mWindowMap and mAnimator we don't need to |
| 7299 | // hold mAnimator.mLayoutToAnim. |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 7300 | if (mAnimator.mAnimating || mLayoutToAnim.mAnimationScheduled) { |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 7301 | // If we are animating, don't do the gc now but |
| 7302 | // delay a bit so we don't interrupt the animation. |
| 7303 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 7304 | 2000); |
| 7305 | return; |
| 7306 | } |
| 7307 | // If we are currently rotating the display, it will |
| 7308 | // schedule a new message when done. |
| 7309 | if (mDisplayFrozen) { |
| 7310 | return; |
| 7311 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7312 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7313 | } |
| 7314 | Runtime.getRuntime().gc(); |
| 7315 | break; |
| 7316 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7318 | case ENABLE_SCREEN: { |
| 7319 | performEnableScreen(); |
| 7320 | break; |
| 7321 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7323 | case APP_FREEZE_TIMEOUT: { |
| 7324 | synchronized (mWindowMap) { |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 7325 | synchronized (mAnimator) { |
| 7326 | Slog.w(TAG, "App freeze timeout expired."); |
| 7327 | int i = mAppTokens.size(); |
| 7328 | while (i > 0) { |
| 7329 | i--; |
| 7330 | AppWindowToken tok = mAppTokens.get(i); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 7331 | if (tok.mAppAnimator.freezingScreen) { |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 7332 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| 7333 | unsetAppFreezingScreenLocked(tok, true, true); |
| 7334 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7335 | } |
| 7336 | } |
| 7337 | } |
| 7338 | break; |
| 7339 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7340 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7341 | case SEND_NEW_CONFIGURATION: { |
| 7342 | removeMessages(SEND_NEW_CONFIGURATION); |
| 7343 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 7344 | break; |
| 7345 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7346 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 7347 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 7348 | if (mWindowsChanged) { |
| 7349 | synchronized (mWindowMap) { |
| 7350 | mWindowsChanged = false; |
| 7351 | } |
| 7352 | notifyWindowsChanged(); |
| 7353 | } |
| 7354 | break; |
| 7355 | } |
| 7356 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7357 | case DRAG_START_TIMEOUT: { |
| 7358 | IBinder win = (IBinder)msg.obj; |
| 7359 | if (DEBUG_DRAG) { |
| 7360 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 7361 | } |
| 7362 | synchronized (mWindowMap) { |
| 7363 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 7364 | if (mDragState != null) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 7365 | mDragState.unregister(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 7366 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7367 | mDragState.reset(); |
| 7368 | mDragState = null; |
| 7369 | } |
| 7370 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 7371 | break; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7372 | } |
| 7373 | |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 7374 | case DRAG_END_TIMEOUT: { |
| 7375 | IBinder win = (IBinder)msg.obj; |
| 7376 | if (DEBUG_DRAG) { |
| 7377 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 7378 | } |
| 7379 | synchronized (mWindowMap) { |
| 7380 | // !!! TODO: ANR the drag-receiving app |
Christopher Tate | d9be36c | 2011-08-16 16:09:33 -0700 | [diff] [blame] | 7381 | if (mDragState != null) { |
| 7382 | mDragState.mDragResult = false; |
| 7383 | mDragState.endDragLw(); |
| 7384 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 7385 | } |
| 7386 | break; |
| 7387 | } |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 7388 | |
| 7389 | case REPORT_HARD_KEYBOARD_STATUS_CHANGE: { |
| 7390 | notifyHardKeyboardStatusChange(); |
| 7391 | break; |
| 7392 | } |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 7393 | |
| 7394 | case BOOT_TIMEOUT: { |
| 7395 | performBootTimeout(); |
| 7396 | break; |
| 7397 | } |
| 7398 | |
| 7399 | case WAITING_FOR_DRAWN_TIMEOUT: { |
| 7400 | Pair<WindowState, IRemoteCallback> pair; |
| 7401 | synchronized (mWindowMap) { |
| 7402 | pair = (Pair<WindowState, IRemoteCallback>)msg.obj; |
| 7403 | Slog.w(TAG, "Timeout waiting for drawn: " + pair.first); |
| 7404 | if (!mWaitingForDrawn.remove(pair)) { |
| 7405 | return; |
| 7406 | } |
| 7407 | } |
| 7408 | try { |
| 7409 | pair.second.sendResult(null); |
| 7410 | } catch (RemoteException e) { |
| 7411 | } |
| 7412 | break; |
| 7413 | } |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 7414 | |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 7415 | case UPDATE_ANIM_PARAMETERS: { |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 7416 | // Used to send multiple changes from the animation side to the layout side. |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 7417 | synchronized (mWindowMap) { |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 7418 | if (copyAnimToLayoutParamsLocked()) { |
| 7419 | mH.sendEmptyMessage(CLEAR_PENDING_ACTIONS); |
| 7420 | performLayoutAndPlaceSurfacesLocked(); |
Craig Mautner | 73850cb | 2012-04-10 12:56:27 -0700 | [diff] [blame] | 7421 | } |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 7422 | } |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 7423 | break; |
| 7424 | } |
| 7425 | |
Craig Mautner | 0447a81 | 2012-05-22 16:01:31 -0700 | [diff] [blame] | 7426 | case SHOW_STRICT_MODE_VIOLATION: { |
| 7427 | showStrictModeViolation(msg.arg1); |
| 7428 | break; |
| 7429 | } |
| 7430 | |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 7431 | // Animation messages. Move to Window{State}Animator |
| 7432 | case SET_TRANSPARENT_REGION: { |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 7433 | Pair<WindowStateAnimator, Region> pair = |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 7434 | (Pair<WindowStateAnimator, Region>) msg.obj; |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 7435 | final WindowStateAnimator winAnimator = pair.first; |
| 7436 | winAnimator.setTransparentRegionHint(pair.second); |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 7437 | break; |
| 7438 | } |
| 7439 | |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 7440 | case CLEAR_PENDING_ACTIONS: { |
| 7441 | mAnimator.clearPendingActions(); |
| 7442 | break; |
| 7443 | } |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 7444 | |
| 7445 | case DO_ANIMATION_CALLBACK: { |
| 7446 | try { |
| 7447 | ((IRemoteCallback)msg.obj).sendResult(null); |
| 7448 | } catch (RemoteException e) { |
| 7449 | } |
| 7450 | break; |
| 7451 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7452 | } |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 7453 | if (DEBUG_WINDOW_TRACE) { |
| 7454 | Slog.v(TAG, "handleMessage: exit"); |
| 7455 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7456 | } |
| 7457 | } |
| 7458 | |
| 7459 | // ------------------------------------------------------------- |
| 7460 | // IWindowManager API |
| 7461 | // ------------------------------------------------------------- |
| 7462 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 7463 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7464 | public IWindowSession openSession(IInputMethodClient client, |
| 7465 | IInputContext inputContext) { |
| 7466 | if (client == null) throw new IllegalArgumentException("null client"); |
| 7467 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 7468 | Session session = new Session(this, client, inputContext); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7469 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7470 | } |
| 7471 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 7472 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7473 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 7474 | synchronized (mWindowMap) { |
| 7475 | // The focus for the client is the window immediately below |
| 7476 | // where we would place the input method window. |
| 7477 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7478 | if (idx > 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7479 | // TODO(multidisplay): IMEs are only supported on the default display. |
| 7480 | WindowState imFocus = getDefaultWindowList().get(idx-1); |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 7481 | if (DEBUG_INPUT_METHOD) { |
| 7482 | Slog.i(TAG, "Desired input method target: " + imFocus); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7483 | Slog.i(TAG, "Current focus: " + mCurrentFocus); |
| 7484 | Slog.i(TAG, "Last focus: " + mLastFocus); |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 7485 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7486 | if (imFocus != null) { |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 7487 | // This may be a starting window, in which case we still want |
| 7488 | // to count it as okay. |
| 7489 | if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING |
| 7490 | && imFocus.mAppToken != null) { |
| 7491 | // The client has definitely started, so it really should |
| 7492 | // have a window in this app token. Let's look for it. |
| 7493 | for (int i=0; i<imFocus.mAppToken.windows.size(); i++) { |
| 7494 | WindowState w = imFocus.mAppToken.windows.get(i); |
| 7495 | if (w != imFocus) { |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 7496 | Log.i(TAG, "Switching to real app window: " + w); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 7497 | imFocus = w; |
| 7498 | break; |
| 7499 | } |
| 7500 | } |
| 7501 | } |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 7502 | if (DEBUG_INPUT_METHOD) { |
| 7503 | Slog.i(TAG, "IM target client: " + imFocus.mSession.mClient); |
| 7504 | if (imFocus.mSession.mClient != null) { |
| 7505 | Slog.i(TAG, "IM target client binder: " |
| 7506 | + imFocus.mSession.mClient.asBinder()); |
| 7507 | Slog.i(TAG, "Requesting client binder: " + client.asBinder()); |
| 7508 | } |
| 7509 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7510 | if (imFocus.mSession.mClient != null && |
| 7511 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 7512 | return true; |
| 7513 | } |
| 7514 | } |
| 7515 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7516 | |
| 7517 | // Okay, how about this... what is the current focus? |
| 7518 | // It seems in some cases we may not have moved the IM |
| 7519 | // target window, such as when it was in a pop-up window, |
| 7520 | // so let's also look at the current focus. (An example: |
| 7521 | // go to Gmail, start searching so the keyboard goes up, |
| 7522 | // press home. Sometimes the IME won't go down.) |
| 7523 | // Would be nice to fix this more correctly, but it's |
| 7524 | // way at the end of a release, and this should be good enough. |
| 7525 | if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null |
| 7526 | && mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 7527 | return true; |
| 7528 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7529 | } |
| 7530 | return false; |
| 7531 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7532 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7533 | public void getInitialDisplaySize(int displayId, Point size) { |
| 7534 | // TODO(cmautner): Access to DisplayContent should be locked on mWindowMap. Doing that |
| 7535 | // could lead to deadlock since this is called from ActivityManager. |
| 7536 | final DisplayContent displayContent = getDisplayContent(displayId); |
| 7537 | synchronized(displayContent.mDisplaySizeLock) { |
| 7538 | size.x = displayContent.mInitialDisplayWidth; |
| 7539 | size.y = displayContent.mInitialDisplayHeight; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 7540 | } |
| 7541 | } |
| 7542 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7543 | public void setForcedDisplaySize(int displayId, int longDimen, int shortDimen) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7544 | synchronized(mWindowMap) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7545 | final DisplayContent displayContent = getDisplayContent(displayId); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7546 | int width, height; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7547 | if (displayContent.mInitialDisplayWidth < displayContent.mInitialDisplayHeight) { |
| 7548 | width = shortDimen < displayContent.mInitialDisplayWidth |
| 7549 | ? shortDimen : displayContent.mInitialDisplayWidth; |
| 7550 | height = longDimen < displayContent.mInitialDisplayHeight |
| 7551 | ? longDimen : displayContent.mInitialDisplayHeight; |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7552 | } else { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7553 | width = longDimen < displayContent.mInitialDisplayWidth |
| 7554 | ? longDimen : displayContent.mInitialDisplayWidth; |
| 7555 | height = shortDimen < displayContent.mInitialDisplayHeight |
| 7556 | ? shortDimen : displayContent.mInitialDisplayHeight; |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7557 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7558 | setForcedDisplaySizeLocked(displayContent, width, height); |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 7559 | Settings.Secure.putString(mContext.getContentResolver(), |
| 7560 | Settings.Secure.DISPLAY_SIZE_FORCED, width + "," + height); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7561 | } |
| 7562 | } |
| 7563 | |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 7564 | private void rebuildBlackFrame() { |
| 7565 | if (mBlackFrame != null) { |
| 7566 | mBlackFrame.kill(); |
| 7567 | mBlackFrame = null; |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7568 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7569 | // TODO(multidisplay): For now rotations are only main screen. |
| 7570 | final DisplayContent displayContent = getDefaultDisplayContent(); |
| 7571 | if (displayContent.mBaseDisplayWidth < displayContent.mInitialDisplayWidth |
| 7572 | || displayContent.mBaseDisplayHeight < displayContent.mInitialDisplayHeight) { |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 7573 | int initW, initH, baseW, baseH; |
| 7574 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 7575 | || mRotation == Surface.ROTATION_270); |
| 7576 | if (rotated) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7577 | initW = displayContent.mInitialDisplayHeight; |
| 7578 | initH = displayContent.mInitialDisplayWidth; |
| 7579 | baseW = displayContent.mBaseDisplayHeight; |
| 7580 | baseH = displayContent.mBaseDisplayWidth; |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 7581 | } else { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7582 | initW = displayContent.mInitialDisplayWidth; |
| 7583 | initH = displayContent.mInitialDisplayHeight; |
| 7584 | baseW = displayContent.mBaseDisplayWidth; |
| 7585 | baseH = displayContent.mBaseDisplayHeight; |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7586 | } |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 7587 | Rect outer = new Rect(0, 0, initW, initH); |
| 7588 | Rect inner = new Rect(0, 0, baseW, baseH); |
| 7589 | try { |
| 7590 | mBlackFrame = new BlackFrame(mFxSession, outer, inner, MASK_LAYER); |
| 7591 | } catch (Surface.OutOfResourcesException e) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7592 | } |
| 7593 | } |
| 7594 | } |
| 7595 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7596 | private void readForcedDisplaySizeAndDensityLocked(final DisplayContent displayContent) { |
| 7597 | boolean changed = false; |
| 7598 | final String sizeStr = Settings.Secure.getString(mContext.getContentResolver(), |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 7599 | Settings.Secure.DISPLAY_SIZE_FORCED); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7600 | if (sizeStr != null && sizeStr.length() > 0) { |
| 7601 | final int pos = sizeStr.indexOf(','); |
| 7602 | if (pos > 0 && sizeStr.lastIndexOf(',') == pos) { |
| 7603 | int width, height; |
| 7604 | try { |
| 7605 | width = Integer.parseInt(sizeStr.substring(0, pos)); |
| 7606 | height = Integer.parseInt(sizeStr.substring(pos+1)); |
| 7607 | synchronized(displayContent.mDisplaySizeLock) { |
| 7608 | if (displayContent.mBaseDisplayWidth != width |
| 7609 | || displayContent.mBaseDisplayHeight != height) { |
| 7610 | changed = true; |
| 7611 | Slog.i(TAG, "FORCED DISPLAY SIZE: " + width + "x" + height); |
| 7612 | displayContent.mBaseDisplayWidth = width; |
| 7613 | displayContent.mBaseDisplayHeight = height; |
| 7614 | } |
| 7615 | } |
| 7616 | } catch (NumberFormatException ex) { |
| 7617 | } |
| 7618 | } |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 7619 | } |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7620 | final String densityStr = Settings.Secure.getString(mContext.getContentResolver(), |
| 7621 | Settings.Secure.DISPLAY_DENSITY_FORCED); |
| 7622 | if (densityStr != null && densityStr.length() > 0) { |
| 7623 | int density; |
| 7624 | try { |
| 7625 | density = Integer.parseInt(densityStr); |
| 7626 | synchronized(displayContent.mDisplaySizeLock) { |
| 7627 | if (displayContent.mBaseDisplayDensity != density) { |
| 7628 | changed = true; |
| 7629 | Slog.i(TAG, "FORCED DISPLAY DENSITY: " + density); |
| 7630 | displayContent.mBaseDisplayDensity = density; |
| 7631 | } |
| 7632 | } |
| 7633 | } catch (NumberFormatException ex) { |
| 7634 | } |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 7635 | } |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7636 | if (changed) { |
| 7637 | reconfigureDisplayLocked(displayContent); |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 7638 | } |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 7639 | } |
| 7640 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7641 | private void setForcedDisplaySizeLocked(DisplayContent displayContent, int width, int height) { |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 7642 | Slog.i(TAG, "Using new display size: " + width + "x" + height); |
| 7643 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7644 | synchronized(displayContent.mDisplaySizeLock) { |
| 7645 | displayContent.mBaseDisplayWidth = width; |
| 7646 | displayContent.mBaseDisplayHeight = height; |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 7647 | } |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7648 | reconfigureDisplayLocked(displayContent); |
| 7649 | } |
| 7650 | |
| 7651 | public void clearForcedDisplaySize(int displayId) { |
| 7652 | synchronized(mWindowMap) { |
| 7653 | final DisplayContent displayContent = getDisplayContent(displayId); |
| 7654 | setForcedDisplaySizeLocked(displayContent, displayContent.mInitialDisplayWidth, |
| 7655 | displayContent.mInitialDisplayHeight); |
| 7656 | Settings.Secure.putString(mContext.getContentResolver(), |
| 7657 | Settings.Secure.DISPLAY_SIZE_FORCED, ""); |
| 7658 | } |
| 7659 | } |
| 7660 | |
| 7661 | public void setForcedDisplayDensity(int displayId, int density) { |
| 7662 | synchronized(mWindowMap) { |
| 7663 | final DisplayContent displayContent = getDisplayContent(displayId); |
| 7664 | setForcedDisplayDensityLocked(displayContent, density); |
| 7665 | Settings.Secure.putString(mContext.getContentResolver(), |
| 7666 | Settings.Secure.DISPLAY_SIZE_FORCED, Integer.toString(density)); |
| 7667 | } |
| 7668 | } |
| 7669 | |
| 7670 | private void setForcedDisplayDensityLocked(DisplayContent displayContent, int density) { |
| 7671 | Slog.i(TAG, "Using new display density: " + density); |
| 7672 | |
| 7673 | synchronized(displayContent.mDisplaySizeLock) { |
| 7674 | displayContent.mBaseDisplayDensity = density; |
| 7675 | } |
| 7676 | reconfigureDisplayLocked(displayContent); |
| 7677 | } |
| 7678 | |
| 7679 | public void clearForcedDisplayDensity(int displayId) { |
| 7680 | synchronized(mWindowMap) { |
| 7681 | final DisplayContent displayContent = getDisplayContent(displayId); |
| 7682 | setForcedDisplayDensityLocked(displayContent, displayContent.mInitialDisplayDensity); |
| 7683 | Settings.Secure.putString(mContext.getContentResolver(), |
| 7684 | Settings.Secure.DISPLAY_DENSITY_FORCED, ""); |
| 7685 | } |
| 7686 | } |
| 7687 | |
| 7688 | private void reconfigureDisplayLocked(DisplayContent displayContent) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7689 | mPolicy.setInitialDisplaySize(mDisplay, displayContent.mBaseDisplayWidth, |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7690 | displayContent.mBaseDisplayHeight, displayContent.mBaseDisplayDensity); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7691 | |
| 7692 | mLayoutNeeded = true; |
| 7693 | |
| 7694 | boolean configChanged = updateOrientationFromAppTokensLocked(false); |
| 7695 | mTempConfiguration.setToDefaults(); |
| 7696 | mTempConfiguration.fontScale = mCurConfiguration.fontScale; |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 7697 | if (computeScreenConfigurationLocked(mTempConfiguration)) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7698 | if (mCurConfiguration.diff(mTempConfiguration) != 0) { |
| 7699 | configChanged = true; |
| 7700 | } |
| 7701 | } |
| 7702 | |
| 7703 | if (configChanged) { |
| 7704 | mWaitingForConfig = true; |
| 7705 | startFreezingDisplayLocked(false); |
| 7706 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 7707 | } |
| 7708 | |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 7709 | rebuildBlackFrame(); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7710 | |
| 7711 | performLayoutAndPlaceSurfacesLocked(); |
| 7712 | } |
| 7713 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 7714 | public boolean hasSystemNavBar() { |
| 7715 | return mPolicy.hasSystemNavBar(); |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 7716 | } |
| 7717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7718 | // ------------------------------------------------------------- |
| 7719 | // Internals |
| 7720 | // ------------------------------------------------------------- |
| 7721 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7722 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 7723 | boolean throwOnError) { |
| 7724 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7725 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7726 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7727 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 7728 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7729 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7730 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7731 | TAG, "Looking up client " + client + ": " + win); |
| 7732 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7733 | RuntimeException ex = new IllegalArgumentException( |
| 7734 | "Requested window " + client + " does not exist"); |
| 7735 | if (throwOnError) { |
| 7736 | throw ex; |
| 7737 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7738 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7739 | return null; |
| 7740 | } |
| 7741 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7742 | RuntimeException ex = new IllegalArgumentException( |
| 7743 | "Requested window " + client + " is in session " + |
| 7744 | win.mSession + ", not " + session); |
| 7745 | if (throwOnError) { |
| 7746 | throw ex; |
| 7747 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7748 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7749 | return null; |
| 7750 | } |
| 7751 | |
| 7752 | return win; |
| 7753 | } |
| 7754 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7755 | final void rebuildAppWindowListLocked() { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7756 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 7757 | while (iterator.hasNext()) { |
| 7758 | rebuildAppWindowListLocked(iterator.next()); |
| 7759 | } |
| 7760 | } |
| 7761 | |
| 7762 | private void rebuildAppWindowListLocked(final DisplayContent displayContent) { |
| 7763 | final WindowList windows = displayContent.getWindowList(); |
| 7764 | int NW = windows.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7765 | int i; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 7766 | int lastBelow = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7767 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7768 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7769 | if (mRebuildTmp.length < NW) { |
| 7770 | mRebuildTmp = new WindowState[NW+10]; |
| 7771 | } |
| 7772 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7773 | // First remove all existing app windows. |
| 7774 | i=0; |
| 7775 | while (i < NW) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7776 | WindowState w = windows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7777 | if (w.mAppToken != null) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7778 | WindowState win = windows.remove(i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7779 | win.mRebuilding = true; |
| 7780 | mRebuildTmp[numRemoved] = win; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 7781 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7782 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 7783 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7784 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7785 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7786 | continue; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 7787 | } else if (lastBelow == i-1) { |
| 7788 | if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 7789 | || w.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND) { |
| 7790 | lastBelow = i; |
| 7791 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7792 | } |
| 7793 | i++; |
| 7794 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7795 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 7796 | // Keep whatever windows were below the app windows still below, |
| 7797 | // by skipping them. |
| 7798 | lastBelow++; |
| 7799 | i = lastBelow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7800 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 7801 | // First add all of the exiting app tokens... these are no longer |
| 7802 | // in the main app list, but still have windows shown. We put them |
| 7803 | // in the back because now that the animation is over we no longer |
| 7804 | // will care about them. |
| 7805 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7806 | for (int j=0; j<NT; j++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7807 | i = reAddAppWindowsLocked(displayContent, i, mExitingAppTokens.get(j)); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 7808 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7809 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 7810 | // And add in the still active app tokens in Z order. |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 7811 | NT = mAnimatingAppTokens.size(); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 7812 | for (int j=0; j<NT; j++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7813 | i = reAddAppWindowsLocked(displayContent, i, mAnimatingAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7814 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7815 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 7816 | i -= lastBelow; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7817 | if (i != numRemoved) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7818 | Slog.w(TAG, "Rebuild removed " + numRemoved |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7819 | + " windows but added " + i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7820 | for (i=0; i<numRemoved; i++) { |
| 7821 | WindowState ws = mRebuildTmp[i]; |
| 7822 | if (ws.mRebuilding) { |
| 7823 | StringWriter sw = new StringWriter(); |
| 7824 | PrintWriter pw = new PrintWriter(sw); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 7825 | ws.dump(pw, "", true); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7826 | pw.flush(); |
| 7827 | Slog.w(TAG, "This window was lost: " + ws); |
| 7828 | Slog.w(TAG, sw.toString()); |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 7829 | ws.mWinAnimator.destroySurfaceLocked(); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7830 | } |
| 7831 | } |
| 7832 | Slog.w(TAG, "Current app token list:"); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 7833 | dumpAnimatingAppTokensLocked(); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7834 | Slog.w(TAG, "Final window list:"); |
| 7835 | dumpWindowsLocked(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7836 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7837 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7838 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7839 | private final void assignLayersLocked(WindowList windows) { |
| 7840 | int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7841 | int curBaseLayer = 0; |
| 7842 | int curLayer = 0; |
| 7843 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7844 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 7845 | if (DEBUG_LAYERS) { |
| 7846 | RuntimeException here = new RuntimeException("here"); |
| 7847 | here.fillInStackTrace(); |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 7848 | Slog.v(TAG, "Assigning layers", here); |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 7849 | } |
| 7850 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7851 | for (i=0; i<N; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7852 | final WindowState w = windows.get(i); |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 7853 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 7854 | boolean layerChanged = false; |
| 7855 | int oldLayer = w.mLayer; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7856 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 7857 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7858 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 7859 | w.mLayer = curLayer; |
| 7860 | } else { |
| 7861 | curBaseLayer = curLayer = w.mBaseLayer; |
| 7862 | w.mLayer = curLayer; |
| 7863 | } |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 7864 | if (w.mLayer != oldLayer) { |
| 7865 | layerChanged = true; |
| 7866 | } |
| 7867 | oldLayer = winAnimator.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7868 | if (w.mTargetAppToken != null) { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 7869 | winAnimator.mAnimLayer = |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 7870 | w.mLayer + w.mTargetAppToken.mAppAnimator.animLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7871 | } else if (w.mAppToken != null) { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 7872 | winAnimator.mAnimLayer = |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 7873 | w.mLayer + w.mAppToken.mAppAnimator.animLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7874 | } else { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 7875 | winAnimator.mAnimLayer = w.mLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7876 | } |
| 7877 | if (w.mIsImWindow) { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 7878 | winAnimator.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7879 | } else if (w.mIsWallpaper) { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 7880 | winAnimator.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| 7881 | } |
| 7882 | if (winAnimator.mAnimLayer != oldLayer) { |
| 7883 | layerChanged = true; |
| 7884 | } |
| 7885 | if (layerChanged && mAnimator.isDimming(winAnimator)) { |
| 7886 | // Force an animation pass just to update the mDimAnimator layer. |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 7887 | updateLayoutToAnimationLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7888 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7889 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 7890 | + winAnimator.mAnimLayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7891 | //System.out.println( |
| 7892 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 7893 | } |
| 7894 | } |
| 7895 | |
| 7896 | private boolean mInLayout = false; |
| 7897 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 7898 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 7899 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7900 | throw new RuntimeException("Recursive call!"); |
| 7901 | } |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 7902 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout. Callers=" |
| 7903 | + Debug.getCallers(3)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7904 | return; |
| 7905 | } |
| 7906 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7907 | if (mWaitingForConfig) { |
| 7908 | // Our configuration has changed (most likely rotation), but we |
| 7909 | // don't yet have the complete configuration to report to |
| 7910 | // applications. Don't do any window layout until we have it. |
| 7911 | return; |
| 7912 | } |
| 7913 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7914 | if (mDisplay == null) { |
| 7915 | // Not yet initialized, nothing to do. |
| 7916 | return; |
| 7917 | } |
| 7918 | |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 7919 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmLayout"); |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 7920 | mInLayout = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7921 | boolean recoveringMemory = false; |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 7922 | |
| 7923 | try { |
| 7924 | if (mForceRemoves != null) { |
| 7925 | recoveringMemory = true; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7926 | // 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] | 7927 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 7928 | WindowState ws = mForceRemoves.get(i); |
| 7929 | Slog.i(TAG, "Force removing: " + ws); |
| 7930 | removeWindowInnerLocked(ws.mSession, ws); |
| 7931 | } |
| 7932 | mForceRemoves = null; |
| 7933 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 7934 | Object tmp = new Object(); |
| 7935 | synchronized (tmp) { |
| 7936 | try { |
| 7937 | tmp.wait(250); |
| 7938 | } catch (InterruptedException e) { |
| 7939 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7940 | } |
| 7941 | } |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 7942 | } catch (RuntimeException e) { |
Dianne Hackborn | 8962028 | 2011-09-11 12:47:45 -0700 | [diff] [blame] | 7943 | Log.wtf(TAG, "Unhandled exception while force removing for memory", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7944 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7945 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7946 | try { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7947 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 7948 | while (iterator.hasNext()) { |
| 7949 | final DisplayContent displayContent = iterator.next(); |
| 7950 | performLayoutAndPlaceSurfacesLockedInner(displayContent, recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7951 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7952 | final int N = mPendingRemove.size(); |
| 7953 | if (N > 0) { |
| 7954 | if (mPendingRemoveTmp.length < N) { |
| 7955 | mPendingRemoveTmp = new WindowState[N+10]; |
| 7956 | } |
| 7957 | mPendingRemove.toArray(mPendingRemoveTmp); |
| 7958 | mPendingRemove.clear(); |
| 7959 | for (int i=0; i<N; i++) { |
| 7960 | WindowState w = mPendingRemoveTmp[i]; |
| 7961 | removeWindowInnerLocked(w.mSession, w); |
| 7962 | } |
| 7963 | |
| 7964 | assignLayersLocked(displayContent.getWindowList()); |
| 7965 | mLayoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7966 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7967 | } |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 7968 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7969 | mInLayout = false; |
| 7970 | |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 7971 | if (mLayoutNeeded) { |
| 7972 | if (++mLayoutRepeatCount < 6) { |
| 7973 | requestTraversalLocked(); |
| 7974 | } else { |
| 7975 | Slog.e(TAG, "Performed 6 layouts in a row. Skipping"); |
| 7976 | mLayoutRepeatCount = 0; |
| 7977 | } |
| 7978 | } else { |
| 7979 | mLayoutRepeatCount = 0; |
| 7980 | } |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 7981 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 7982 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 7983 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 7984 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 7985 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7986 | } catch (RuntimeException e) { |
| 7987 | mInLayout = false; |
Dianne Hackborn | 8962028 | 2011-09-11 12:47:45 -0700 | [diff] [blame] | 7988 | Log.wtf(TAG, "Unhandled exception while laying out windows", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7989 | } |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 7990 | |
| 7991 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7992 | } |
| 7993 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7994 | private final void performLayoutLockedInner(final DisplayContent displayContent, |
| 7995 | boolean initial, boolean updateInputWindows) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7996 | if (!mLayoutNeeded) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 7997 | return; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7998 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7999 | WindowList windows = displayContent.getWindowList(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8000 | mLayoutNeeded = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8001 | |
| 8002 | DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 8003 | final int dw = displayInfo.logicalWidth; |
| 8004 | final int dh = displayInfo.logicalHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8005 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 8006 | final int NFW = mFakeWindows.size(); |
| 8007 | for (int i=0; i<NFW; i++) { |
| 8008 | mFakeWindows.get(i).layout(dw, dh); |
| 8009 | } |
| 8010 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8011 | final int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8012 | int i; |
| 8013 | |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8014 | if (DEBUG_LAYOUT) { |
| 8015 | Slog.v(TAG, "-------------------------------------"); |
| 8016 | Slog.v(TAG, "performLayout: needed=" |
| 8017 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 8018 | } |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8019 | |
| 8020 | WindowStateAnimator universeBackground = null; |
| 8021 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 8022 | mPolicy.beginLayoutLw(dw, dh, mRotation); |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 8023 | mSystemDecorLayer = mPolicy.getSystemDecorRectLw(mSystemDecorRect); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8024 | mScreenRect.set(0, 0, dw, dh); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8025 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8026 | int seq = mLayoutSeq+1; |
| 8027 | if (seq < 0) seq = 0; |
| 8028 | mLayoutSeq = seq; |
| 8029 | |
| 8030 | // First perform layout of any root windows (not attached |
| 8031 | // to another window). |
| 8032 | int topAttached = -1; |
| 8033 | for (i = N-1; i >= 0; i--) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8034 | final WindowState win = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8035 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8036 | // Don't do layout of a window if it is not visible, or |
| 8037 | // soon won't be visible, to avoid wasting time and funky |
| 8038 | // changes while a window is animating away. |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8039 | final boolean gone = win.isGoneForLayoutLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8040 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8041 | if (DEBUG_LAYOUT && !win.mLayoutAttached) { |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8042 | Slog.v(TAG, "1ST PASS " + win |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8043 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 8044 | + " mLayoutAttached=" + win.mLayoutAttached); |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8045 | final AppWindowToken atoken = win.mAppToken; |
| 8046 | if (gone) Slog.v(TAG, " GONE: mViewVisibility=" |
| 8047 | + win.mViewVisibility + " mRelayoutCalled=" |
| 8048 | + win.mRelayoutCalled + " hidden=" |
| 8049 | + win.mRootToken.hidden + " hiddenRequested=" |
| 8050 | + (atoken != null && atoken.hiddenRequested) |
| 8051 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 8052 | else Slog.v(TAG, " VIS: mViewVisibility=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8053 | + win.mViewVisibility + " mRelayoutCalled=" |
| 8054 | + win.mRelayoutCalled + " hidden=" |
| 8055 | + win.mRootToken.hidden + " hiddenRequested=" |
| 8056 | + (atoken != null && atoken.hiddenRequested) |
| 8057 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 8058 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8059 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8060 | // If this view is GONE, then skip it -- keep the current |
| 8061 | // frame, and let the caller know so they can ignore it |
| 8062 | // if they want. (We do the normal layout for INVISIBLE |
| 8063 | // windows, since that means "perform layout as normal, |
| 8064 | // just don't display"). |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8065 | if (!gone || !win.mHaveFrame || win.mLayoutNeeded |
| 8066 | || win.mAttrs.type == TYPE_UNIVERSE_BACKGROUND) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8067 | if (!win.mLayoutAttached) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 8068 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 8069 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 8070 | win.mContentChanged = false; |
| 8071 | } |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 8072 | win.mLayoutNeeded = false; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 8073 | win.prelayout(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8074 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 8075 | win.mLayoutSeq = seq; |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8076 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8077 | + win.mFrame + " mContainingFrame=" |
| 8078 | + win.mContainingFrame + " mDisplayFrame=" |
| 8079 | + win.mDisplayFrame); |
| 8080 | } else { |
| 8081 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8082 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8083 | } |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8084 | if (win.mViewVisibility == View.VISIBLE |
| 8085 | && win.mAttrs.type == TYPE_UNIVERSE_BACKGROUND |
| 8086 | && universeBackground == null) { |
| 8087 | universeBackground = win.mWinAnimator; |
| 8088 | } |
| 8089 | } |
| 8090 | |
| 8091 | if (mAnimator.mUniverseBackground != universeBackground) { |
| 8092 | mFocusMayChange = true; |
| 8093 | mAnimator.mUniverseBackground = universeBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8094 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8095 | |
| 8096 | // Now perform layout of attached windows, which usually |
| 8097 | // depend on the position of the window they are attached to. |
| 8098 | // XXX does not deal with windows that are attached to windows |
| 8099 | // that are themselves attached. |
| 8100 | for (i = topAttached; i >= 0; i--) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8101 | final WindowState win = windows.get(i); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8102 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8103 | if (win.mLayoutAttached) { |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8104 | if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + win |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8105 | + " mHaveFrame=" + win.mHaveFrame |
| 8106 | + " mViewVisibility=" + win.mViewVisibility |
| 8107 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8108 | // If this view is GONE, then skip it -- keep the current |
| 8109 | // frame, and let the caller know so they can ignore it |
| 8110 | // if they want. (We do the normal layout for INVISIBLE |
| 8111 | // windows, since that means "perform layout as normal, |
| 8112 | // just don't display"). |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8113 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 8114 | || !win.mHaveFrame || win.mLayoutNeeded) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 8115 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 8116 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 8117 | win.mContentChanged = false; |
| 8118 | } |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 8119 | win.mLayoutNeeded = false; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 8120 | win.prelayout(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8121 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 8122 | win.mLayoutSeq = seq; |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8123 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8124 | + win.mFrame + " mContainingFrame=" |
| 8125 | + win.mContainingFrame + " mDisplayFrame=" |
| 8126 | + win.mDisplayFrame); |
| 8127 | } |
| 8128 | } |
| 8129 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8130 | |
| 8131 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8132 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 8133 | if (updateInputWindows) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 8134 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8135 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8136 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8137 | mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8138 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8139 | |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 8140 | void makeWindowFreezingScreenIfNeededLocked(WindowState w) { |
| 8141 | // If the screen is currently frozen or off, then keep |
| 8142 | // it frozen/off until this window draws at its new |
| 8143 | // orientation. |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 8144 | if (!okToDisplay()) { |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 8145 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| 8146 | "Changing surface while display frozen: " + w); |
| 8147 | w.mOrientationChanging = true; |
Craig Mautner | 3255a28 | 2012-04-16 15:42:47 -0700 | [diff] [blame] | 8148 | mInnerFields.mOrientationChangeComplete = false; |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 8149 | if (!mWindowsFreezingScreen) { |
| 8150 | mWindowsFreezingScreen = true; |
| 8151 | // XXX should probably keep timeout from |
| 8152 | // when we first froze the display. |
| 8153 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 8154 | mH.sendMessageDelayed(mH.obtainMessage( |
| 8155 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 8156 | } |
| 8157 | } |
| 8158 | } |
| 8159 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8160 | /** |
| 8161 | * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8162 | * @param windows TODO(cmautner): |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8163 | * |
| 8164 | * @return bitmap indicating if another pass through layout must be made. |
| 8165 | */ |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8166 | public int handleAppTransitionReadyLocked(WindowList windows) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8167 | int changes = 0; |
| 8168 | int i; |
| 8169 | int NN = mOpeningApps.size(); |
| 8170 | boolean goodToGo = true; |
| 8171 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8172 | "Checking " + NN + " opening apps (frozen=" |
| 8173 | + mDisplayFrozen + " timeout=" |
| 8174 | + mAppTransitionTimeout + ")..."); |
| 8175 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 8176 | // If the display isn't frozen, wait to do anything until |
| 8177 | // all of the apps are ready. Otherwise just go because |
| 8178 | // we'll unfreeze the display when everyone is ready. |
| 8179 | for (i=0; i<NN && goodToGo; i++) { |
| 8180 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 8181 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Craig Mautner | 1d961d4 | 2012-05-27 12:02:11 -0700 | [diff] [blame] | 8182 | "Check opening app=" + wtoken + ": allDrawn=" |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8183 | + wtoken.allDrawn + " startingDisplayed=" |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 8184 | + wtoken.startingDisplayed + " startingMoved=" |
| 8185 | + wtoken.startingMoved); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8186 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 8187 | && !wtoken.startingMoved) { |
| 8188 | goodToGo = false; |
| 8189 | } |
| 8190 | } |
| 8191 | } |
| 8192 | if (goodToGo) { |
| 8193 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO"); |
| 8194 | int transit = mNextAppTransition; |
| 8195 | if (mSkipAppTransitionAnimation) { |
| 8196 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| 8197 | } |
| 8198 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| 8199 | mAppTransitionReady = false; |
| 8200 | mAppTransitionRunning = true; |
| 8201 | mAppTransitionTimeout = false; |
| 8202 | mStartingIconInTransition = false; |
| 8203 | mSkipAppTransitionAnimation = false; |
| 8204 | |
| 8205 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 8206 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8207 | rebuildAppWindowListLocked(); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8208 | |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 8209 | // if wallpaper is animating in or out set oldWallpaper to null else to wallpaper |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 8210 | WindowState oldWallpaper = |
| 8211 | mWallpaperTarget != null && mWallpaperTarget.mWinAnimator.isAnimating() |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 8212 | && !mWallpaperTarget.mWinAnimator.isDummyAnimation() |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 8213 | ? null : mWallpaperTarget; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8214 | |
| 8215 | adjustWallpaperWindowsLocked(); |
| 8216 | mInnerFields.mWallpaperMayChange = false; |
| 8217 | |
| 8218 | // The top-most window will supply the layout params, |
| 8219 | // and we will determine it below. |
| 8220 | LayoutParams animLp = null; |
| 8221 | int bestAnimLayer = -1; |
| 8222 | boolean fullscreenAnim = false; |
| 8223 | |
| 8224 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8225 | "New wallpaper target=" + mWallpaperTarget |
Daniel Sandler | ab886f5 | 2012-06-04 14:36:25 -0400 | [diff] [blame] | 8226 | + ", oldWallpaper=" + oldWallpaper |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8227 | + ", lower target=" + mLowerWallpaperTarget |
| 8228 | + ", upper target=" + mUpperWallpaperTarget); |
| 8229 | int foundWallpapers = 0; |
| 8230 | // Do a first pass through the tokens for two |
| 8231 | // things: |
| 8232 | // (1) Determine if both the closing and opening |
| 8233 | // app token sets are wallpaper targets, in which |
| 8234 | // case special animations are needed |
| 8235 | // (since the wallpaper needs to stay static |
| 8236 | // behind them). |
| 8237 | // (2) Find the layout params of the top-most |
| 8238 | // application window in the tokens, which is |
| 8239 | // what will control the animation theme. |
| 8240 | final int NC = mClosingApps.size(); |
| 8241 | NN = NC + mOpeningApps.size(); |
| 8242 | for (i=0; i<NN; i++) { |
| 8243 | AppWindowToken wtoken; |
| 8244 | int mode; |
| 8245 | if (i < NC) { |
| 8246 | wtoken = mClosingApps.get(i); |
| 8247 | mode = 1; |
| 8248 | } else { |
| 8249 | wtoken = mOpeningApps.get(i-NC); |
| 8250 | mode = 2; |
| 8251 | } |
| 8252 | if (mLowerWallpaperTarget != null) { |
| 8253 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 8254 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 8255 | foundWallpapers |= mode; |
| 8256 | } |
| 8257 | } |
| 8258 | if (wtoken.appFullscreen) { |
| 8259 | WindowState ws = wtoken.findMainWindow(); |
| 8260 | if (ws != null) { |
| 8261 | animLp = ws.mAttrs; |
| 8262 | bestAnimLayer = ws.mLayer; |
| 8263 | fullscreenAnim = true; |
| 8264 | } |
| 8265 | } else if (!fullscreenAnim) { |
| 8266 | WindowState ws = wtoken.findMainWindow(); |
| 8267 | if (ws != null) { |
| 8268 | if (ws.mLayer > bestAnimLayer) { |
| 8269 | animLp = ws.mAttrs; |
| 8270 | bestAnimLayer = ws.mLayer; |
| 8271 | } |
| 8272 | } |
| 8273 | } |
| 8274 | } |
| 8275 | |
| 8276 | if (foundWallpapers == 3) { |
| 8277 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8278 | "Wallpaper animation!"); |
| 8279 | switch (transit) { |
| 8280 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 8281 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 8282 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 8283 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 8284 | break; |
| 8285 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 8286 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 8287 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 8288 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 8289 | break; |
| 8290 | } |
| 8291 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8292 | "New transit: " + transit); |
Daniel Sandler | ab886f5 | 2012-06-04 14:36:25 -0400 | [diff] [blame] | 8293 | } else if ((oldWallpaper != null) && !mOpeningApps.contains(oldWallpaper.mAppToken)) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8294 | // We are transitioning from an activity with |
| 8295 | // a wallpaper to one without. |
| 8296 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| 8297 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8298 | "New transit away from wallpaper: " + transit); |
| 8299 | } else if (mWallpaperTarget != null) { |
| 8300 | // We are transitioning from an activity without |
| 8301 | // a wallpaper to now showing the wallpaper |
| 8302 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| 8303 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8304 | "New transit into wallpaper: " + transit); |
| 8305 | } |
| 8306 | |
| 8307 | // If all closing windows are obscured, then there is |
| 8308 | // no need to do an animation. This is the case, for |
| 8309 | // example, when this transition is being done behind |
| 8310 | // the lock screen. |
| 8311 | if (!mPolicy.allowAppAnimationsLw()) { |
| 8312 | animLp = null; |
| 8313 | } |
| 8314 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8315 | AppWindowToken topOpeningApp = null; |
| 8316 | int topOpeningLayer = 0; |
| 8317 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8318 | NN = mOpeningApps.size(); |
| 8319 | for (i=0; i<NN; i++) { |
| 8320 | AppWindowToken wtoken = mOpeningApps.get(i); |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 8321 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now opening app" + wtoken); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8322 | wtoken.mAppAnimator.clearThumbnail(); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8323 | wtoken.reportedVisible = false; |
| 8324 | wtoken.inPendingTransaction = false; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8325 | wtoken.mAppAnimator.animation = null; |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 8326 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8327 | wtoken.updateReportedVisibilityLocked(); |
| 8328 | wtoken.waitingToShow = false; |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 8329 | mAnimator.mAnimating |= wtoken.mAppAnimator.showAllWindowsLocked(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8330 | if (animLp != null) { |
| 8331 | int layer = -1; |
| 8332 | for (int j=0; j<wtoken.windows.size(); j++) { |
| 8333 | WindowState win = wtoken.windows.get(j); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 8334 | if (win.mWinAnimator.mAnimLayer > layer) { |
| 8335 | layer = win.mWinAnimator.mAnimLayer; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8336 | } |
| 8337 | } |
| 8338 | if (topOpeningApp == null || layer > topOpeningLayer) { |
| 8339 | topOpeningApp = wtoken; |
| 8340 | topOpeningLayer = layer; |
| 8341 | } |
| 8342 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8343 | } |
| 8344 | NN = mClosingApps.size(); |
| 8345 | for (i=0; i<NN; i++) { |
| 8346 | AppWindowToken wtoken = mClosingApps.get(i); |
| 8347 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8348 | "Now closing app" + wtoken); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8349 | wtoken.mAppAnimator.clearThumbnail(); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8350 | wtoken.inPendingTransaction = false; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8351 | wtoken.mAppAnimator.animation = null; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8352 | setTokenVisibilityLocked(wtoken, animLp, false, |
| 8353 | transit, false); |
| 8354 | wtoken.updateReportedVisibilityLocked(); |
| 8355 | wtoken.waitingToHide = false; |
| 8356 | // Force the allDrawn flag, because we want to start |
| 8357 | // this guy's animations regardless of whether it's |
| 8358 | // gotten drawn. |
| 8359 | wtoken.allDrawn = true; |
| 8360 | } |
| 8361 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8362 | if (mNextAppTransitionThumbnail != null && topOpeningApp != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8363 | && topOpeningApp.mAppAnimator.animation != null) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8364 | // This thumbnail animation is very special, we need to have |
| 8365 | // an extra surface with the thumbnail included with the animation. |
| 8366 | Rect dirty = new Rect(0, 0, mNextAppTransitionThumbnail.getWidth(), |
| 8367 | mNextAppTransitionThumbnail.getHeight()); |
| 8368 | try { |
| 8369 | Surface surface = new Surface(mFxSession, Process.myPid(), |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 8370 | "thumbnail anim", Display.DEFAULT_DISPLAY, |
| 8371 | dirty.width(), dirty.height(), |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8372 | PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8373 | topOpeningApp.mAppAnimator.thumbnail = surface; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8374 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " THUMBNAIL " |
| 8375 | + surface + ": CREATE"); |
| 8376 | Surface drawSurface = new Surface(); |
| 8377 | drawSurface.copyFrom(surface); |
| 8378 | Canvas c = drawSurface.lockCanvas(dirty); |
| 8379 | c.drawBitmap(mNextAppTransitionThumbnail, 0, 0, null); |
| 8380 | drawSurface.unlockCanvasAndPost(c); |
| 8381 | drawSurface.release(); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8382 | topOpeningApp.mAppAnimator.thumbnailLayer = topOpeningLayer; |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 8383 | Animation anim = createThumbnailAnimationLocked( |
| 8384 | transit, true, true, mNextAppTransitionDelayed); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8385 | topOpeningApp.mAppAnimator.thumbnailAnimation = anim; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8386 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8387 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8388 | topOpeningApp.mAppAnimator.thumbnailX = mNextAppTransitionStartX; |
| 8389 | topOpeningApp.mAppAnimator.thumbnailY = mNextAppTransitionStartY; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8390 | } catch (Surface.OutOfResourcesException e) { |
| 8391 | Slog.e(TAG, "Can't allocate thumbnail surface w=" + dirty.width() |
| 8392 | + " h=" + dirty.height(), e); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8393 | topOpeningApp.mAppAnimator.clearThumbnail(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8394 | } |
| 8395 | } |
| 8396 | |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 8397 | mNextAppTransitionType = ActivityOptions.ANIM_NONE; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8398 | mNextAppTransitionPackage = null; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8399 | mNextAppTransitionThumbnail = null; |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 8400 | scheduleAnimationCallback(mNextAppTransitionCallback); |
| 8401 | mNextAppTransitionCallback = null; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8402 | |
| 8403 | mOpeningApps.clear(); |
| 8404 | mClosingApps.clear(); |
| 8405 | |
| 8406 | // This has changed the visibility of windows, so perform |
| 8407 | // a new layout to get them all up-to-date. |
| 8408 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT |
| 8409 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
| 8410 | mLayoutNeeded = true; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8411 | |
| 8412 | // TODO(multidisplay): IMEs are only supported on the default display. |
| 8413 | if (windows == getDefaultWindowList() && !moveInputMethodWindowsIfNeededLocked(true)) { |
| 8414 | assignLayersLocked(windows); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8415 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8416 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, false /*updateInputWindows*/); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8417 | mFocusMayChange = false; |
| 8418 | } |
| 8419 | |
| 8420 | return changes; |
| 8421 | } |
| 8422 | |
| 8423 | /** |
| 8424 | * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method. |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8425 | * @return bitmap indicating if another pass through layout must be made. |
| 8426 | */ |
Craig Mautner | 2f995a7 | 2012-02-21 09:53:21 -0800 | [diff] [blame] | 8427 | private int handleAnimatingStoppedAndTransitionLocked() { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8428 | int changes = 0; |
| 8429 | |
| 8430 | mAppTransitionRunning = false; |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8431 | // Restore window app tokens to the ActivityManager views |
Craig Mautner | 3f99fde | 2012-06-19 14:10:01 -0700 | [diff] [blame] | 8432 | for (int i = mAnimatingAppTokens.size() - 1; i >= 0; i--) { |
| 8433 | mAnimatingAppTokens.get(i).sendingToBottom = false; |
| 8434 | } |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8435 | mAnimatingAppTokens.clear(); |
| 8436 | mAnimatingAppTokens.addAll(mAppTokens); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8437 | rebuildAppWindowListLocked(); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8438 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8439 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| 8440 | mInnerFields.mAdjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8441 | moveInputMethodWindowsIfNeededLocked(true); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8442 | mInnerFields.mWallpaperMayChange = true; |
| 8443 | // Since the window list has been rebuilt, focus might |
| 8444 | // have to be recomputed since the actual order of windows |
| 8445 | // might have changed again. |
| 8446 | mFocusMayChange = true; |
| 8447 | |
| 8448 | return changes; |
| 8449 | } |
| 8450 | |
| 8451 | /** |
| 8452 | * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method. |
| 8453 | * |
| 8454 | * @return bitmap indicating if another pass through layout must be made. |
| 8455 | */ |
| 8456 | private int animateAwayWallpaperLocked() { |
| 8457 | int changes = 0; |
| 8458 | WindowState oldWallpaper = mWallpaperTarget; |
| 8459 | if (mLowerWallpaperTarget != null |
| 8460 | && mLowerWallpaperTarget.mAppToken != null) { |
| 8461 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 8462 | "wallpaperForceHiding changed with lower=" |
| 8463 | + mLowerWallpaperTarget); |
| 8464 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 8465 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 8466 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 8467 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 8468 | // The lower target has become hidden before we |
| 8469 | // actually started the animation... let's completely |
| 8470 | // re-evaluate everything. |
| 8471 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| 8472 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| 8473 | } |
| 8474 | } |
| 8475 | mInnerFields.mAdjResult |= adjustWallpaperWindowsLocked(); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8476 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
| 8477 | + " NEW: " + mWallpaperTarget |
| 8478 | + " LOWER: " + mLowerWallpaperTarget); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8479 | return changes; |
| 8480 | } |
| 8481 | |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8482 | private void updateResizingWindows(final WindowState w) { |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 8483 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
Craig Mautner | 1efacf7 | 2012-04-27 12:58:21 -0700 | [diff] [blame] | 8484 | if (w.mHasSurface && !w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8485 | w.mContentInsetsChanged |= |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 8486 | !w.mLastContentInsets.equals(w.mContentInsets); |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8487 | w.mVisibleInsetsChanged |= |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 8488 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8489 | boolean configChanged = |
| 8490 | w.mConfiguration != mCurConfiguration |
| 8491 | && (w.mConfiguration == null |
| 8492 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
| 8493 | if (DEBUG_CONFIGURATION && configChanged) { |
| 8494 | Slog.v(TAG, "Win " + w + " config changed: " |
| 8495 | + mCurConfiguration); |
| 8496 | } |
| 8497 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| 8498 | + ": configChanged=" + configChanged |
| 8499 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| 8500 | w.mLastFrame.set(w.mFrame); |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 8501 | if (w.mContentInsetsChanged |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8502 | || w.mVisibleInsetsChanged |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 8503 | || winAnimator.mSurfaceResized |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8504 | || configChanged) { |
| 8505 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) { |
| 8506 | Slog.v(TAG, "Resize reasons: " |
| 8507 | + " contentInsetsChanged=" + w.mContentInsetsChanged |
| 8508 | + " visibleInsetsChanged=" + w.mVisibleInsetsChanged |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8509 | + " surfaceResized=" + winAnimator.mSurfaceResized |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8510 | + " configChanged=" + configChanged); |
| 8511 | } |
| 8512 | |
| 8513 | w.mLastContentInsets.set(w.mContentInsets); |
| 8514 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| 8515 | makeWindowFreezingScreenIfNeededLocked(w); |
| 8516 | // If the orientation is changing, then we need to |
| 8517 | // hold off on unfreezing the display until this |
| 8518 | // window has been redrawn; to do that, we need |
| 8519 | // to go through the process of getting informed |
| 8520 | // by the application when it has finished drawing. |
| 8521 | if (w.mOrientationChanging) { |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8522 | if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION) Slog.v(TAG, |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 8523 | "Orientation start waiting for draw mDrawState=DRAW_PENDING in " |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8524 | + w + ", surface " + winAnimator.mSurface); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 8525 | winAnimator.mDrawState = WindowStateAnimator.DRAW_PENDING; |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8526 | if (w.mAppToken != null) { |
| 8527 | w.mAppToken.allDrawn = false; |
| 8528 | } |
| 8529 | } |
| 8530 | if (!mResizingWindows.contains(w)) { |
| 8531 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8532 | "Resizing window " + w + " to " + winAnimator.mSurfaceW |
| 8533 | + "x" + winAnimator.mSurfaceH); |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8534 | mResizingWindows.add(w); |
| 8535 | } |
| 8536 | } else if (w.mOrientationChanging) { |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 8537 | if (w.isDrawnLw()) { |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8538 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| 8539 | "Orientation not waiting for draw in " |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8540 | + w + ", surface " + winAnimator.mSurface); |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8541 | w.mOrientationChanging = false; |
| 8542 | } |
| 8543 | } |
| 8544 | } |
| 8545 | } |
| 8546 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8547 | /** |
| 8548 | * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method. |
| 8549 | * |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8550 | * @param w WindowState this method is applied to. |
| 8551 | * @param currentTime The time which animations use for calculating transitions. |
| 8552 | * @param innerDw Width of app window. |
| 8553 | * @param innerDh Height of app window. |
| 8554 | */ |
| 8555 | private void handleNotObscuredLocked(final WindowState w, final long currentTime, |
| 8556 | final int innerDw, final int innerDh) { |
| 8557 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8558 | final int attrFlags = attrs.flags; |
| 8559 | final boolean canBeSeen = w.isDisplayedLw(); |
| 8560 | |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 8561 | if (w.mHasSurface) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8562 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 8563 | mInnerFields.mHoldScreen = w.mSession; |
| 8564 | } |
| 8565 | if (!mInnerFields.mSyswin && w.mAttrs.screenBrightness >= 0 |
| 8566 | && mInnerFields.mScreenBrightness < 0) { |
| 8567 | mInnerFields.mScreenBrightness = w.mAttrs.screenBrightness; |
| 8568 | } |
| 8569 | if (!mInnerFields.mSyswin && w.mAttrs.buttonBrightness >= 0 |
| 8570 | && mInnerFields.mButtonBrightness < 0) { |
| 8571 | mInnerFields.mButtonBrightness = w.mAttrs.buttonBrightness; |
| 8572 | } |
| 8573 | if (canBeSeen |
| 8574 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 8575 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 8576 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
| 8577 | mInnerFields.mSyswin = true; |
| 8578 | } |
| 8579 | } |
| 8580 | |
| 8581 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 8582 | if (opaqueDrawn && w.isFullscreen(innerDw, innerDh)) { |
| 8583 | // This window completely covers everything behind it, |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 8584 | // so we want to leave all of them as undimmed (for |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8585 | // performance reasons). |
| 8586 | mInnerFields.mObscured = true; |
Craig Mautner | 35af2ff | 2012-04-24 14:30:15 -0700 | [diff] [blame] | 8587 | } else if (canBeSeen && (attrFlags & FLAG_DIM_BEHIND) != 0 |
Craig Mautner | 236a35b | 2012-06-08 09:54:59 -0700 | [diff] [blame] | 8588 | && !(w.mAppToken != null && w.mAppToken.hiddenRequested) |
| 8589 | && !w.mExiting) { |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 8590 | if (localLOGV) Slog.v(TAG, "Win " + w + " obscured=" + mInnerFields.mObscured); |
| 8591 | if (!mInnerFields.mDimming) { |
| 8592 | //Slog.i(TAG, "DIM BEHIND: " + w); |
| 8593 | mInnerFields.mDimming = true; |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8594 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 8595 | if (!mAnimator.isDimming(winAnimator)) { |
Craig Mautner | f8d4fbb | 2012-04-11 09:25:53 -0700 | [diff] [blame] | 8596 | final int width, height; |
| 8597 | if (attrs.type == WindowManager.LayoutParams.TYPE_BOOT_PROGRESS) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8598 | final DisplayInfo displayInfo = w.mDisplayContent.getDisplayInfo(); |
| 8599 | width = displayInfo.logicalWidth; |
| 8600 | height = displayInfo.logicalHeight; |
Craig Mautner | f8d4fbb | 2012-04-11 09:25:53 -0700 | [diff] [blame] | 8601 | } else { |
| 8602 | width = innerDw; |
| 8603 | height = innerDh; |
| 8604 | } |
Craig Mautner | a76fdb7 | 2012-07-03 19:03:02 -0700 | [diff] [blame] | 8605 | startDimming(winAnimator, w.mExiting ? 0 : w.mAttrs.dimAmount, width, height); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8606 | } |
| 8607 | } |
| 8608 | } |
| 8609 | } |
| 8610 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 8611 | private void updateAllDrawnLocked() { |
| 8612 | // See if any windows have been drawn, so they (and others |
| 8613 | // associated with them) can now be shown. |
| 8614 | final ArrayList<AppWindowToken> appTokens = mAnimatingAppTokens; |
| 8615 | final int NT = appTokens.size(); |
| 8616 | for (int i=0; i<NT; i++) { |
| 8617 | AppWindowToken wtoken = appTokens.get(i); |
| 8618 | if (!wtoken.allDrawn) { |
| 8619 | int numInteresting = wtoken.numInterestingWindows; |
| 8620 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 8621 | if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, |
| 8622 | "allDrawn: " + wtoken |
| 8623 | + " interesting=" + numInteresting |
| 8624 | + " drawn=" + wtoken.numDrawnWindows); |
| 8625 | wtoken.allDrawn = true; |
| 8626 | } |
| 8627 | } |
| 8628 | } |
| 8629 | } |
| 8630 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 8631 | // "Something has changed! Let's make it correct now." |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8632 | private final void performLayoutAndPlaceSurfacesLockedInner( |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8633 | final DisplayContent displayContent, boolean recoveringMemory) { |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 8634 | if (DEBUG_WINDOW_TRACE) { |
Craig Mautner | 3255a28 | 2012-04-16 15:42:47 -0700 | [diff] [blame] | 8635 | Slog.v(TAG, "performLayoutAndPlaceSurfacesLockedInner: entry. Called by " |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 8636 | + Debug.getCallers(3)); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 8637 | } |
Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 8638 | if (mDisplay == null) { |
| 8639 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 8640 | return; |
| 8641 | } |
| 8642 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8643 | final WindowList windows = displayContent.getWindowList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8644 | final long currentTime = SystemClock.uptimeMillis(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8645 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 8646 | final int dw = displayInfo.logicalWidth; |
| 8647 | final int dh = displayInfo.logicalHeight; |
| 8648 | final int innerDw = displayInfo.appWidth; |
| 8649 | final int innerDh = displayInfo.appHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 8650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8651 | int i; |
| 8652 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8653 | if (mFocusMayChange) { |
| 8654 | mFocusMayChange = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8655 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 8656 | false /*updateInputWindows*/); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8657 | } |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8658 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8659 | // Initialize state of exiting tokens. |
| 8660 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 8661 | mExitingTokens.get(i).hasVisible = false; |
| 8662 | } |
| 8663 | |
| 8664 | // Initialize state of exiting applications. |
| 8665 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 8666 | mExitingAppTokens.get(i).hasVisible = false; |
| 8667 | } |
| 8668 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8669 | mInnerFields.mHoldScreen = null; |
| 8670 | mInnerFields.mScreenBrightness = -1; |
| 8671 | mInnerFields.mButtonBrightness = -1; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 8672 | mTransactionSequence++; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8673 | |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 8674 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 8675 | ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8676 | |
| 8677 | Surface.openTransaction(); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8678 | |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8679 | if (mWatermark != null) { |
| 8680 | mWatermark.positionSurface(dw, dh); |
| 8681 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 8682 | if (mStrictModeFlash != null) { |
| 8683 | mStrictModeFlash.positionSurface(dw, dh); |
| 8684 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8686 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8687 | int repeats = 0; |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8688 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8689 | do { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8690 | repeats++; |
| 8691 | if (repeats > 6) { |
| 8692 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 8693 | mLayoutNeeded = false; |
| 8694 | break; |
| 8695 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8696 | |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 8697 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("On entry to LockedInner", |
| 8698 | mPendingLayoutChanges); |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 8699 | |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8700 | if ((mPendingLayoutChanges & WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8701 | if ((adjustWallpaperWindowsLocked() & ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 8702 | assignLayersLocked(windows); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8703 | mLayoutNeeded = true; |
| 8704 | } |
| 8705 | } |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 8706 | |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8707 | if ((mPendingLayoutChanges & WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8708 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 8709 | if (updateOrientationFromAppTokensLocked(true)) { |
| 8710 | mLayoutNeeded = true; |
| 8711 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 8712 | } |
| 8713 | } |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 8714 | |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8715 | if ((mPendingLayoutChanges & WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8716 | mLayoutNeeded = true; |
| 8717 | } |
| 8718 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8719 | // FIRST LOOP: Perform a layout, if needed. |
| 8720 | if (repeats < 4) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8721 | performLayoutLockedInner(displayContent, repeats == 1, false /*updateInputWindows*/); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8722 | } else { |
| 8723 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8724 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8725 | |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8726 | // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think |
| 8727 | // it is animating. |
| 8728 | mPendingLayoutChanges = 0; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 8729 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("loop number " + mLayoutRepeatCount, |
| 8730 | mPendingLayoutChanges); |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8731 | mPolicy.beginAnimationLw(dw, dh); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8732 | for (i = windows.size() - 1; i >= 0; i--) { |
| 8733 | WindowState w = windows.get(i); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 8734 | if (w.mHasSurface) { |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8735 | mPolicy.animatingWindowLw(w, w.mAttrs); |
| 8736 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8737 | } |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8738 | mPendingLayoutChanges |= mPolicy.finishAnimationLw(); |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 8739 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after finishAnimationLw", |
| 8740 | mPendingLayoutChanges); |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8741 | } while (mPendingLayoutChanges != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8742 | |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 8743 | final boolean someoneLosingFocus = !mLosingFocus.isEmpty(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8744 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8745 | mInnerFields.mObscured = false; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8746 | mInnerFields.mDimming = false; |
| 8747 | mInnerFields.mSyswin = false; |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8748 | |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 8749 | boolean focusDisplayed = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 8750 | boolean updateAllDrawn = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8751 | final int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8752 | for (i=N-1; i>=0; i--) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8753 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8754 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8755 | final boolean obscuredChanged = w.mObscured != mInnerFields.mObscured; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8756 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8757 | // Update effect. |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8758 | w.mObscured = mInnerFields.mObscured; |
| 8759 | if (!mInnerFields.mObscured) { |
| 8760 | handleNotObscuredLocked(w, currentTime, innerDw, innerDh); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8761 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8762 | |
Craig Mautner | ad5725d | 2012-06-05 10:20:56 -0700 | [diff] [blame] | 8763 | if (obscuredChanged && (mWallpaperTarget == w) && w.isVisibleLw()) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 8764 | // This is the wallpaper target and its obscured state |
| 8765 | // changed... make sure the current wallaper's visibility |
| 8766 | // has been updated accordingly. |
| 8767 | updateWallpaperVisibilityLocked(); |
| 8768 | } |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8769 | |
| 8770 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 8771 | |
| 8772 | // If the window has moved due to its containing |
| 8773 | // content frame changing, then we'd like to animate |
| 8774 | // it. |
| 8775 | if (w.mHasSurface && w.shouldAnimateMove()) { |
| 8776 | // Frame has moved, containing content frame |
| 8777 | // has also moved, and we're not currently animating... |
| 8778 | // let's do something. |
| 8779 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 8780 | com.android.internal.R.anim.window_move_from_decor); |
| 8781 | winAnimator.setAnimation(a); |
| 8782 | winAnimator.mAnimDw = w.mLastFrame.left - w.mFrame.left; |
| 8783 | winAnimator.mAnimDh = w.mLastFrame.top - w.mFrame.top; |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 8784 | try { |
| 8785 | w.mClient.moved(w.mFrame.left, w.mFrame.top); |
| 8786 | } catch (RemoteException e) { |
| 8787 | } |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8788 | } |
| 8789 | |
| 8790 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
| 8791 | w.mContentChanged = false; |
| 8792 | |
| 8793 | // Moved from updateWindowsAndWallpaperLocked(). |
| 8794 | if (w.mHasSurface) { |
| 8795 | // Take care of the window being ready to display. |
| 8796 | if (winAnimator.commitFinishDrawingLocked(currentTime)) { |
| 8797 | if ((w.mAttrs.flags |
| 8798 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 8799 | if (WindowManagerService.DEBUG_WALLPAPER) Slog.v(TAG, |
| 8800 | "First draw done in potential wallpaper target " + w); |
| 8801 | mInnerFields.mWallpaperMayChange = true; |
| 8802 | mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
| 8803 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 8804 | debugLayoutRepeats("wallpaper and commitFinishDrawingLocked true", |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8805 | mPendingLayoutChanges); |
| 8806 | } |
| 8807 | } |
| 8808 | } |
| 8809 | |
| 8810 | winAnimator.setSurfaceBoundaries(recoveringMemory); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 8811 | |
| 8812 | final AppWindowToken atoken = w.mAppToken; |
| 8813 | if (DEBUG_STARTING_WINDOW && atoken != null && w == atoken.startingWindow) { |
| 8814 | Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" |
| 8815 | + w.isOnScreen() + " allDrawn=" + atoken.allDrawn |
| 8816 | + " freezingScreen=" + atoken.mAppAnimator.freezingScreen); |
| 8817 | } |
| 8818 | if (atoken != null |
| 8819 | && (!atoken.allDrawn || atoken.mAppAnimator.freezingScreen)) { |
| 8820 | if (atoken.lastTransactionSequence != mTransactionSequence) { |
| 8821 | atoken.lastTransactionSequence = mTransactionSequence; |
| 8822 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 8823 | atoken.startingDisplayed = false; |
| 8824 | } |
| 8825 | if ((w.isOnScreen() || winAnimator.mAttrType |
| 8826 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 8827 | && !w.mExiting && !w.mDestroying) { |
| 8828 | if (WindowManagerService.DEBUG_VISIBILITY || |
| 8829 | WindowManagerService.DEBUG_ORIENTATION) { |
| 8830 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw() |
| 8831 | + ", isAnimating=" + winAnimator.isAnimating()); |
| 8832 | if (!w.isDrawnLw()) { |
| 8833 | Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurface |
| 8834 | + " pv=" + w.mPolicyVisibility |
| 8835 | + " mDrawState=" + winAnimator.mDrawState |
| 8836 | + " ah=" + w.mAttachedHidden |
| 8837 | + " th=" + atoken.hiddenRequested |
| 8838 | + " a=" + winAnimator.mAnimating); |
| 8839 | } |
| 8840 | } |
| 8841 | if (w != atoken.startingWindow) { |
| 8842 | if (!atoken.mAppAnimator.freezingScreen || !w.mAppFreezing) { |
| 8843 | atoken.numInterestingWindows++; |
| 8844 | if (w.isDrawnLw()) { |
| 8845 | atoken.numDrawnWindows++; |
| 8846 | if (WindowManagerService.DEBUG_VISIBILITY || |
| 8847 | WindowManagerService.DEBUG_ORIENTATION) Slog.v(TAG, |
| 8848 | "tokenMayBeDrawn: " + atoken |
| 8849 | + " freezingScreen=" + atoken.mAppAnimator.freezingScreen |
| 8850 | + " mAppFreezing=" + w.mAppFreezing); |
| 8851 | updateAllDrawn = true; |
| 8852 | } |
| 8853 | } |
| 8854 | } else if (w.isDrawnLw()) { |
| 8855 | atoken.startingDisplayed = true; |
| 8856 | } |
| 8857 | } |
| 8858 | } |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8859 | } |
| 8860 | |
Craig Mautner | 51bb12b | 2012-04-27 14:39:53 -0700 | [diff] [blame] | 8861 | if (someoneLosingFocus && w == mCurrentFocus && w.isDisplayedLw()) { |
| 8862 | focusDisplayed = true; |
| 8863 | } |
| 8864 | |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8865 | updateResizingWindows(w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8866 | } |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8867 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 8868 | if (updateAllDrawn) { |
| 8869 | updateAllDrawnLocked(); |
| 8870 | } |
| 8871 | |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 8872 | if (focusDisplayed) { |
| 8873 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 8874 | } |
| 8875 | |
Craig Mautner | f8d4fbb | 2012-04-11 09:25:53 -0700 | [diff] [blame] | 8876 | if (!mInnerFields.mDimming && mAnimator.isDimming()) { |
Craig Mautner | a76fdb7 | 2012-07-03 19:03:02 -0700 | [diff] [blame] | 8877 | stopDimming(); |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 8878 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8879 | } catch (RuntimeException e) { |
Dianne Hackborn | 8962028 | 2011-09-11 12:47:45 -0700 | [diff] [blame] | 8880 | Log.wtf(TAG, "Unhandled exception in Window Manager", e); |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 8881 | } finally { |
| 8882 | Surface.closeTransaction(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8883 | } |
| 8884 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 8885 | // If we are ready to perform an app transition, check through |
| 8886 | // all of the app tokens to be shown and see if they are ready |
| 8887 | // to go. |
| 8888 | if (mAppTransitionReady) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8889 | mPendingLayoutChanges |= handleAppTransitionReadyLocked(windows); |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 8890 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after handleAppTransitionReadyLocked", |
| 8891 | mPendingLayoutChanges); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 8892 | } |
| 8893 | |
| 8894 | mInnerFields.mAdjResult = 0; |
| 8895 | |
| 8896 | if (!mAnimator.mAnimating && mAppTransitionRunning) { |
| 8897 | // We have finished the animation of an app transition. To do |
| 8898 | // this, we have delayed a lot of operations like showing and |
| 8899 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 8900 | // reflects the correct Z-order, but the window list may now |
| 8901 | // be out of sync with it. So here we will just rebuild the |
| 8902 | // entire app window list. Fun! |
| 8903 | mPendingLayoutChanges |= handleAnimatingStoppedAndTransitionLocked(); |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 8904 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after handleAnimStopAndXitionLock", |
| 8905 | mPendingLayoutChanges); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 8906 | } |
| 8907 | |
| 8908 | if (mInnerFields.mWallpaperForceHidingChanged && mPendingLayoutChanges == 0 && |
| 8909 | !mAppTransitionReady) { |
| 8910 | // At this point, there was a window with a wallpaper that |
| 8911 | // was force hiding other windows behind it, but now it |
| 8912 | // is going away. This may be simple -- just animate |
| 8913 | // away the wallpaper and its window -- or it may be |
| 8914 | // hard -- the wallpaper now needs to be shown behind |
| 8915 | // something that was hidden. |
| 8916 | mPendingLayoutChanges |= animateAwayWallpaperLocked(); |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 8917 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after animateAwayWallpaperLocked", |
| 8918 | mPendingLayoutChanges); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 8919 | } |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 8920 | mInnerFields.mWallpaperForceHidingChanged = false; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 8921 | |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 8922 | if (mInnerFields.mWallpaperMayChange) { |
| 8923 | if (WindowManagerService.DEBUG_WALLPAPER) Slog.v(TAG, |
| 8924 | "Wallpaper may change! Adjusting"); |
| 8925 | mInnerFields.mAdjResult |= adjustWallpaperWindowsLocked(); |
| 8926 | } |
| 8927 | |
| 8928 | if ((mInnerFields.mAdjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 8929 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 8930 | "Wallpaper layer changed: assigning layers + relayout"); |
| 8931 | mPendingLayoutChanges |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8932 | assignLayersLocked(windows); |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 8933 | } else if ((mInnerFields.mAdjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| 8934 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 8935 | "Wallpaper visibility changed: relayout"); |
| 8936 | mPendingLayoutChanges |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| 8937 | } |
| 8938 | |
| 8939 | if (mFocusMayChange) { |
| 8940 | mFocusMayChange = false; |
| 8941 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 8942 | false /*updateInputWindows*/)) { |
| 8943 | mPendingLayoutChanges |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| 8944 | mInnerFields.mAdjResult = 0; |
| 8945 | } |
| 8946 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 8947 | |
| 8948 | if (mLayoutNeeded) { |
| 8949 | mPendingLayoutChanges |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 8950 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("mLayoutNeeded", mPendingLayoutChanges); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 8951 | } |
| 8952 | |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 8953 | if (!mResizingWindows.isEmpty()) { |
| 8954 | for (i = mResizingWindows.size() - 1; i >= 0; i--) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8955 | WindowState win = mResizingWindows.get(i); |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8956 | final WindowStateAnimator winAnimator = win.mWinAnimator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8957 | try { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 8958 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 8959 | "Reporting new frame to " + win + ": " + win.mCompatFrame); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 8960 | int diff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8961 | boolean configChanged = |
| 8962 | win.mConfiguration != mCurConfiguration |
| 8963 | && (win.mConfiguration == null |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 8964 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 8965 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 8966 | && configChanged) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8967 | Slog.i(TAG, "Sending new config to window " + win + ": " |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 8968 | + winAnimator.mSurfaceW + "x" + winAnimator.mSurfaceH |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 8969 | + " / " + mCurConfiguration + " / 0x" |
| 8970 | + Integer.toHexString(diff)); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8971 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 8972 | win.mConfiguration = mCurConfiguration; |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 8973 | if (DEBUG_ORIENTATION && |
| 8974 | winAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING) Slog.i( |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8975 | TAG, "Resizing " + win + " WITH DRAW PENDING"); |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 8976 | win.mClient.resized(win.mFrame, win.mLastContentInsets, win.mLastVisibleInsets, |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 8977 | winAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING, |
| 8978 | configChanged ? win.mConfiguration : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8979 | win.mContentInsetsChanged = false; |
| 8980 | win.mVisibleInsetsChanged = false; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 8981 | winAnimator.mSurfaceResized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8982 | } catch (RemoteException e) { |
| 8983 | win.mOrientationChanging = false; |
| 8984 | } |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 8985 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8986 | mResizingWindows.clear(); |
| 8987 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8988 | |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8989 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| 8990 | "With display frozen, orientationChangeComplete=" |
| 8991 | + mInnerFields.mOrientationChangeComplete); |
| 8992 | if (mInnerFields.mOrientationChangeComplete) { |
| 8993 | if (mWindowsFreezingScreen) { |
| 8994 | mWindowsFreezingScreen = false; |
| 8995 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 8996 | } |
| 8997 | stopFreezingDisplayLocked(); |
| 8998 | } |
| 8999 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9000 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9001 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9002 | i = mDestroySurface.size(); |
| 9003 | if (i > 0) { |
| 9004 | do { |
| 9005 | i--; |
| 9006 | WindowState win = mDestroySurface.get(i); |
| 9007 | win.mDestroying = false; |
| 9008 | if (mInputMethodWindow == win) { |
| 9009 | mInputMethodWindow = null; |
| 9010 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9011 | if (win == mWallpaperTarget) { |
| 9012 | wallpaperDestroyed = true; |
| 9013 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9014 | win.mWinAnimator.destroySurfaceLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9015 | } while (i > 0); |
| 9016 | mDestroySurface.clear(); |
| 9017 | } |
| 9018 | |
| 9019 | // Time to remove any exiting tokens? |
| 9020 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9021 | WindowToken token = mExitingTokens.get(i); |
| 9022 | if (!token.hasVisible) { |
| 9023 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 9024 | if (token.windowType == TYPE_WALLPAPER) { |
| 9025 | mWallpaperTokens.remove(token); |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 9026 | updateLayoutToAnimWallpaperTokens(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 9027 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9028 | } |
| 9029 | } |
| 9030 | |
| 9031 | // Time to remove any exiting applications? |
| 9032 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9033 | AppWindowToken token = mExitingAppTokens.get(i); |
| 9034 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9035 | // Make sure there is no animation running on this token, |
| 9036 | // so any windows associated with it will be removed as |
| 9037 | // soon as their animations are complete |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 9038 | token.mAppAnimator.clearAnimation(); |
| 9039 | token.mAppAnimator.animating = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9040 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 9041 | "performLayout: App token exiting now removed" + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9042 | mAppTokens.remove(token); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 9043 | mAnimatingAppTokens.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9044 | mExitingAppTokens.remove(i); |
| 9045 | } |
| 9046 | } |
| 9047 | |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 9048 | if (!mAnimator.mAnimating && mRelayoutWhileAnimating.size() > 0) { |
| 9049 | for (int j=mRelayoutWhileAnimating.size()-1; j>=0; j--) { |
| 9050 | try { |
| 9051 | mRelayoutWhileAnimating.get(j).mClient.doneAnimating(); |
| 9052 | } catch (RemoteException e) { |
| 9053 | } |
| 9054 | } |
| 9055 | mRelayoutWhileAnimating.clear(); |
| 9056 | } |
| 9057 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9058 | if (wallpaperDestroyed) { |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 9059 | mLayoutNeeded |= adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9060 | } |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 9061 | if (mPendingLayoutChanges != 0) { |
| 9062 | mLayoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9063 | } |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 9064 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9065 | // Finally update all input windows now that the window changes have stabilized. |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 9066 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 9067 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 9068 | setHoldScreenLocked(mInnerFields.mHoldScreen != null); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 9069 | if (!mDisplayFrozen) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 9070 | if (mInnerFields.mScreenBrightness < 0 || mInnerFields.mScreenBrightness > 1.0f) { |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 9071 | mPowerManager.setScreenBrightnessOverride(-1); |
| 9072 | } else { |
| 9073 | mPowerManager.setScreenBrightnessOverride((int) |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 9074 | (mInnerFields.mScreenBrightness * PowerManager.BRIGHTNESS_ON)); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 9075 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 9076 | if (mInnerFields.mButtonBrightness < 0 || mInnerFields.mButtonBrightness > 1.0f) { |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 9077 | mPowerManager.setButtonBrightnessOverride(-1); |
| 9078 | } else { |
| 9079 | mPowerManager.setButtonBrightnessOverride((int) |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 9080 | (mInnerFields.mButtonBrightness * PowerManager.BRIGHTNESS_ON)); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 9081 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9082 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 9083 | if (mInnerFields.mHoldScreen != mHoldingScreenOn) { |
| 9084 | mHoldingScreenOn = mInnerFields.mHoldScreen; |
| 9085 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, mInnerFields.mHoldScreen); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9086 | mH.sendMessage(m); |
| 9087 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9088 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9089 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9090 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9091 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
Jeff Brown | b696de5 | 2012-07-27 15:38:50 -0700 | [diff] [blame] | 9092 | PowerManager.USER_ACTIVITY_EVENT_BUTTON, true); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9093 | mTurnOnScreen = false; |
| 9094 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 9095 | |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 9096 | if (mInnerFields.mUpdateRotation) { |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9097 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 9098 | if (updateRotationUncheckedLocked(false)) { |
Dianne Hackborn | 3e4f9d0 | 2011-02-04 14:05:55 -0800 | [diff] [blame] | 9099 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 9100 | } else { |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 9101 | mInnerFields.mUpdateRotation = false; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9102 | } |
| 9103 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 9104 | |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 9105 | if (mInnerFields.mOrientationChangeComplete && !mLayoutNeeded && |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 9106 | !mInnerFields.mUpdateRotation) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 9107 | checkDrawnWindowsLocked(); |
| 9108 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 9109 | |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 9110 | // Check to see if we are now in a state where the screen should |
| 9111 | // be enabled, because the window obscured flags have changed. |
| 9112 | enableScreenIfNeededLocked(); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9113 | |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 9114 | updateLayoutToAnimationLocked(); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9115 | |
| 9116 | if (DEBUG_WINDOW_TRACE) { |
| 9117 | Slog.e(TAG, "performLayoutAndPlaceSurfacesLockedInner exit: mPendingLayoutChanges=" |
| 9118 | + Integer.toHexString(mPendingLayoutChanges) + " mLayoutNeeded=" + mLayoutNeeded |
| 9119 | + " animating=" + mAnimator.mAnimating); |
| 9120 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9121 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 9122 | |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 9123 | void checkDrawnWindowsLocked() { |
| 9124 | if (mWaitingForDrawn.size() > 0) { |
| 9125 | for (int j=mWaitingForDrawn.size()-1; j>=0; j--) { |
| 9126 | Pair<WindowState, IRemoteCallback> pair = mWaitingForDrawn.get(j); |
| 9127 | WindowState win = pair.first; |
| 9128 | //Slog.i(TAG, "Waiting for drawn " + win + ": removed=" |
| 9129 | // + win.mRemoved + " visible=" + win.isVisibleLw() |
| 9130 | // + " shown=" + win.mSurfaceShown); |
| 9131 | if (win.mRemoved || !win.isVisibleLw()) { |
| 9132 | // Window has been removed or made invisible; no draw |
| 9133 | // will now happen, so stop waiting. |
| 9134 | Slog.w(TAG, "Aborted waiting for drawn: " + pair.first); |
| 9135 | try { |
| 9136 | pair.second.sendResult(null); |
| 9137 | } catch (RemoteException e) { |
| 9138 | } |
| 9139 | mWaitingForDrawn.remove(pair); |
| 9140 | mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT, pair); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9141 | } else if (win.mWinAnimator.mSurfaceShown) { |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 9142 | // Window is now drawn (and shown). |
| 9143 | try { |
| 9144 | pair.second.sendResult(null); |
| 9145 | } catch (RemoteException e) { |
| 9146 | } |
| 9147 | mWaitingForDrawn.remove(pair); |
| 9148 | mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT, pair); |
| 9149 | } |
| 9150 | } |
| 9151 | } |
| 9152 | } |
| 9153 | |
| 9154 | public void waitForWindowDrawn(IBinder token, IRemoteCallback callback) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 9155 | synchronized (mWindowMap) { |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 9156 | WindowState win = windowForClientLocked(null, token, true); |
| 9157 | if (win != null) { |
| 9158 | Pair<WindowState, IRemoteCallback> pair = |
| 9159 | new Pair<WindowState, IRemoteCallback>(win, callback); |
| 9160 | Message m = mH.obtainMessage(H.WAITING_FOR_DRAWN_TIMEOUT, pair); |
| 9161 | mH.sendMessageDelayed(m, 2000); |
| 9162 | mWaitingForDrawn.add(pair); |
| 9163 | checkDrawnWindowsLocked(); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 9164 | } |
| 9165 | } |
| 9166 | } |
| 9167 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9168 | /** |
| 9169 | * Must be called with the main window manager lock held. |
| 9170 | */ |
| 9171 | void setHoldScreenLocked(boolean holding) { |
| 9172 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 9173 | if (holding != state) { |
| 9174 | if (holding) { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 9175 | mPolicy.screenOnStartedLw(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9176 | mHoldingScreenWakeLock.acquire(); |
| 9177 | } else { |
| 9178 | mPolicy.screenOnStoppedLw(); |
| 9179 | mHoldingScreenWakeLock.release(); |
| 9180 | } |
| 9181 | } |
| 9182 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9183 | |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 9184 | void requestTraversalLocked() { |
| 9185 | if (!mTraversalScheduled) { |
| 9186 | mTraversalScheduled = true; |
| 9187 | mH.sendEmptyMessage(H.DO_TRAVERSAL); |
| 9188 | } |
| 9189 | } |
| 9190 | |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 9191 | /** Note that Locked in this case is on mLayoutToAnim */ |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 9192 | void scheduleAnimationLocked() { |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 9193 | final LayoutToAnimatorParams layoutToAnim = mLayoutToAnim; |
| 9194 | if (!layoutToAnim.mAnimationScheduled) { |
| 9195 | layoutToAnim.mAnimationScheduled = true; |
| 9196 | mChoreographer.postCallback( |
| 9197 | Choreographer.CALLBACK_ANIMATION, mAnimator.mAnimationRunnable, null); |
| 9198 | } |
| 9199 | } |
| 9200 | |
| 9201 | void updateLayoutToAnimationLocked() { |
| 9202 | final LayoutToAnimatorParams layoutToAnim = mLayoutToAnim; |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 9203 | synchronized (layoutToAnim) { |
| 9204 | // Copy local params to transfer params. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9205 | ArrayList<WinAnimatorList> allWinAnimatorLists = layoutToAnim.mWinAnimatorLists; |
| 9206 | allWinAnimatorLists.clear(); |
| 9207 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 9208 | while (iterator.hasNext()) { |
| 9209 | final DisplayContent displayContent = iterator.next(); |
| 9210 | WinAnimatorList winAnimatorList = new WinAnimatorList(); |
| 9211 | final WindowList windows = displayContent.getWindowList(); |
| 9212 | int N = windows.size(); |
| 9213 | for (int i = 0; i < N; i++) { |
| 9214 | final WindowStateAnimator winAnimator = windows.get(i).mWinAnimator; |
| 9215 | if (winAnimator.mSurface != null) { |
| 9216 | winAnimatorList.add(winAnimator); |
| 9217 | } |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 9218 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9219 | allWinAnimatorLists.add(winAnimatorList); |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 9220 | } |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 9221 | |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 9222 | layoutToAnim.mWallpaperTarget = mWallpaperTarget; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 9223 | layoutToAnim.mLowerWallpaperTarget = mLowerWallpaperTarget; |
| 9224 | layoutToAnim.mUpperWallpaperTarget = mUpperWallpaperTarget; |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 9225 | |
| 9226 | final ArrayList<AppWindowAnimParams> paramList = layoutToAnim.mAppWindowAnimParams; |
| 9227 | paramList.clear(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9228 | int N = mAnimatingAppTokens.size(); |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 9229 | for (int i = 0; i < N; i++) { |
| 9230 | paramList.add(new AppWindowAnimParams(mAnimatingAppTokens.get(i).mAppAnimator)); |
| 9231 | } |
| 9232 | |
| 9233 | layoutToAnim.mParamsModified = true; |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 9234 | scheduleAnimationLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9235 | } |
| 9236 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9237 | |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 9238 | void updateLayoutToAnimWallpaperTokens() { |
| 9239 | synchronized(mLayoutToAnim) { |
| 9240 | mLayoutToAnim.mWallpaperTokens = new ArrayList<WindowToken>(mWallpaperTokens); |
| 9241 | mLayoutToAnim.mChanges |= LayoutToAnimatorParams.WALLPAPER_TOKENS_CHANGED; |
| 9242 | } |
| 9243 | } |
| 9244 | |
Craig Mautner | a76fdb7 | 2012-07-03 19:03:02 -0700 | [diff] [blame] | 9245 | void setAnimDimParams(DimAnimator.Parameters params) { |
| 9246 | synchronized (mLayoutToAnim) { |
| 9247 | mLayoutToAnim.mDimParams = params; |
| 9248 | scheduleAnimationLocked(); |
| 9249 | } |
| 9250 | } |
| 9251 | |
| 9252 | void startDimming(final WindowStateAnimator winAnimator, final float target, |
| 9253 | final int width, final int height) { |
| 9254 | setAnimDimParams(new DimAnimator.Parameters(winAnimator, width, height, target)); |
| 9255 | } |
| 9256 | |
| 9257 | void stopDimming() { |
| 9258 | setAnimDimParams(null); |
| 9259 | } |
| 9260 | |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 9261 | private boolean copyAnimToLayoutParamsLocked() { |
| 9262 | boolean doRequest = false; |
| 9263 | final WindowAnimator.AnimatorToLayoutParams animToLayout = mAnimator.mAnimToLayout; |
| 9264 | synchronized (animToLayout) { |
| 9265 | animToLayout.mUpdateQueued = false; |
| 9266 | final int bulkUpdateParams = animToLayout.mBulkUpdateParams; |
| 9267 | // TODO(cmautner): As the number of bits grows, use masks of bit groups to |
| 9268 | // eliminate unnecessary tests. |
| 9269 | if ((bulkUpdateParams & LayoutFields.SET_UPDATE_ROTATION) != 0) { |
| 9270 | mInnerFields.mUpdateRotation = true; |
| 9271 | doRequest = true; |
| 9272 | } |
| 9273 | if ((bulkUpdateParams & LayoutFields.SET_WALLPAPER_MAY_CHANGE) != 0) { |
| 9274 | mInnerFields.mWallpaperMayChange = true; |
| 9275 | doRequest = true; |
| 9276 | } |
| 9277 | if ((bulkUpdateParams & LayoutFields.SET_FORCE_HIDING_CHANGED) != 0) { |
| 9278 | mInnerFields.mWallpaperForceHidingChanged = true; |
| 9279 | doRequest = true; |
| 9280 | } |
| 9281 | if ((bulkUpdateParams & LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE) == 0) { |
| 9282 | mInnerFields.mOrientationChangeComplete = false; |
| 9283 | } else { |
| 9284 | mInnerFields.mOrientationChangeComplete = true; |
| 9285 | if (mWindowsFreezingScreen) { |
| 9286 | doRequest = true; |
| 9287 | } |
| 9288 | } |
| 9289 | if ((bulkUpdateParams & LayoutFields.SET_TURN_ON_SCREEN) != 0) { |
| 9290 | mTurnOnScreen = true; |
| 9291 | } |
| 9292 | |
| 9293 | mPendingLayoutChanges |= animToLayout.mPendingLayoutChanges; |
| 9294 | if (mPendingLayoutChanges != 0) { |
| 9295 | doRequest = true; |
| 9296 | } |
| 9297 | |
| 9298 | mWindowDetachedWallpaper = animToLayout.mWindowDetachedWallpaper; |
| 9299 | } |
| 9300 | return doRequest; |
| 9301 | } |
| 9302 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9303 | boolean reclaimSomeSurfaceMemoryLocked(WindowStateAnimator winAnimator, String operation, |
| 9304 | boolean secure) { |
| 9305 | final Surface surface = winAnimator.mSurface; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 9306 | boolean leakedSurface = false; |
| 9307 | boolean killedApps = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9308 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9309 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(), |
| 9310 | winAnimator.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9311 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9312 | if (mForceRemoves == null) { |
| 9313 | mForceRemoves = new ArrayList<WindowState>(); |
| 9314 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9315 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9316 | long callingIdentity = Binder.clearCallingIdentity(); |
| 9317 | try { |
| 9318 | // There was some problem... first, do a sanity check of the |
| 9319 | // window list to make sure we haven't left any dangling surfaces |
| 9320 | // around. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9321 | |
| 9322 | AllWindowsIterator iterator = new AllWindowsIterator(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9323 | Slog.i(TAG, "Out of memory for surface! Looking for leaks..."); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9324 | while (iterator.hasNext()) { |
| 9325 | WindowState ws = iterator.next(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9326 | WindowStateAnimator wsa = ws.mWinAnimator; |
| 9327 | if (wsa.mSurface != null) { |
| 9328 | if (!mSessions.contains(wsa.mSession)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9329 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9330 | + ws + " surface=" + wsa.mSurface |
| 9331 | + " token=" + ws.mToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9332 | + " pid=" + ws.mSession.mPid |
| 9333 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9334 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9335 | wsa.mSurface.destroy(); |
| 9336 | wsa.mSurfaceShown = false; |
| 9337 | wsa.mSurface = null; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 9338 | ws.mHasSurface = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9339 | mForceRemoves.add(ws); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9340 | leakedSurface = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9341 | } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9342 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9343 | + ws + " surface=" + wsa.mSurface |
| 9344 | + " token=" + ws.mAppToken); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9345 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9346 | wsa.mSurface.destroy(); |
| 9347 | wsa.mSurfaceShown = false; |
| 9348 | wsa.mSurface = null; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 9349 | ws.mHasSurface = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9350 | leakedSurface = true; |
| 9351 | } |
| 9352 | } |
| 9353 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9354 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9355 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9356 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9357 | SparseIntArray pidCandidates = new SparseIntArray(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9358 | iterator = new AllWindowsIterator(); |
| 9359 | while (iterator.hasNext()) { |
| 9360 | WindowState ws = iterator.next(); |
| 9361 | if (mForceRemoves.contains(ws)) { |
| 9362 | continue; |
| 9363 | } |
| 9364 | WindowStateAnimator wsa = ws.mWinAnimator; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9365 | if (wsa.mSurface != null) { |
| 9366 | pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9367 | } |
| 9368 | } |
| 9369 | if (pidCandidates.size() > 0) { |
| 9370 | int[] pids = new int[pidCandidates.size()]; |
| 9371 | for (int i=0; i<pids.length; i++) { |
| 9372 | pids[i] = pidCandidates.keyAt(i); |
| 9373 | } |
| 9374 | try { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 9375 | if (mActivityManager.killPids(pids, "Free memory", secure)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9376 | killedApps = true; |
| 9377 | } |
| 9378 | } catch (RemoteException e) { |
| 9379 | } |
| 9380 | } |
| 9381 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9383 | if (leakedSurface || killedApps) { |
| 9384 | // We managed to reclaim some memory, so get rid of the trouble |
| 9385 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9386 | 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] | 9387 | if (surface != null) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9388 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin, |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 9389 | "RECOVER DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9390 | surface.destroy(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9391 | winAnimator.mSurfaceShown = false; |
| 9392 | winAnimator.mSurface = null; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 9393 | winAnimator.mWin.mHasSurface = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9394 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9395 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9396 | try { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9397 | winAnimator.mWin.mClient.dispatchGetNewSurface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9398 | } catch (RemoteException e) { |
| 9399 | } |
| 9400 | } |
| 9401 | } finally { |
| 9402 | Binder.restoreCallingIdentity(callingIdentity); |
| 9403 | } |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 9404 | |
| 9405 | return leakedSurface || killedApps; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9406 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9407 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9408 | private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9409 | WindowState newFocus = computeFocusedWindowLocked(); |
| 9410 | if (mCurrentFocus != newFocus) { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 9411 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmUpdateFocus"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9412 | // This check makes sure that we don't already have the focus |
| 9413 | // change message pending. |
| 9414 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 9415 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9416 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9417 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 9418 | final WindowState oldFocus = mCurrentFocus; |
| 9419 | mCurrentFocus = newFocus; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 9420 | mAnimator.setCurrentFocus(newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9421 | mLosingFocus.remove(newFocus); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9422 | int focusChanged = mPolicy.focusChangedLw(oldFocus, newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9423 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9424 | // TODO(multidisplay): Focused windows on default display only. |
| 9425 | final DisplayContent displayContent = getDefaultDisplayContent(); |
| 9426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9427 | final WindowState imWindow = mInputMethodWindow; |
| 9428 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9429 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9430 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9431 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 9432 | mLayoutNeeded = true; |
| 9433 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9434 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9435 | performLayoutLockedInner(displayContent, true /*initial*/, updateInputWindows); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9436 | focusChanged &= ~WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9437 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 9438 | // Client will do the layout, but we need to assign layers |
| 9439 | // for handleNewWindowLocked() below. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9440 | assignLayersLocked(displayContent.getWindowList()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9441 | } |
| 9442 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9443 | |
| 9444 | if ((focusChanged&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9445 | // The change in focus caused us to need to do a layout. Okay. |
| 9446 | mLayoutNeeded = true; |
| 9447 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9448 | performLayoutLockedInner(displayContent, true /*initial*/, updateInputWindows); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9449 | } |
| 9450 | } |
| 9451 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9452 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 9453 | // If we defer assigning layers, then the caller is responsible for |
| 9454 | // doing this part. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9455 | finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9456 | } |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 9457 | |
| 9458 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9459 | return true; |
| 9460 | } |
| 9461 | return false; |
| 9462 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9463 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9464 | private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) { |
| 9465 | mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9466 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9467 | |
| 9468 | private WindowState computeFocusedWindowLocked() { |
| 9469 | WindowState result = null; |
| 9470 | WindowState win; |
| 9471 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 9472 | if (mAnimator.mUniverseBackground != null |
| 9473 | && mAnimator.mUniverseBackground.mWin.canReceiveKeys()) { |
| 9474 | return mAnimator.mUniverseBackground.mWin; |
| 9475 | } |
| 9476 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9477 | int nextAppIndex = mAppTokens.size()-1; |
| 9478 | WindowToken nextApp = nextAppIndex >= 0 |
| 9479 | ? mAppTokens.get(nextAppIndex) : null; |
| 9480 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9481 | // TODO(multidisplay): IMEs are only supported on the default display. |
| 9482 | WindowList windows = getDefaultWindowList(); |
| 9483 | for (int i = windows.size() - 1; i >= 0; i--) { |
| 9484 | win = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9485 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9486 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9487 | TAG, "Looking for focus: " + i |
| 9488 | + " = " + win |
| 9489 | + ", flags=" + win.mAttrs.flags |
| 9490 | + ", canReceive=" + win.canReceiveKeys()); |
| 9491 | |
| 9492 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9494 | // If this window's application has been removed, just skip it. |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 9495 | if (thisApp != null && (thisApp.removed || thisApp.sendingToBottom)) { |
Craig Mautner | 3f99fde | 2012-06-19 14:10:01 -0700 | [diff] [blame] | 9496 | if (DEBUG_FOCUS) Slog.v(TAG, "Skipping app because " + (thisApp.removed |
| 9497 | ? "removed" : "sendingToBottom")); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9498 | continue; |
| 9499 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9500 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9501 | // If there is a focused app, don't allow focus to go to any |
| 9502 | // windows below it. If this is an application window, step |
| 9503 | // through the app tokens until we find its app. |
| 9504 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 9505 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 9506 | int origAppIndex = nextAppIndex; |
| 9507 | while (nextAppIndex > 0) { |
| 9508 | if (nextApp == mFocusedApp) { |
| 9509 | // Whoops, we are below the focused app... no focus |
| 9510 | // for you! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9511 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9512 | TAG, "Reached focused app: " + mFocusedApp); |
| 9513 | return null; |
| 9514 | } |
| 9515 | nextAppIndex--; |
| 9516 | nextApp = mAppTokens.get(nextAppIndex); |
| 9517 | if (nextApp == thisApp) { |
| 9518 | break; |
| 9519 | } |
| 9520 | } |
| 9521 | if (thisApp != nextApp) { |
| 9522 | // Uh oh, the app token doesn't exist! This shouldn't |
| 9523 | // happen, but if it does we can get totally hosed... |
| 9524 | // so restart at the original app. |
| 9525 | nextAppIndex = origAppIndex; |
| 9526 | nextApp = mAppTokens.get(nextAppIndex); |
| 9527 | } |
| 9528 | } |
| 9529 | |
| 9530 | // Dispatch to this window if it is wants key events. |
| 9531 | if (win.canReceiveKeys()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9532 | if (DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9533 | TAG, "Found focus @ " + i + " = " + win); |
| 9534 | result = win; |
| 9535 | break; |
| 9536 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9537 | } |
| 9538 | |
| 9539 | return result; |
| 9540 | } |
| 9541 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9542 | private void startFreezingDisplayLocked(boolean inTransaction) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9543 | if (mDisplayFrozen) { |
| 9544 | return; |
| 9545 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9546 | |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 9547 | if (mDisplay == null || !mPolicy.isScreenOnFully()) { |
Dianne Hackborn | 8e8d65f | 2011-08-11 19:36:18 -0700 | [diff] [blame] | 9548 | // No need to freeze the screen before the system is ready or if |
| 9549 | // the screen is off. |
| 9550 | return; |
| 9551 | } |
| 9552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9553 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9554 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9555 | mDisplayFrozen = true; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9556 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9557 | mInputMonitor.freezeInputDispatchingLw(); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9558 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9559 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 9560 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 9561 | mNextAppTransitionType = ActivityOptions.ANIM_NONE; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9562 | mNextAppTransitionPackage = null; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 9563 | mNextAppTransitionThumbnail = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9564 | mAppTransitionReady = true; |
| 9565 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9567 | if (PROFILE_ORIENTATION) { |
| 9568 | File file = new File("/data/system/frozen"); |
| 9569 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 9570 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 9571 | |
| 9572 | if (CUSTOM_SCREEN_ROTATION) { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9573 | if (mAnimator.mScreenRotationAnimation != null) { |
| 9574 | mAnimator.mScreenRotationAnimation.kill(); |
| 9575 | mAnimator.mScreenRotationAnimation = null; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 9576 | } |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 9577 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9578 | // TODO(multidisplay): rotation on main screen only. |
| 9579 | DisplayInfo displayInfo = getDefaultDisplayContent().getDisplayInfo(); |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 9580 | mAnimator.mScreenRotationAnimation = new ScreenRotationAnimation(mContext, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9581 | mFxSession, inTransaction, displayInfo.logicalWidth, displayInfo.logicalHeight, |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 9582 | mDisplay.getRotation()); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 9583 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9584 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9585 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9586 | private void stopFreezingDisplayLocked() { |
| 9587 | if (!mDisplayFrozen) { |
| 9588 | return; |
| 9589 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9590 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9591 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 9592 | if (DEBUG_ORIENTATION) Slog.d(TAG, |
| 9593 | "stopFreezingDisplayLocked: Returning mWaitingForConfig=" + mWaitingForConfig |
| 9594 | + ", mAppsFreezingScreen=" + mAppsFreezingScreen |
| 9595 | + ", mWindowsFreezingScreen=" + mWindowsFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9596 | return; |
| 9597 | } |
| 9598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9599 | mDisplayFrozen = false; |
| 9600 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 9601 | if (PROFILE_ORIENTATION) { |
| 9602 | Debug.stopMethodTracing(); |
| 9603 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 9604 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9605 | boolean updateRotation = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9606 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9607 | if (CUSTOM_SCREEN_ROTATION && mAnimator.mScreenRotationAnimation != null |
| 9608 | && mAnimator.mScreenRotationAnimation.hasScreenshot()) { |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 9609 | if (DEBUG_ORIENTATION) Slog.i(TAG, "**** Dismissing screen rotation animation"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9610 | // TODO(multidisplay): rotation on main screen only. |
| 9611 | DisplayInfo displayInfo = getDefaultDisplayContent().getDisplayInfo(); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9612 | if (mAnimator.mScreenRotationAnimation.dismiss(mFxSession, MAX_ANIMATION_DURATION, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9613 | mTransitionAnimationScale, displayInfo.logicalWidth, |
| 9614 | displayInfo.logicalHeight)) { |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 9615 | updateLayoutToAnimationLocked(); |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 9616 | } else { |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9617 | mAnimator.mScreenRotationAnimation.kill(); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9618 | mAnimator.mScreenRotationAnimation = null; |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 9619 | updateRotation = true; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 9620 | } |
| 9621 | } else { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9622 | if (mAnimator.mScreenRotationAnimation != null) { |
| 9623 | mAnimator.mScreenRotationAnimation.kill(); |
| 9624 | mAnimator.mScreenRotationAnimation = null; |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 9625 | } |
| 9626 | updateRotation = true; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 9627 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9628 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9629 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9630 | |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 9631 | boolean configChanged; |
| 9632 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 9633 | // While the display is frozen we don't re-compute the orientation |
| 9634 | // to avoid inconsistent states. However, something interesting |
| 9635 | // could have actually changed during that time so re-evaluate it |
| 9636 | // now to catch that. |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 9637 | configChanged = updateOrientationFromAppTokensLocked(false); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 9638 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9639 | // A little kludge: a lot could have happened while the |
| 9640 | // display was frozen, so now that we are coming back we |
| 9641 | // do a gc so that any remote references the system |
| 9642 | // processes holds on others can be released if they are |
| 9643 | // no longer needed. |
| 9644 | mH.removeMessages(H.FORCE_GC); |
| 9645 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9646 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9647 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9648 | mScreenFrozenLock.release(); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9649 | |
| 9650 | if (updateRotation) { |
| 9651 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 9652 | configChanged |= updateRotationUncheckedLocked(false); |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 9653 | } |
| 9654 | |
| 9655 | if (configChanged) { |
| 9656 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9657 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9658 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9659 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 9660 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 9661 | DisplayMetrics dm) { |
| 9662 | if (index < tokens.length) { |
| 9663 | String str = tokens[index]; |
| 9664 | if (str != null && str.length() > 0) { |
| 9665 | try { |
| 9666 | int val = Integer.parseInt(str); |
| 9667 | return val; |
| 9668 | } catch (Exception e) { |
| 9669 | } |
| 9670 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9671 | } |
| 9672 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 9673 | return defDps; |
| 9674 | } |
| 9675 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 9676 | return val; |
| 9677 | } |
| 9678 | |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9679 | void createWatermark() { |
| 9680 | if (mWatermark != null) { |
| 9681 | return; |
| 9682 | } |
| 9683 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 9684 | File file = new File("/system/etc/setup.conf"); |
| 9685 | FileInputStream in = null; |
| 9686 | try { |
| 9687 | in = new FileInputStream(file); |
| 9688 | DataInputStream ind = new DataInputStream(in); |
| 9689 | String line = ind.readLine(); |
| 9690 | if (line != null) { |
| 9691 | String[] toks = line.split("%"); |
| 9692 | if (toks != null && toks.length > 0) { |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 9693 | mWatermark = new Watermark(mRealDisplayMetrics, mFxSession, toks); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 9694 | } |
| 9695 | } |
| 9696 | } catch (FileNotFoundException e) { |
| 9697 | } catch (IOException e) { |
| 9698 | } finally { |
| 9699 | if (in != null) { |
| 9700 | try { |
| 9701 | in.close(); |
| 9702 | } catch (IOException e) { |
| 9703 | } |
| 9704 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9705 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9706 | } |
| 9707 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9708 | @Override |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 9709 | public void statusBarVisibilityChanged(int visibility) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9710 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR) |
| 9711 | != PackageManager.PERMISSION_GRANTED) { |
| 9712 | throw new SecurityException("Caller does not hold permission " |
| 9713 | + android.Manifest.permission.STATUS_BAR); |
| 9714 | } |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 9715 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 9716 | synchronized (mWindowMap) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9717 | mLastStatusBarVisibility = visibility; |
| 9718 | visibility = mPolicy.adjustSystemUiVisibilityLw(visibility); |
| 9719 | updateStatusBarVisibilityLocked(visibility); |
| 9720 | } |
| 9721 | } |
| 9722 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9723 | // TOOD(multidisplay): StatusBar on multiple screens? |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9724 | void updateStatusBarVisibilityLocked(int visibility) { |
| 9725 | mInputManager.setSystemUiVisibility(visibility); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9726 | final WindowList windows = getDefaultWindowList(); |
| 9727 | final int N = windows.size(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9728 | for (int i = 0; i < N; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9729 | WindowState ws = windows.get(i); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9730 | try { |
| 9731 | int curValue = ws.mSystemUiVisibility; |
| 9732 | int diff = curValue ^ visibility; |
| 9733 | // We are only interested in differences of one of the |
| 9734 | // clearable flags... |
| 9735 | diff &= View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 9736 | // ...if it has actually been cleared. |
| 9737 | diff &= ~visibility; |
| 9738 | int newValue = (curValue&~diff) | (visibility&diff); |
| 9739 | if (newValue != curValue) { |
| 9740 | ws.mSeq++; |
| 9741 | ws.mSystemUiVisibility = newValue; |
| 9742 | } |
| 9743 | if (newValue != curValue || ws.mAttrs.hasSystemUiListeners) { |
| 9744 | ws.mClient.dispatchSystemUiVisibilityChanged(ws.mSeq, |
| 9745 | visibility, newValue, diff); |
| 9746 | } |
| 9747 | } catch (RemoteException e) { |
| 9748 | // so sorry |
| 9749 | } |
| 9750 | } |
| 9751 | } |
| 9752 | |
| 9753 | @Override |
| 9754 | public void reevaluateStatusBarVisibility() { |
| 9755 | synchronized (mWindowMap) { |
| 9756 | int visibility = mPolicy.adjustSystemUiVisibilityLw(mLastStatusBarVisibility); |
| 9757 | updateStatusBarVisibilityLocked(visibility); |
| 9758 | performLayoutAndPlaceSurfacesLocked(); |
| 9759 | } |
| 9760 | } |
| 9761 | |
| 9762 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 9763 | public FakeWindow addFakeWindow(Looper looper, |
| 9764 | InputEventReceiver.Factory inputEventReceiverFactory, |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9765 | String name, int windowType, int layoutParamsFlags, boolean canReceiveKeys, |
| 9766 | boolean hasFocus, boolean touchFullscreen) { |
| 9767 | synchronized (mWindowMap) { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 9768 | FakeWindowImpl fw = new FakeWindowImpl(this, looper, inputEventReceiverFactory, |
| 9769 | name, windowType, |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9770 | layoutParamsFlags, canReceiveKeys, hasFocus, touchFullscreen); |
| 9771 | int i=0; |
| 9772 | while (i<mFakeWindows.size()) { |
| 9773 | if (mFakeWindows.get(i).mWindowLayer <= fw.mWindowLayer) { |
| 9774 | break; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 9775 | } |
| 9776 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9777 | mFakeWindows.add(i, fw); |
| 9778 | mInputMonitor.updateInputWindowsLw(true); |
| 9779 | return fw; |
| 9780 | } |
| 9781 | } |
| 9782 | |
| 9783 | boolean removeFakeWindowLocked(FakeWindow window) { |
| 9784 | synchronized (mWindowMap) { |
| 9785 | if (mFakeWindows.remove(window)) { |
| 9786 | mInputMonitor.updateInputWindowsLw(true); |
| 9787 | return true; |
| 9788 | } |
| 9789 | return false; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 9790 | } |
| 9791 | } |
| 9792 | |
satok | e0a9941 | 2012-05-10 02:22:58 +0900 | [diff] [blame] | 9793 | // It is assumed that this method is called only by InputMethodManagerService. |
| 9794 | public void saveLastInputMethodWindowForTransition() { |
| 9795 | synchronized (mWindowMap) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9796 | // TODO(multidisplay): Pass in the displayID. |
| 9797 | DisplayContent displayContent = getDefaultDisplayContent(); |
satok | e0a9941 | 2012-05-10 02:22:58 +0900 | [diff] [blame] | 9798 | if (mInputMethodWindow != null) { |
| 9799 | mPolicy.setLastInputMethodWindowLw(mInputMethodWindow, mInputMethodTarget); |
| 9800 | } |
| 9801 | } |
| 9802 | } |
| 9803 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 9804 | @Override |
| 9805 | public boolean hasNavigationBar() { |
| 9806 | return mPolicy.hasNavigationBar(); |
| 9807 | } |
| 9808 | |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 9809 | public void lockNow() { |
| 9810 | mPolicy.lockNow(); |
| 9811 | } |
| 9812 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 9813 | void dumpPolicyLocked(PrintWriter pw, String[] args, boolean dumpAll) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 9814 | pw.println("WINDOW MANAGER POLICY STATE (dumpsys window policy)"); |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 9815 | mPolicy.dump(" ", pw, args); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 9816 | } |
| 9817 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 9818 | void dumpTokensLocked(PrintWriter pw, boolean dumpAll) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 9819 | pw.println("WINDOW MANAGER TOKENS (dumpsys window tokens)"); |
| 9820 | if (mTokenMap.size() > 0) { |
| 9821 | pw.println(" All tokens:"); |
| 9822 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 9823 | while (it.hasNext()) { |
| 9824 | WindowToken token = it.next(); |
| 9825 | pw.print(" Token "); pw.print(token.token); |
| 9826 | if (dumpAll) { |
| 9827 | pw.println(':'); |
| 9828 | token.dump(pw, " "); |
| 9829 | } else { |
| 9830 | pw.println(); |
| 9831 | } |
| 9832 | } |
| 9833 | } |
| 9834 | if (mWallpaperTokens.size() > 0) { |
| 9835 | pw.println(); |
| 9836 | pw.println(" Wallpaper tokens:"); |
| 9837 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 9838 | WindowToken token = mWallpaperTokens.get(i); |
| 9839 | pw.print(" Wallpaper #"); pw.print(i); |
| 9840 | pw.print(' '); pw.print(token); |
| 9841 | if (dumpAll) { |
| 9842 | pw.println(':'); |
| 9843 | token.dump(pw, " "); |
| 9844 | } else { |
| 9845 | pw.println(); |
| 9846 | } |
| 9847 | } |
| 9848 | } |
| 9849 | if (mAppTokens.size() > 0) { |
| 9850 | pw.println(); |
| 9851 | pw.println(" Application tokens in Z order:"); |
| 9852 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 9853 | pw.print(" App #"); pw.print(i); pw.println(": "); |
| 9854 | mAppTokens.get(i).dump(pw, " "); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 9855 | } |
| 9856 | } |
| 9857 | if (mFinishedStarting.size() > 0) { |
| 9858 | pw.println(); |
| 9859 | pw.println(" Finishing start of application tokens:"); |
| 9860 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 9861 | WindowToken token = mFinishedStarting.get(i); |
| 9862 | pw.print(" Finished Starting #"); pw.print(i); |
| 9863 | pw.print(' '); pw.print(token); |
| 9864 | if (dumpAll) { |
| 9865 | pw.println(':'); |
| 9866 | token.dump(pw, " "); |
| 9867 | } else { |
| 9868 | pw.println(); |
| 9869 | } |
| 9870 | } |
| 9871 | } |
| 9872 | if (mExitingTokens.size() > 0) { |
| 9873 | pw.println(); |
| 9874 | pw.println(" Exiting tokens:"); |
| 9875 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 9876 | WindowToken token = mExitingTokens.get(i); |
| 9877 | pw.print(" Exiting #"); pw.print(i); |
| 9878 | pw.print(' '); pw.print(token); |
| 9879 | if (dumpAll) { |
| 9880 | pw.println(':'); |
| 9881 | token.dump(pw, " "); |
| 9882 | } else { |
| 9883 | pw.println(); |
| 9884 | } |
| 9885 | } |
| 9886 | } |
| 9887 | if (mExitingAppTokens.size() > 0) { |
| 9888 | pw.println(); |
| 9889 | pw.println(" Exiting application tokens:"); |
| 9890 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9891 | WindowToken token = mExitingAppTokens.get(i); |
| 9892 | pw.print(" Exiting App #"); pw.print(i); |
| 9893 | pw.print(' '); pw.print(token); |
| 9894 | if (dumpAll) { |
| 9895 | pw.println(':'); |
| 9896 | token.dump(pw, " "); |
| 9897 | } else { |
| 9898 | pw.println(); |
| 9899 | } |
| 9900 | } |
| 9901 | } |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 9902 | if (mAppTransitionRunning && mAnimatingAppTokens.size() > 0) { |
| 9903 | pw.println(); |
| 9904 | pw.println(" Application tokens during animation:"); |
| 9905 | for (int i=mAnimatingAppTokens.size()-1; i>=0; i--) { |
| 9906 | WindowToken token = mAnimatingAppTokens.get(i); |
| 9907 | pw.print(" App moving to bottom #"); pw.print(i); |
| 9908 | pw.print(' '); pw.print(token); |
| 9909 | if (dumpAll) { |
| 9910 | pw.println(':'); |
| 9911 | token.dump(pw, " "); |
| 9912 | } else { |
| 9913 | pw.println(); |
| 9914 | } |
| 9915 | } |
| 9916 | } |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 9917 | if (mOpeningApps.size() > 0 || mClosingApps.size() > 0) { |
| 9918 | pw.println(); |
| 9919 | if (mOpeningApps.size() > 0) { |
| 9920 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 9921 | } |
| 9922 | if (mClosingApps.size() > 0) { |
| 9923 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 9924 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 9925 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 9926 | } |
| 9927 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 9928 | void dumpSessionsLocked(PrintWriter pw, boolean dumpAll) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 9929 | pw.println("WINDOW MANAGER SESSIONS (dumpsys window sessions)"); |
| 9930 | if (mSessions.size() > 0) { |
| 9931 | Iterator<Session> it = mSessions.iterator(); |
| 9932 | while (it.hasNext()) { |
| 9933 | Session s = it.next(); |
| 9934 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| 9935 | s.dump(pw, " "); |
| 9936 | } |
| 9937 | } |
| 9938 | } |
| 9939 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 9940 | void dumpWindowsLocked(PrintWriter pw, boolean dumpAll, |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 9941 | ArrayList<WindowState> windows) { |
| 9942 | pw.println("WINDOW MANAGER WINDOWS (dumpsys window windows)"); |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 9943 | dumpWindowsNoHeaderLocked(pw, dumpAll, windows); |
| 9944 | } |
| 9945 | |
| 9946 | void dumpWindowsNoHeaderLocked(PrintWriter pw, boolean dumpAll, |
| 9947 | ArrayList<WindowState> windows) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9948 | int j = 0; |
| 9949 | final AllWindowsIterator iterator = new AllWindowsIterator(REVERSE_ITERATOR); |
| 9950 | while (iterator.hasNext()) { |
| 9951 | final WindowState w = iterator.next(); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 9952 | if (windows == null || windows.contains(w)) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9953 | pw.print(" Window #"); pw.print(j++); pw.print(' '); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9954 | pw.print(w); pw.println(":"); |
Dianne Hackborn | 8962028 | 2011-09-11 12:47:45 -0700 | [diff] [blame] | 9955 | w.dump(pw, " ", dumpAll || windows != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9956 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 9957 | } |
| 9958 | if (mInputMethodDialogs.size() > 0) { |
| 9959 | pw.println(); |
| 9960 | pw.println(" Input method dialogs:"); |
| 9961 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 9962 | WindowState w = mInputMethodDialogs.get(i); |
| 9963 | if (windows == null || windows.contains(w)) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9964 | 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] | 9965 | } |
| 9966 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 9967 | } |
| 9968 | if (mPendingRemove.size() > 0) { |
| 9969 | pw.println(); |
| 9970 | pw.println(" Remove pending for:"); |
| 9971 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 9972 | WindowState w = mPendingRemove.get(i); |
| 9973 | if (windows == null || windows.contains(w)) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9974 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 9975 | pw.print(w); |
| 9976 | if (dumpAll) { |
| 9977 | pw.println(":"); |
| 9978 | w.dump(pw, " ", true); |
| 9979 | } else { |
| 9980 | pw.println(); |
| 9981 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9982 | } |
| 9983 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 9984 | } |
| 9985 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 9986 | pw.println(); |
| 9987 | pw.println(" Windows force removing:"); |
| 9988 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 9989 | WindowState w = mForceRemoves.get(i); |
| 9990 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 9991 | pw.print(w); |
| 9992 | if (dumpAll) { |
| 9993 | pw.println(":"); |
| 9994 | w.dump(pw, " ", true); |
| 9995 | } else { |
| 9996 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9997 | } |
| 9998 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 9999 | } |
| 10000 | if (mDestroySurface.size() > 0) { |
| 10001 | pw.println(); |
| 10002 | pw.println(" Windows waiting to destroy their surface:"); |
| 10003 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10004 | WindowState w = mDestroySurface.get(i); |
| 10005 | if (windows == null || windows.contains(w)) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10006 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10007 | pw.print(w); |
| 10008 | if (dumpAll) { |
| 10009 | pw.println(":"); |
| 10010 | w.dump(pw, " ", true); |
| 10011 | } else { |
| 10012 | pw.println(); |
| 10013 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10014 | } |
| 10015 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10016 | } |
| 10017 | if (mLosingFocus.size() > 0) { |
| 10018 | pw.println(); |
| 10019 | pw.println(" Windows losing focus:"); |
| 10020 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10021 | WindowState w = mLosingFocus.get(i); |
| 10022 | if (windows == null || windows.contains(w)) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10023 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10024 | pw.print(w); |
| 10025 | if (dumpAll) { |
| 10026 | pw.println(":"); |
| 10027 | w.dump(pw, " ", true); |
| 10028 | } else { |
| 10029 | pw.println(); |
| 10030 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10031 | } |
| 10032 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10033 | } |
| 10034 | if (mResizingWindows.size() > 0) { |
| 10035 | pw.println(); |
| 10036 | pw.println(" Windows waiting to resize:"); |
| 10037 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10038 | WindowState w = mResizingWindows.get(i); |
| 10039 | if (windows == null || windows.contains(w)) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10040 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10041 | pw.print(w); |
| 10042 | if (dumpAll) { |
| 10043 | pw.println(":"); |
| 10044 | w.dump(pw, " ", true); |
| 10045 | } else { |
| 10046 | pw.println(); |
| 10047 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10048 | } |
| 10049 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10050 | } |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 10051 | if (mWaitingForDrawn.size() > 0) { |
| 10052 | pw.println(); |
| 10053 | pw.println(" Clients waiting for these windows to be drawn:"); |
| 10054 | for (int i=mWaitingForDrawn.size()-1; i>=0; i--) { |
| 10055 | Pair<WindowState, IRemoteCallback> pair = mWaitingForDrawn.get(i); |
| 10056 | pw.print(" Waiting #"); pw.print(i); pw.print(' '); pw.print(pair.first); |
| 10057 | pw.print(": "); pw.println(pair.second); |
| 10058 | } |
| 10059 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10060 | pw.println(); |
| 10061 | if (mDisplay != null) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10062 | DisplayContentsIterator dCIterator = new DisplayContentsIterator(); |
| 10063 | while (dCIterator.hasNext()) { |
| 10064 | dCIterator.next().dump(pw); |
| 10065 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10066 | } else { |
| 10067 | pw.println(" NO DISPLAY"); |
| 10068 | } |
| 10069 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 10070 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10071 | if (mLastFocus != mCurrentFocus) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10072 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10073 | } |
| 10074 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10075 | if (mInputMethodTarget != null) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10076 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10077 | } |
| 10078 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 10079 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| 10080 | if (dumpAll) { |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 10081 | pw.print(" mSystemDecorRect="); pw.print(mSystemDecorRect.toShortString()); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 10082 | pw.print(" mSystemDecorLayer="); pw.print(mSystemDecorLayer); |
| 10083 | pw.print(" mScreenRecr="); pw.println(mScreenRect.toShortString()); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10084 | if (mLastStatusBarVisibility != 0) { |
| 10085 | pw.print(" mLastStatusBarVisibility=0x"); |
| 10086 | pw.println(Integer.toHexString(mLastStatusBarVisibility)); |
| 10087 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10088 | if (mInputMethodWindow != null) { |
| 10089 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| 10090 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10091 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10092 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10093 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10094 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10095 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10096 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10097 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| 10098 | if (mInputMethodAnimLayerAdjustment != 0 || |
| 10099 | mWallpaperAnimLayerAdjustment != 0) { |
| 10100 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| 10101 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10102 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10103 | pw.println(mWallpaperAnimLayerAdjustment); |
| 10104 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10105 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10106 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 10107 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 10108 | pw.print("mTransactionSequence="); pw.println(mTransactionSequence); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10109 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 10110 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10111 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 10112 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10113 | pw.print(" mRotation="); pw.print(mRotation); |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 10114 | pw.print(" mAltOrientation="); pw.println(mAltOrientation); |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 10115 | pw.print(" mLastWindowForcedOrientation="); pw.print(mLastWindowForcedOrientation); |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 10116 | pw.print(" mForcedAppOrientation="); pw.println(mForcedAppOrientation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 10117 | pw.print(" mDeferredRotationPauseCount="); pw.println(mDeferredRotationPauseCount); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 10118 | if (mAnimator.mScreenRotationAnimation != null) { |
Dianne Hackborn | 4dcece8 | 2012-02-10 14:50:32 -0800 | [diff] [blame] | 10119 | pw.println(" mScreenRotationAnimation:"); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 10120 | mAnimator.mScreenRotationAnimation.printTo(" ", pw); |
Dianne Hackborn | 4dcece8 | 2012-02-10 14:50:32 -0800 | [diff] [blame] | 10121 | } |
| 10122 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10123 | pw.print(" mTransitionWindowAnimationScale="); pw.print(mTransitionAnimationScale); |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 10124 | pw.print(" mAnimatorDurationScale="); pw.println(mAnimatorDurationScale); |
Dianne Hackborn | 4dcece8 | 2012-02-10 14:50:32 -0800 | [diff] [blame] | 10125 | pw.print(" mTraversalScheduled="); pw.print(mTraversalScheduled); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 10126 | pw.print(" mNextAppTransition=0x"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10127 | pw.print(Integer.toHexString(mNextAppTransition)); |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 10128 | pw.print(" mAppTransitionReady="); pw.println(mAppTransitionReady); |
| 10129 | pw.print(" mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 10130 | pw.print(" mAppTransitionTimeout="); pw.println(mAppTransitionTimeout); |
| 10131 | if (mNextAppTransitionType != ActivityOptions.ANIM_NONE) { |
| 10132 | pw.print(" mNextAppTransitionType="); pw.println(mNextAppTransitionType); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10133 | } |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 10134 | switch (mNextAppTransitionType) { |
| 10135 | case ActivityOptions.ANIM_CUSTOM: |
| 10136 | pw.print(" mNextAppTransitionPackage="); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 10137 | pw.println(mNextAppTransitionPackage); |
| 10138 | pw.print(" mNextAppTransitionEnter=0x"); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 10139 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 10140 | pw.print(" mNextAppTransitionExit=0x"); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 10141 | pw.println(Integer.toHexString(mNextAppTransitionExit)); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 10142 | break; |
| 10143 | case ActivityOptions.ANIM_SCALE_UP: |
| 10144 | pw.print(" mNextAppTransitionStartX="); pw.print(mNextAppTransitionStartX); |
| 10145 | pw.print(" mNextAppTransitionStartY="); |
| 10146 | pw.println(mNextAppTransitionStartY); |
| 10147 | pw.print(" mNextAppTransitionStartWidth="); |
| 10148 | pw.print(mNextAppTransitionStartWidth); |
| 10149 | pw.print(" mNextAppTransitionStartHeight="); |
| 10150 | pw.println(mNextAppTransitionStartHeight); |
| 10151 | break; |
| 10152 | case ActivityOptions.ANIM_THUMBNAIL: |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 10153 | case ActivityOptions.ANIM_THUMBNAIL_DELAYED: |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 10154 | pw.print(" mNextAppTransitionThumbnail="); |
| 10155 | pw.print(mNextAppTransitionThumbnail); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 10156 | pw.print(" mNextAppTransitionStartX="); |
| 10157 | pw.print(mNextAppTransitionStartX); |
| 10158 | pw.print(" mNextAppTransitionStartY="); |
| 10159 | pw.println(mNextAppTransitionStartY); |
| 10160 | pw.print(" mNextAppTransitionDelayed="); pw.println(mNextAppTransitionDelayed); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 10161 | break; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 10162 | } |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 10163 | if (mNextAppTransitionCallback != null) { |
| 10164 | pw.print(" mNextAppTransitionCallback="); |
| 10165 | pw.println(mNextAppTransitionCallback); |
| 10166 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10167 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 10168 | pw.print(" mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 10169 | pw.println(" Window Animator:"); |
| 10170 | mAnimator.dump(pw, " ", dumpAll); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10171 | } |
| 10172 | } |
| 10173 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10174 | boolean dumpWindows(PrintWriter pw, String name, String[] args, |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10175 | int opti, boolean dumpAll) { |
| 10176 | ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 10177 | if ("visible".equals(name)) { |
| 10178 | synchronized(mWindowMap) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10179 | final AllWindowsIterator iterator = new AllWindowsIterator(REVERSE_ITERATOR); |
| 10180 | while (iterator.hasNext()) { |
| 10181 | final WindowState w = iterator.next(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 10182 | if (w.mWinAnimator.mSurfaceShown) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10183 | windows.add(w); |
| 10184 | } |
| 10185 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10186 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10187 | } else { |
| 10188 | int objectId = 0; |
| 10189 | // See if this is an object ID. |
| 10190 | try { |
| 10191 | objectId = Integer.parseInt(name, 16); |
| 10192 | name = null; |
| 10193 | } catch (RuntimeException e) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10194 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10195 | synchronized(mWindowMap) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10196 | final AllWindowsIterator iterator = new AllWindowsIterator(REVERSE_ITERATOR); |
| 10197 | while (iterator.hasNext()) { |
| 10198 | final WindowState w = iterator.next(); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10199 | if (name != null) { |
| 10200 | if (w.mAttrs.getTitle().toString().contains(name)) { |
| 10201 | windows.add(w); |
| 10202 | } |
| 10203 | } else if (System.identityHashCode(w) == objectId) { |
| 10204 | windows.add(w); |
| 10205 | } |
| 10206 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10207 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10208 | } |
| 10209 | |
| 10210 | if (windows.size() <= 0) { |
| 10211 | return false; |
| 10212 | } |
| 10213 | |
| 10214 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10215 | dumpWindowsLocked(pw, dumpAll, windows); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10216 | } |
| 10217 | return true; |
| 10218 | } |
| 10219 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10220 | void dumpLastANRLocked(PrintWriter pw) { |
| 10221 | pw.println("WINDOW MANAGER LAST ANR (dumpsys window lastanr)"); |
| 10222 | if (mLastANRState == null) { |
| 10223 | pw.println(" <no ANR has occurred since boot>"); |
| 10224 | } else { |
| 10225 | pw.println(mLastANRState); |
| 10226 | } |
| 10227 | } |
| 10228 | |
| 10229 | /** |
| 10230 | * Saves information about the state of the window manager at |
| 10231 | * the time an ANR occurred before anything else in the system changes |
| 10232 | * in response. |
| 10233 | * |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 10234 | * @param appWindowToken The application that ANR'd, may be null. |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10235 | * @param windowState The window that ANR'd, may be null. |
| 10236 | */ |
| 10237 | public void saveANRStateLocked(AppWindowToken appWindowToken, WindowState windowState) { |
| 10238 | StringWriter sw = new StringWriter(); |
| 10239 | PrintWriter pw = new PrintWriter(sw); |
| 10240 | pw.println(" ANR time: " + DateFormat.getInstance().format(new Date())); |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 10241 | if (appWindowToken != null) { |
| 10242 | pw.println(" Application at fault: " + appWindowToken.stringName); |
| 10243 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10244 | if (windowState != null) { |
| 10245 | pw.println(" Window at fault: " + windowState.mAttrs.getTitle()); |
| 10246 | } |
| 10247 | pw.println(); |
| 10248 | dumpWindowsNoHeaderLocked(pw, true, null); |
| 10249 | pw.close(); |
| 10250 | mLastANRState = sw.toString(); |
| 10251 | } |
| 10252 | |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10253 | @Override |
| 10254 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10255 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10256 | != PackageManager.PERMISSION_GRANTED) { |
| 10257 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10258 | + Binder.getCallingPid() |
| 10259 | + ", uid=" + Binder.getCallingUid()); |
| 10260 | return; |
| 10261 | } |
| 10262 | |
| 10263 | boolean dumpAll = false; |
| 10264 | |
| 10265 | int opti = 0; |
| 10266 | while (opti < args.length) { |
| 10267 | String opt = args[opti]; |
| 10268 | if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') { |
| 10269 | break; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10270 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10271 | opti++; |
| 10272 | if ("-a".equals(opt)) { |
| 10273 | dumpAll = true; |
| 10274 | } else if ("-h".equals(opt)) { |
| 10275 | pw.println("Window manager dump options:"); |
| 10276 | pw.println(" [-a] [-h] [cmd] ..."); |
| 10277 | pw.println(" cmd may be one of:"); |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10278 | pw.println(" l[astanr]: last ANR information"); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10279 | pw.println(" p[policy]: policy state"); |
| 10280 | pw.println(" s[essions]: active sessions"); |
| 10281 | pw.println(" t[okens]: token list"); |
| 10282 | pw.println(" w[indows]: window list"); |
| 10283 | pw.println(" cmd may also be a NAME to dump windows. NAME may"); |
| 10284 | pw.println(" be a partial substring in a window name, a"); |
| 10285 | pw.println(" Window hex object identifier, or"); |
| 10286 | pw.println(" \"all\" for all windows, or"); |
| 10287 | pw.println(" \"visible\" for the visible windows."); |
| 10288 | pw.println(" -a: include all available server state."); |
| 10289 | return; |
Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 10290 | } else { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10291 | pw.println("Unknown argument: " + opt + "; use -h for help"); |
Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 10292 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10293 | } |
| 10294 | |
| 10295 | // Is the caller requesting to dump a particular piece of data? |
| 10296 | if (opti < args.length) { |
| 10297 | String cmd = args[opti]; |
| 10298 | opti++; |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10299 | if ("lastanr".equals(cmd) || "l".equals(cmd)) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10300 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10301 | dumpLastANRLocked(pw); |
| 10302 | } |
| 10303 | return; |
| 10304 | } else if ("policy".equals(cmd) || "p".equals(cmd)) { |
| 10305 | synchronized(mWindowMap) { |
| 10306 | dumpPolicyLocked(pw, args, true); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10307 | } |
| 10308 | return; |
| 10309 | } else if ("sessions".equals(cmd) || "s".equals(cmd)) { |
| 10310 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10311 | dumpSessionsLocked(pw, true); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10312 | } |
| 10313 | return; |
| 10314 | } else if ("tokens".equals(cmd) || "t".equals(cmd)) { |
| 10315 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10316 | dumpTokensLocked(pw, true); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10317 | } |
| 10318 | return; |
| 10319 | } else if ("windows".equals(cmd) || "w".equals(cmd)) { |
| 10320 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10321 | dumpWindowsLocked(pw, true, null); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10322 | } |
| 10323 | return; |
| 10324 | } else if ("all".equals(cmd) || "a".equals(cmd)) { |
| 10325 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10326 | dumpWindowsLocked(pw, true, null); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10327 | } |
| 10328 | return; |
| 10329 | } else { |
| 10330 | // Dumping a single name? |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10331 | if (!dumpWindows(pw, cmd, args, opti, dumpAll)) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10332 | pw.println("Bad window command, or no windows match: " + cmd); |
| 10333 | pw.println("Use -h for help."); |
| 10334 | } |
| 10335 | return; |
| 10336 | } |
| 10337 | } |
| 10338 | |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10339 | synchronized(mWindowMap) { |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 10340 | pw.println(); |
| 10341 | if (dumpAll) { |
| 10342 | pw.println("-------------------------------------------------------------------------------"); |
| 10343 | } |
| 10344 | dumpLastANRLocked(pw); |
| 10345 | pw.println(); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10346 | if (dumpAll) { |
| 10347 | pw.println("-------------------------------------------------------------------------------"); |
| 10348 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10349 | dumpPolicyLocked(pw, args, dumpAll); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10350 | pw.println(); |
| 10351 | if (dumpAll) { |
| 10352 | pw.println("-------------------------------------------------------------------------------"); |
| 10353 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10354 | dumpSessionsLocked(pw, dumpAll); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10355 | pw.println(); |
| 10356 | if (dumpAll) { |
| 10357 | pw.println("-------------------------------------------------------------------------------"); |
| 10358 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10359 | dumpTokensLocked(pw, dumpAll); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10360 | pw.println(); |
| 10361 | if (dumpAll) { |
| 10362 | pw.println("-------------------------------------------------------------------------------"); |
| 10363 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10364 | dumpWindowsLocked(pw, dumpAll, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10365 | } |
| 10366 | } |
| 10367 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10368 | // 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] | 10369 | public void monitor() { |
| 10370 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 10371 | synchronized (mKeyguardTokenWatcher) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10372 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10373 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 10374 | public interface OnHardKeyboardStatusChangeListener { |
| 10375 | public void onHardKeyboardStatusChange(boolean available, boolean enabled); |
| 10376 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 10377 | |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 10378 | void debugLayoutRepeats(final String msg, int pendingLayoutChanges) { |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 10379 | if (mLayoutRepeatCount >= LAYOUT_REPEAT_THRESHOLD) { |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 10380 | Slog.v(TAG, "Layouts looping: " + msg + ", mPendingLayoutChanges = 0x" + |
| 10381 | Integer.toHexString(pendingLayoutChanges)); |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 10382 | } |
| 10383 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10384 | |
| 10385 | public DisplayContent getDisplayContent(final int displayId) { |
| 10386 | DisplayContent displayContent = mDisplayContents.get(displayId); |
| 10387 | if (displayContent == null) { |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 10388 | displayContent = new DisplayContent(mDisplayManager, displayId); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10389 | mDisplayContents.put(displayId, displayContent); |
| 10390 | } |
| 10391 | return displayContent; |
| 10392 | } |
| 10393 | |
| 10394 | class DisplayContentsIterator implements Iterator<DisplayContent> { |
| 10395 | private int cur; |
| 10396 | |
| 10397 | @Override |
| 10398 | public boolean hasNext() { |
| 10399 | return cur < mDisplayContents.size(); |
| 10400 | } |
| 10401 | |
| 10402 | @Override |
| 10403 | public DisplayContent next() { |
| 10404 | if (hasNext()) { |
| 10405 | return mDisplayContents.valueAt(cur++); |
| 10406 | } |
| 10407 | throw new NoSuchElementException(); |
| 10408 | } |
| 10409 | |
| 10410 | @Override |
| 10411 | public void remove() { |
| 10412 | throw new IllegalArgumentException("AllDisplayContentIterator.remove not implemented"); |
| 10413 | } |
| 10414 | } |
| 10415 | |
| 10416 | boolean REVERSE_ITERATOR = true; |
| 10417 | class AllWindowsIterator implements Iterator<WindowState> { |
| 10418 | private DisplayContent mDisplayContent; |
| 10419 | private DisplayContentsIterator mDisplayContentsIterator; |
| 10420 | private WindowList mWindowList; |
| 10421 | private int mWindowListIndex; |
| 10422 | private boolean mReverse; |
| 10423 | |
| 10424 | AllWindowsIterator() { |
| 10425 | mDisplayContentsIterator = new DisplayContentsIterator(); |
| 10426 | mDisplayContent = mDisplayContentsIterator.next(); |
| 10427 | mWindowList = mDisplayContent.getWindowList(); |
| 10428 | } |
| 10429 | |
| 10430 | AllWindowsIterator(boolean reverse) { |
| 10431 | this(); |
| 10432 | mReverse = reverse; |
| 10433 | mWindowListIndex = reverse ? mWindowList.size() - 1 : 0; |
| 10434 | } |
| 10435 | |
| 10436 | @Override |
| 10437 | public boolean hasNext() { |
| 10438 | if (mReverse) { |
| 10439 | return mWindowListIndex >= 0; |
| 10440 | } |
| 10441 | return mWindowListIndex < mWindowList.size(); |
| 10442 | } |
| 10443 | |
| 10444 | @Override |
| 10445 | public WindowState next() { |
| 10446 | if (hasNext()) { |
| 10447 | WindowState win = mWindowList.get(mWindowListIndex); |
| 10448 | if (mReverse) { |
| 10449 | mWindowListIndex--; |
| 10450 | if (mWindowListIndex < 0 && mDisplayContentsIterator.hasNext()) { |
| 10451 | mDisplayContent = mDisplayContentsIterator.next(); |
| 10452 | mWindowList = mDisplayContent.getWindowList(); |
| 10453 | mWindowListIndex = mWindowList.size() - 1; |
| 10454 | } |
| 10455 | } else { |
| 10456 | mWindowListIndex++; |
| 10457 | if (mWindowListIndex >= mWindowList.size() && mDisplayContentsIterator.hasNext()) { |
| 10458 | mDisplayContent = mDisplayContentsIterator.next(); |
| 10459 | mWindowList = mDisplayContent.getWindowList(); |
| 10460 | mWindowListIndex = 0; |
| 10461 | } |
| 10462 | } |
| 10463 | return win; |
| 10464 | } |
| 10465 | throw new NoSuchElementException(); |
| 10466 | } |
| 10467 | |
| 10468 | @Override |
| 10469 | public void remove() { |
| 10470 | throw new IllegalArgumentException("AllWindowsIterator.remove not implemented"); |
| 10471 | } |
| 10472 | } |
| 10473 | |
| 10474 | public DisplayContent getDefaultDisplayContent() { |
| 10475 | return getDisplayContent(Display.DEFAULT_DISPLAY); |
| 10476 | } |
| 10477 | |
| 10478 | public WindowList getDefaultWindowList() { |
| 10479 | return getDefaultDisplayContent().getWindowList(); |
| 10480 | } |
| 10481 | |
| 10482 | public DisplayInfo getDefaultDisplayInfo() { |
| 10483 | return getDefaultDisplayContent().getDisplayInfo(); |
| 10484 | } |
| 10485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10486 | } |