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 | |
Craig Mautner | 9e4f28c | 2013-04-03 10:53:23 -0700 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.*; |
| 20 | |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 21 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 22 | import android.app.AppOpsManager; |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 23 | import android.util.ArraySet; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 24 | import android.util.TimeUtils; |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 25 | import android.view.IWindowId; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 26 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import com.android.internal.app.IBatteryStats; |
| 28 | import com.android.internal.policy.PolicyManager; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 29 | import com.android.internal.policy.impl.PhoneWindowManager; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 30 | import com.android.internal.util.FastPrintWriter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import com.android.internal.view.IInputContext; |
| 32 | import com.android.internal.view.IInputMethodClient; |
| 33 | import com.android.internal.view.IInputMethodManager; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 34 | import com.android.internal.view.WindowManagerPolicyThread; |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 35 | import com.android.server.AttributeCache; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 36 | import com.android.server.DisplayThread; |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 37 | import com.android.server.EventLogTags; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 38 | import com.android.server.LocalServices; |
Dianne Hackborn | 8d044e8 | 2013-04-30 17:24:15 -0700 | [diff] [blame] | 39 | import com.android.server.UiThread; |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 40 | import com.android.server.Watchdog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import com.android.server.am.BatteryStatsService; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 42 | import com.android.server.input.InputManagerService; |
Jeff Brown | 4f8ecd8 | 2012-06-18 18:29:13 -0700 | [diff] [blame] | 43 | import com.android.server.power.ShutdownThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
| 45 | import android.Manifest; |
| 46 | import android.app.ActivityManagerNative; |
| 47 | import android.app.IActivityManager; |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 48 | import android.app.StatusBarManager; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 49 | import android.app.admin.DevicePolicyManager; |
Jeff Brown | ff7e6ef | 2012-08-15 02:05:18 -0700 | [diff] [blame] | 50 | import android.animation.ValueAnimator; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 51 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.content.Context; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 53 | import android.content.Intent; |
| 54 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.content.pm.ActivityInfo; |
| 56 | import android.content.pm.PackageManager; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 57 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.content.res.Configuration; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 59 | import android.graphics.Bitmap; |
John Reck | 172e87c | 2013-10-02 16:55:16 -0700 | [diff] [blame] | 60 | import android.graphics.Bitmap.Config; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 61 | import android.graphics.Canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.graphics.Matrix; |
| 63 | import android.graphics.PixelFormat; |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 64 | import android.graphics.Point; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.graphics.Rect; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 66 | import android.graphics.RectF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.graphics.Region; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 68 | import android.hardware.display.DisplayManager; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 69 | import android.hardware.display.DisplayManagerInternal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import android.os.Binder; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 71 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.os.Debug; |
| 73 | import android.os.Handler; |
| 74 | import android.os.IBinder; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 75 | import android.os.IRemoteCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | import android.os.Looper; |
| 77 | import android.os.Message; |
| 78 | import android.os.Parcel; |
| 79 | import android.os.ParcelFileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | import android.os.PowerManager; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 81 | import android.os.PowerManagerInternal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import android.os.Process; |
| 83 | import android.os.RemoteException; |
| 84 | import android.os.ServiceManager; |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 85 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import android.os.SystemClock; |
| 87 | import android.os.SystemProperties; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 88 | import android.os.Trace; |
Craig Mautner | 259328c | 2012-08-21 19:30:58 -0700 | [diff] [blame] | 89 | import android.os.WorkSource; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | import android.provider.Settings; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 91 | import android.util.DisplayMetrics; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | import android.util.EventLog; |
Michael Jurka | 4accb6a | 2012-03-26 09:18:46 -0700 | [diff] [blame] | 93 | import android.util.FloatMath; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 94 | import android.util.Log; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 95 | import android.util.SparseArray; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 96 | import android.util.Pair; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 97 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | import android.util.SparseIntArray; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 99 | import android.util.TypedValue; |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 100 | import android.view.Choreographer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | import android.view.Display; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 102 | import android.view.DisplayInfo; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 103 | import android.view.Gravity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | import android.view.IApplicationToken; |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 105 | import android.view.IInputFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | import android.view.IOnKeyguardExitResult; |
| 107 | import android.view.IRotationWatcher; |
| 108 | import android.view.IWindow; |
| 109 | import android.view.IWindowManager; |
| 110 | import android.view.IWindowSession; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 111 | import android.view.InputChannel; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 112 | import android.view.InputDevice; |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 113 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 114 | import android.view.InputEventReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | import android.view.KeyEvent; |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 116 | import android.view.MagnificationSpec; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | import android.view.MotionEvent; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 118 | import android.view.WindowManagerInternal; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 119 | import android.view.Surface.OutOfResourcesException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | import android.view.Surface; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 121 | import android.view.SurfaceControl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | import android.view.SurfaceSession; |
| 123 | import android.view.View; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 124 | import android.view.ViewTreeObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 126 | import android.view.WindowManagerGlobal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | import android.view.WindowManagerPolicy; |
| 128 | import android.view.WindowManager.LayoutParams; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 129 | import android.view.WindowManagerPolicy.FakeWindow; |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 130 | import android.view.WindowManagerPolicy.PointerEventListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | import android.view.animation.Animation; |
| 132 | import android.view.animation.AnimationUtils; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 133 | import android.view.animation.Transformation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | |
| 135 | import java.io.BufferedWriter; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 136 | import java.io.DataInputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | import java.io.File; |
| 138 | import java.io.FileDescriptor; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 139 | import java.io.FileInputStream; |
| 140 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | import java.io.IOException; |
| 142 | import java.io.OutputStream; |
| 143 | import java.io.OutputStreamWriter; |
| 144 | import java.io.PrintWriter; |
| 145 | import java.io.StringWriter; |
| 146 | import java.net.Socket; |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 147 | import java.text.DateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | import java.util.ArrayList; |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 149 | import java.util.Date; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | import java.util.HashMap; |
| 151 | import java.util.HashSet; |
| 152 | import java.util.Iterator; |
| 153 | import java.util.List; |
| 154 | |
| 155 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 156 | public class WindowManagerService extends IWindowManager.Stub |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 157 | implements Watchdog.Monitor, WindowManagerPolicy.WindowManagerFuncs { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | static final String TAG = "WindowManager"; |
| 159 | static final boolean DEBUG = false; |
Craig Mautner | ac56514 | 2013-09-23 17:37:09 -0700 | [diff] [blame] | 160 | static final boolean DEBUG_ADD_REMOVE = false; |
Craig Mautner | 343511c | 2012-02-28 17:30:50 -0800 | [diff] [blame] | 161 | static final boolean DEBUG_FOCUS = false; |
Craig Mautner | b3370ce | 2013-09-19 12:02:09 -0700 | [diff] [blame] | 162 | static final boolean DEBUG_FOCUS_LIGHT = DEBUG_FOCUS || false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | static final boolean DEBUG_ANIM = false; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 164 | static final boolean DEBUG_LAYOUT = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 165 | static final boolean DEBUG_RESIZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | static final boolean DEBUG_LAYERS = false; |
| 167 | static final boolean DEBUG_INPUT = false; |
| 168 | static final boolean DEBUG_INPUT_METHOD = false; |
| 169 | static final boolean DEBUG_VISIBILITY = false; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 170 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 171 | static final boolean DEBUG_TOKEN_MOVEMENT = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | static final boolean DEBUG_ORIENTATION = false; |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 173 | static final boolean DEBUG_APP_ORIENTATION = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 174 | static final boolean DEBUG_CONFIGURATION = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 176 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 177 | static final boolean DEBUG_REORDER = false; |
Craig Mautner | 343511c | 2012-02-28 17:30:50 -0800 | [diff] [blame] | 178 | static final boolean DEBUG_WALLPAPER = false; |
Dianne Hackborn | 9812973 | 2012-11-01 16:28:16 -0700 | [diff] [blame] | 179 | static final boolean DEBUG_WALLPAPER_LIGHT = false || DEBUG_WALLPAPER; |
Christopher Tate | 994ef92 | 2011-01-12 20:06:07 -0800 | [diff] [blame] | 180 | static final boolean DEBUG_DRAG = false; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 181 | static final boolean DEBUG_SCREEN_ON = false; |
Dianne Hackborn | cfb9f2b | 2011-08-24 10:51:49 -0700 | [diff] [blame] | 182 | static final boolean DEBUG_SCREENSHOT = false; |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 183 | static final boolean DEBUG_BOOT = false; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 184 | static final boolean DEBUG_LAYOUT_REPEATS = true; |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 185 | static final boolean DEBUG_SURFACE_TRACE = false; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 186 | static final boolean DEBUG_WINDOW_TRACE = false; |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 187 | static final boolean DEBUG_TASK_MOVEMENT = false; |
Craig Mautner | 5800443 | 2013-10-14 12:58:42 -0700 | [diff] [blame] | 188 | static final boolean DEBUG_STACK = false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 189 | static final boolean DEBUG_DISPLAY = false; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 190 | static final boolean SHOW_SURFACE_ALLOC = false; |
Craig Mautner | 343511c | 2012-02-28 17:30:50 -0800 | [diff] [blame] | 191 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 192 | static final boolean SHOW_LIGHT_TRANSACTIONS = false || SHOW_TRANSACTIONS; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 193 | static final boolean HIDE_STACK_CRAWLS = true; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 194 | static final int LAYOUT_REPEAT_THRESHOLD = 4; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | static final boolean PROFILE_ORIENTATION = false; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 197 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | /** How much to multiply the policy's type layer, to reserve room |
| 200 | * for multiple windows of the same type and Z-ordering adjustment |
| 201 | * with TYPE_LAYER_OFFSET. */ |
| 202 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 205 | * or below others in the same layer. */ |
| 206 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | /** How much to increment the layer for each window, to reserve room |
| 209 | * for effect surfaces between them. |
| 210 | */ |
| 211 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 212 | |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 213 | /** |
| 214 | * Dim surface layer is immediately below target window. |
| 215 | */ |
| 216 | static final int LAYER_OFFSET_DIM = 1; |
| 217 | |
| 218 | /** |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 219 | * Blur surface layer is immediately below dim layer. |
| 220 | */ |
| 221 | static final int LAYER_OFFSET_BLUR = 2; |
| 222 | |
| 223 | /** |
Craig Mautner | f766646 | 2013-04-28 08:58:21 -0700 | [diff] [blame] | 224 | * FocusedStackFrame layer is immediately above focused window. |
| 225 | */ |
| 226 | static final int LAYER_OFFSET_FOCUSED_STACK = 1; |
| 227 | |
| 228 | /** |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 229 | * Animation thumbnail is as far as possible below the window above |
| 230 | * the thumbnail (or in other words as far as possible above the window |
| 231 | * below it). |
| 232 | */ |
| 233 | static final int LAYER_OFFSET_THUMBNAIL = WINDOW_LAYER_MULTIPLIER-1; |
| 234 | |
| 235 | /** |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 236 | * Layer at which to put the rotation freeze snapshot. |
| 237 | */ |
| 238 | static final int FREEZE_LAYER = (TYPE_LAYER_MULTIPLIER * 200) + 1; |
| 239 | |
| 240 | /** |
| 241 | * Layer at which to put the mask for emulated screen sizes. |
| 242 | */ |
| 243 | static final int MASK_LAYER = TYPE_LAYER_MULTIPLIER * 200; |
| 244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | /** The maximum length we will accept for a loaded animation duration: |
| 246 | * this is 10 seconds. |
| 247 | */ |
| 248 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 249 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 250 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 251 | * compatible windows. |
| 252 | */ |
| 253 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 254 | |
Craig Mautner | 7dfcb01 | 2012-10-10 10:24:47 -0700 | [diff] [blame] | 255 | /** Amount of time (in milliseconds) to delay before declaring a window freeze timeout. */ |
Craig Mautner | a4942c9 | 2012-10-16 09:06:53 -0700 | [diff] [blame] | 256 | static final int WINDOW_FREEZE_TIMEOUT_DURATION = 2000; |
Craig Mautner | 7dfcb01 | 2012-10-10 10:24:47 -0700 | [diff] [blame] | 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 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 271 | /** Minimum value for attachStack and resizeStack weight value */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 272 | public static final float STACK_WEIGHT_MIN = 0.2f; |
| 273 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 274 | /** Maximum value for attachStack and resizeStack weight value */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 275 | public static final float STACK_WEIGHT_MAX = 0.8f; |
| 276 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 278 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 279 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 280 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 281 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 283 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | |
Colin Cross | ef96fd9 | 2013-07-18 17:09:56 -0700 | [diff] [blame] | 285 | private static final String DENSITY_OVERRIDE = "ro.config.density_override"; |
| 286 | private static final String SIZE_OVERRIDE = "ro.config.size_override"; |
| 287 | |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 288 | private static final int MAX_SCREENSHOT_RETRIES = 3; |
| 289 | |
Craig Mautner | 5642a48 | 2012-08-23 12:16:53 -0700 | [diff] [blame] | 290 | final private KeyguardDisableHandler mKeyguardDisableHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 292 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 293 | @Override |
| 294 | public void onReceive(Context context, Intent intent) { |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 295 | final String action = intent.getAction(); |
| 296 | if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals(action)) { |
Craig Mautner | 5642a48 | 2012-08-23 12:16:53 -0700 | [diff] [blame] | 297 | mKeyguardDisableHandler.sendEmptyMessage( |
| 298 | KeyguardDisableHandler.KEYGUARD_POLICY_CHANGED); |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | }; |
| 302 | |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 303 | /** |
| 304 | * Current user when multi-user is enabled. Don't show windows of |
| 305 | * non-current user. Also see mRelatedUserIds. |
| 306 | */ |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 307 | int mCurrentUserId; |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 308 | /** |
| 309 | * Users related to the current user. These are also allowed to show windows |
| 310 | * on the current user. |
| 311 | */ |
| 312 | int[] mRelatedUserIds = new int[0]; |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 313 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | final Context mContext; |
| 315 | |
| 316 | final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 317 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 318 | final boolean mAllowBootMessages; |
| 319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | final boolean mLimitedAlphaCompositing; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 323 | |
| 324 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 327 | |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 328 | final AppOpsManager mAppOps; |
| 329 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 330 | final DisplaySettings mDisplaySettings; |
| 331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | /** |
| 333 | * All currently active sessions with clients. |
| 334 | */ |
| 335 | final HashSet<Session> mSessions = new HashSet<Session>(); |
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 | /** |
| 338 | * Mapping from an IWindow IBinder to the server's Window object. |
| 339 | * This is also used as the lock for all of our state. |
Craig Mautner | 5810681 | 2012-12-28 12:27:40 -0800 | [diff] [blame] | 340 | * NOTE: Never call into methods that lock ActivityManagerService while holding this object. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | */ |
| 342 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 343 | |
| 344 | /** |
| 345 | * Mapping from a token IBinder to a WindowToken object. |
| 346 | */ |
Craig Mautner | 05d6272 | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 347 | final HashMap<IBinder, WindowToken> mTokenMap = new HashMap<IBinder, WindowToken>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | |
| 349 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | * List of window tokens that have finished starting their application, |
| 351 | * and now need to have the policy remove their windows. |
| 352 | */ |
| 353 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 354 | |
| 355 | /** |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 356 | * Fake windows added to the window manager. Note: ordered from top to |
| 357 | * bottom, opposite of mWindows. |
| 358 | */ |
| 359 | final ArrayList<FakeWindowImpl> mFakeWindows = new ArrayList<FakeWindowImpl>(); |
| 360 | |
| 361 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | * Windows that are being resized. Used so we can tell the client about |
| 363 | * the resize after closing the transaction in which we resized the |
| 364 | * underlying surface. |
| 365 | */ |
| 366 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 367 | |
| 368 | /** |
| 369 | * Windows whose animations have ended and now must be removed. |
| 370 | */ |
| 371 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 372 | |
| 373 | /** |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 374 | * Stacks whose animations have ended and whose tasks, apps, selves may now be removed. |
| 375 | */ |
| 376 | final ArraySet<TaskStack> mPendingStacksRemove = new ArraySet<TaskStack>(); |
| 377 | |
| 378 | /** |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 379 | * Used when processing mPendingRemove to avoid working on the original array. |
| 380 | */ |
| 381 | WindowState[] mPendingRemoveTmp = new WindowState[20]; |
| 382 | |
| 383 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | * Windows whose surface should be destroyed. |
| 385 | */ |
| 386 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 387 | |
| 388 | /** |
| 389 | * Windows that have lost input focus and are waiting for the new |
| 390 | * focus window to be displayed before they are told about this. |
| 391 | */ |
| 392 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 393 | |
| 394 | /** |
| 395 | * This is set when we have run out of memory, and will either be an empty |
| 396 | * list or contain windows that need to be force removed. |
| 397 | */ |
| 398 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 399 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 400 | /** |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 401 | * Windows that clients are waiting to have drawn. |
| 402 | */ |
| 403 | ArrayList<Pair<WindowState, IRemoteCallback>> mWaitingForDrawn |
| 404 | = new ArrayList<Pair<WindowState, IRemoteCallback>>(); |
| 405 | |
| 406 | /** |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 407 | * Windows that have called relayout() while we were running animations, |
| 408 | * so we need to tell when the animation is done. |
| 409 | */ |
| 410 | final ArrayList<WindowState> mRelayoutWhileAnimating = new ArrayList<WindowState>(); |
| 411 | |
| 412 | /** |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 413 | * Used when rebuilding window list to keep track of windows that have |
| 414 | * been removed. |
| 415 | */ |
| 416 | WindowState[] mRebuildTmp = new WindowState[20]; |
| 417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 419 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 420 | AccessibilityController mAccessibilityController; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 421 | |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 422 | final SurfaceSession mFxSession; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 423 | Watermark mWatermark; |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 424 | StrictModeFlash mStrictModeFlash; |
Craig Mautner | a9a3fb1 | 2013-04-18 10:01:00 -0700 | [diff] [blame] | 425 | FocusedStackFrame mFocusedStackFrame; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 426 | |
Craig Mautner | f766646 | 2013-04-28 08:58:21 -0700 | [diff] [blame] | 427 | int mFocusedStackLayer; |
| 428 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | final float[] mTmpFloats = new float[9]; |
John Spurlock | 4e92a7c | 2013-09-24 17:09:05 -0400 | [diff] [blame] | 430 | final Rect mTmpContentRect = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 432 | boolean mDisplayReady; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | boolean mSafeMode; |
| 434 | boolean mDisplayEnabled = false; |
| 435 | boolean mSystemBooted = false; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 436 | boolean mForceDisplayEnabled = false; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 437 | boolean mShowingBootMessages = false; |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 438 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 439 | String mLastANRState; |
| 440 | |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 441 | /** All DisplayContents in the world, kept here */ |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 442 | SparseArray<DisplayContent> mDisplayContents = new SparseArray<DisplayContent>(2); |
Craig Mautner | 343ad71 | 2013-02-13 22:37:26 -0800 | [diff] [blame] | 443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | int mRotation = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 446 | boolean mAltOrientation = false; |
Jim Miller | 7267ed1 | 2013-12-09 17:38:05 -0800 | [diff] [blame] | 447 | class RotationWatcher { |
| 448 | IRotationWatcher watcher; |
| 449 | IBinder.DeathRecipient deathRecipient; |
| 450 | RotationWatcher(IRotationWatcher w, IBinder.DeathRecipient d) { |
| 451 | watcher = w; |
| 452 | deathRecipient = d; |
| 453 | } |
| 454 | } |
| 455 | ArrayList<RotationWatcher> mRotationWatchers = new ArrayList<RotationWatcher>(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 456 | int mDeferredRotationPauseCount; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 457 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 458 | int mSystemDecorLayer = 0; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 459 | final Rect mScreenRect = new Rect(); |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 460 | |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 461 | boolean mTraversalScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | boolean mDisplayFrozen = false; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 463 | long mDisplayFreezeTime = 0; |
| 464 | int mLastDisplayFreezeDuration = 0; |
| 465 | Object mLastFinishedFreezeSource = null; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 466 | boolean mWaitingForConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | boolean mWindowsFreezingScreen = false; |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 468 | boolean mClientFreezingScreen = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | int mAppsFreezingScreen = 0; |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 470 | int mLastWindowForcedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 472 | int mLayoutSeq = 0; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 473 | |
| 474 | int mLastStatusBarVisibility = 0; |
| 475 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 476 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 477 | boolean mFocusMayChange; |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 478 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 479 | Configuration mCurConfiguration = new Configuration(); |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | // This is held as long as we have the screen frozen, to give us time to |
| 482 | // perform a rotation animation when turning off shows the lock screen which |
| 483 | // changes the orientation. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 484 | private final PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 485 | |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 486 | final AppTransition mAppTransition; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | boolean mStartingIconInTransition = false; |
| 488 | boolean mSkipAppTransitionAnimation = false; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 491 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 492 | |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 493 | boolean mIsTouchDevice; |
| 494 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 495 | final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 496 | final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics(); |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 497 | final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics(); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 498 | final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics(); |
| 499 | |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 500 | final H mH = new H(); |
| 501 | |
| 502 | final Choreographer mChoreographer = Choreographer.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | |
| 504 | WindowState mCurrentFocus = null; |
| 505 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 506 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 507 | /** This just indicates the window the input method is on top of, not |
| 508 | * necessarily the window its input is going to. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | WindowState mInputMethodTarget = null; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 510 | |
| 511 | /** 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] | 512 | boolean mInputMethodTargetWaitingAnim; |
| 513 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | WindowState mInputMethodWindow = null; |
| 516 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 517 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 518 | boolean mHardKeyboardAvailable; |
| 519 | boolean mHardKeyboardEnabled; |
| 520 | OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener; |
| 521 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 522 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 523 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 524 | // If non-null, this is the currently visible window that is associated |
| 525 | // with the wallpaper. |
| 526 | WindowState mWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 527 | // If non-null, we are in the middle of animating from one wallpaper target |
| 528 | // to another, and this is the lower one in Z-order. |
Dianne Hackborn | 9812973 | 2012-11-01 16:28:16 -0700 | [diff] [blame] | 529 | WindowState mLowerWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 530 | // If non-null, we are in the middle of animating from one wallpaper target |
| 531 | // to another, and this is the higher one in Z-order. |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 532 | WindowState mUpperWallpaperTarget = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 533 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 534 | float mLastWallpaperX = -1; |
| 535 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 536 | float mLastWallpaperXStep = -1; |
| 537 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 538 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 539 | // changing its scroll position. |
| 540 | WindowState mWaitingOnWallpaper; |
| 541 | // The last time we had a timeout when waiting for a wallpaper. |
| 542 | long mLastWallpaperTimeoutTime; |
| 543 | // We give a wallpaper up to 150ms to finish scrolling. |
| 544 | static final long WALLPAPER_TIMEOUT = 150; |
| 545 | // Time we wait after a timeout before trying to wait again. |
| 546 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Craig Mautner | 798adef | 2013-10-22 14:29:01 -0700 | [diff] [blame] | 547 | boolean mAnimateWallpaperWithTarget; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 549 | AppWindowToken mFocusedApp = null; |
| 550 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 551 | PowerManager mPowerManager; |
| 552 | PowerManagerInternal mPowerManagerInternal; |
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 | float mWindowAnimationScale = 1.0f; |
| 555 | float mTransitionAnimationScale = 1.0f; |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 556 | float mAnimatorDurationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 557 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 558 | final InputManagerService mInputManager; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 559 | final DisplayManagerInternal mDisplayManagerInternal; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 560 | final DisplayManager mDisplayManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | |
| 562 | // Who is holding the screen on. |
| 563 | Session mHoldingScreenOn; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 564 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 565 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 566 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 567 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 568 | DragState mDragState = null; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 569 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 570 | // For frozen screen animations. |
| 571 | int mExitAnimId, mEnterAnimId; |
| 572 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 573 | /** Pulled out of performLayoutAndPlaceSurfacesLockedInner in order to refactor into multiple |
| 574 | * methods. */ |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 575 | class LayoutFields { |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 576 | static final int SET_UPDATE_ROTATION = 1 << 0; |
| 577 | static final int SET_WALLPAPER_MAY_CHANGE = 1 << 1; |
| 578 | static final int SET_FORCE_HIDING_CHANGED = 1 << 2; |
Craig Mautner | 2639da5 | 2012-07-09 09:39:06 -0700 | [diff] [blame] | 579 | static final int SET_ORIENTATION_CHANGE_COMPLETE = 1 << 3; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 580 | static final int SET_TURN_ON_SCREEN = 1 << 4; |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 581 | static final int SET_WALLPAPER_ACTION_PENDING = 1 << 5; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 582 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 583 | boolean mWallpaperForceHidingChanged = false; |
| 584 | boolean mWallpaperMayChange = false; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 585 | boolean mOrientationChangeComplete = true; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 586 | Object mLastWindowFreezeSource = null; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 587 | private Session mHoldScreen = null; |
| 588 | private boolean mObscured = false; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 589 | private boolean mSyswin = false; |
| 590 | private float mScreenBrightness = -1; |
| 591 | private float mButtonBrightness = -1; |
Jeff Brown | 1e3b98d | 2012-09-30 18:58:59 -0700 | [diff] [blame] | 592 | private long mUserActivityTimeout = -1; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 593 | private boolean mUpdateRotation = false; |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 594 | boolean mWallpaperActionPending = false; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 595 | |
Jeff Brown | 4fd7917 | 2013-11-07 17:58:15 -0800 | [diff] [blame] | 596 | // Set to true when the display contains content to show the user. |
| 597 | // When false, the display manager may choose to mirror or blank the display. |
| 598 | boolean mDisplayHasContent = false; |
| 599 | |
| 600 | // Only set while traversing the default display based on its content. |
| 601 | // Affects the behavior of mirroring on secondary displays. |
| 602 | boolean mObscureApplicationContentOnSecondaryDisplays = false; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 603 | } |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 604 | final LayoutFields mInnerFields = new LayoutFields(); |
| 605 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 606 | boolean mAnimationScheduled; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 607 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 608 | /** Skip repeated AppWindowTokens initialization. Note that AppWindowsToken's version of this |
| 609 | * is a long initialized to Long.MIN_VALUE so that it doesn't match this value on startup. */ |
| 610 | private int mTransactionSequence; |
| 611 | |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 612 | /** Only do a maximum of 6 repeated layouts. After that quit */ |
| 613 | private int mLayoutRepeatCount; |
| 614 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 615 | final WindowAnimator mAnimator; |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 616 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 617 | SparseArray<Task> mTaskIdToTask = new SparseArray<Task>(); |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 618 | |
| 619 | /** All of the TaskStacks in the window manager, unordered. For an ordered list call |
| 620 | * DisplayContent.getStacks(). */ |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 621 | SparseArray<TaskStack> mStackIdToStack = new SparseArray<TaskStack>(); |
| 622 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 623 | private final PointerEventDispatcher mPointerEventDispatcher; |
| 624 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 625 | final class DragInputEventReceiver extends InputEventReceiver { |
| 626 | public DragInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 627 | super(inputChannel, looper); |
| 628 | } |
| 629 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 630 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 631 | public void onInputEvent(InputEvent event) { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 632 | boolean handled = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 633 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 634 | if (event instanceof MotionEvent |
| 635 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 636 | && mDragState != null) { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 637 | final MotionEvent motionEvent = (MotionEvent)event; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 638 | boolean endDrag = false; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 639 | final float newX = motionEvent.getRawX(); |
| 640 | final float newY = motionEvent.getRawY(); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 641 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 642 | switch (motionEvent.getAction()) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 643 | case MotionEvent.ACTION_DOWN: { |
| 644 | if (DEBUG_DRAG) { |
| 645 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 646 | } |
| 647 | } break; |
| 648 | |
| 649 | case MotionEvent.ACTION_MOVE: { |
| 650 | synchronized (mWindowMap) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 651 | // move the surface and tell the involved window(s) where we are |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 652 | mDragState.notifyMoveLw(newX, newY); |
| 653 | } |
| 654 | } break; |
| 655 | |
| 656 | case MotionEvent.ACTION_UP: { |
| 657 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 658 | + newX + "," + newY); |
| 659 | synchronized (mWindowMap) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 660 | endDrag = mDragState.notifyDropLw(newX, newY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 661 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 662 | } break; |
| 663 | |
| 664 | case MotionEvent.ACTION_CANCEL: { |
| 665 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 666 | endDrag = true; |
| 667 | } break; |
| 668 | } |
| 669 | |
| 670 | if (endDrag) { |
| 671 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 672 | // tell all the windows that the drag has ended |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 673 | synchronized (mWindowMap) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 674 | mDragState.endDragLw(); |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 675 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 676 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 677 | |
| 678 | handled = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 679 | } |
| 680 | } catch (Exception e) { |
| 681 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 682 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 683 | finishInputEvent(event, handled); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 684 | } |
| 685 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 686 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 687 | |
| 688 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 689 | * Whether the UI is currently running in touch mode (not showing |
| 690 | * navigational focus because the user is directly pressing the screen). |
| 691 | */ |
Michael Jurka | e99adc7 | 2011-08-11 18:28:01 -0700 | [diff] [blame] | 692 | boolean mInTouchMode = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 693 | |
| 694 | private ViewServer mViewServer; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 695 | private final ArrayList<WindowChangeListener> mWindowChangeListeners = |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 696 | new ArrayList<WindowChangeListener>(); |
| 697 | private boolean mWindowsChanged = false; |
| 698 | |
| 699 | public interface WindowChangeListener { |
| 700 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 701 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 702 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 704 | final Configuration mTempConfiguration = new Configuration(); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 705 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 706 | // The desired scaling factor for compatible apps. |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 707 | float mCompatibleScreenScale; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 708 | |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 709 | // If true, only the core apps and services are being launched because the device |
| 710 | // is in a special boot mode, such as being encrypted or waiting for a decryption password. |
| 711 | // For example, when this flag is true, there will be no wallpaper service. |
| 712 | final boolean mOnlyCore; |
| 713 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 714 | public static WindowManagerService main(final Context context, |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 715 | final InputManagerService im, |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 716 | final boolean haveInputMethods, final boolean showBootMsgs, |
| 717 | final boolean onlyCore) { |
| 718 | final WindowManagerService[] holder = new WindowManagerService[1]; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 719 | DisplayThread.getHandler().runWithScissors(new Runnable() { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 720 | @Override |
| 721 | public void run() { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 722 | holder[0] = new WindowManagerService(context, im, |
Dianne Hackborn | 8d044e8 | 2013-04-30 17:24:15 -0700 | [diff] [blame] | 723 | haveInputMethods, showBootMsgs, onlyCore); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 724 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 725 | }, 0); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 726 | return holder[0]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 727 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 728 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 729 | private void initPolicy() { |
| 730 | UiThread.getHandler().runWithScissors(new Runnable() { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 731 | @Override |
| 732 | public void run() { |
| 733 | WindowManagerPolicyThread.set(Thread.currentThread(), Looper.myLooper()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 734 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 735 | mPolicy.init(mContext, WindowManagerService.this, WindowManagerService.this); |
| 736 | mAnimator.mAboveUniverseLayer = mPolicy.getAboveUniverseLayer() |
| 737 | * TYPE_LAYER_MULTIPLIER |
| 738 | + TYPE_LAYER_OFFSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 740 | }, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | } |
| 742 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 743 | private WindowManagerService(Context context, InputManagerService inputManager, |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 744 | boolean haveInputMethods, boolean showBootMsgs, boolean onlyCore) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | mContext = context; |
| 746 | mHaveInputMethods = haveInputMethods; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 747 | mAllowBootMessages = showBootMsgs; |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 748 | mOnlyCore = onlyCore; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 750 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 751 | mInputManager = inputManager; // Must be before createDisplayContentLocked. |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 752 | mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 753 | mDisplaySettings = new DisplaySettings(context); |
| 754 | mDisplaySettings.readSettingsLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 755 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 756 | mPointerEventDispatcher = new PointerEventDispatcher(mInputManager.monitorInput(TAG)); |
| 757 | |
Craig Mautner | dee8bf0 | 2013-08-07 09:24:11 -0700 | [diff] [blame] | 758 | mFxSession = new SurfaceSession(); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 759 | mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 760 | Display[] displays = mDisplayManager.getDisplays(); |
| 761 | for (Display display : displays) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 762 | createDisplayContentLocked(display); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Craig Mautner | 5642a48 | 2012-08-23 12:16:53 -0700 | [diff] [blame] | 765 | mKeyguardDisableHandler = new KeyguardDisableHandler(mContext, mPolicy); |
| 766 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 767 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 768 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
| 769 | mPowerManagerInternal.setPolicy(mPolicy); // TODO: register as local service instead |
| 770 | mScreenFrozenLock = mPowerManager.newWakeLock( |
| 771 | PowerManager.PARTIAL_WAKE_LOCK, "SCREEN_FROZEN"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | mScreenFrozenLock.setReferenceCounted(false); |
| 773 | |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 774 | mAppTransition = new AppTransition(context, mH); |
| 775 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 776 | mActivityManager = ActivityManagerNative.getDefault(); |
| 777 | mBatteryStats = BatteryStatsService.getService(); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 778 | mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE); |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 779 | mAppOps.startWatchingMode(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, null, |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 780 | new AppOpsManager.OnOpChangedInternalListener() { |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 781 | @Override |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 782 | public void onOpChanged(int op, String packageName) { |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 783 | updateAppOpsState(); |
| 784 | } |
| 785 | } |
| 786 | ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | |
| 788 | // Get persisted window scale setting |
Jeff Sharkey | 6e2bee7 | 2012-10-01 13:39:08 -0700 | [diff] [blame] | 789 | mWindowAnimationScale = Settings.Global.getFloat(context.getContentResolver(), |
| 790 | Settings.Global.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 791 | mTransitionAnimationScale = Settings.Global.getFloat(context.getContentResolver(), |
| 792 | Settings.Global.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 793 | setAnimatorDurationScale(Settings.Global.getFloat(context.getContentResolver(), |
Craig Mautner | a7233fe | 2012-11-15 14:25:14 -0800 | [diff] [blame] | 794 | Settings.Global.ANIMATOR_DURATION_SCALE, mAnimatorDurationScale)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 795 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 796 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 797 | IntentFilter filter = new IntentFilter(); |
| 798 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 799 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 800 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 801 | mHoldingScreenWakeLock = mPowerManager.newWakeLock( |
| 802 | PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 803 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 804 | |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 805 | mAnimator = new WindowAnimator(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 806 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 807 | initPolicy(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 808 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | // Add ourself to the Watchdog monitors. |
| 810 | Watchdog.getInstance().addMonitor(this); |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 811 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 812 | SurfaceControl.openTransaction(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 813 | try { |
| 814 | createWatermarkInTransaction(); |
Craig Mautner | a9a3fb1 | 2013-04-18 10:01:00 -0700 | [diff] [blame] | 815 | mFocusedStackFrame = new FocusedStackFrame( |
| 816 | getDefaultDisplayContentLocked().getDisplay(), mFxSession); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 817 | } finally { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 818 | SurfaceControl.closeTransaction(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 819 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 820 | |
| 821 | LocalServices.addService(WindowManagerInternal.class, new LocalService()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 822 | } |
| 823 | |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 824 | public InputMonitor getInputMonitor() { |
| 825 | return mInputMonitor; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 826 | } |
| 827 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | @Override |
| 829 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 830 | throws RemoteException { |
| 831 | try { |
| 832 | return super.onTransact(code, data, reply, flags); |
| 833 | } catch (RuntimeException e) { |
| 834 | // The window manager only throws security exceptions, so let's |
| 835 | // log all others. |
| 836 | if (!(e instanceof SecurityException)) { |
Dianne Hackborn | 164371f | 2013-10-01 19:10:13 -0700 | [diff] [blame] | 837 | Slog.wtf(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 838 | } |
| 839 | throw e; |
| 840 | } |
| 841 | } |
| 842 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 843 | private void placeWindowAfter(WindowState pos, WindowState window) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 844 | final WindowList windows = pos.getWindowList(); |
| 845 | final int i = windows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 846 | 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] | 847 | TAG, "Adding window " + window + " at " |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 848 | + (i+1) + " of " + windows.size() + " (after " + pos + ")"); |
| 849 | windows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 850 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 851 | } |
| 852 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 853 | private void placeWindowBefore(WindowState pos, WindowState window) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 854 | final WindowList windows = pos.getWindowList(); |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 855 | int i = windows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 856 | 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] | 857 | TAG, "Adding window " + window + " at " |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 858 | + i + " of " + windows.size() + " (before " + pos + ")"); |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 859 | if (i < 0) { |
| 860 | Slog.w(TAG, "placeWindowBefore: Unable to find " + pos + " in " + windows); |
| 861 | i = 0; |
| 862 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 863 | windows.add(i, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 864 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | //This method finds out the index of a window that has the same app token as |
| 868 | //win. used for z ordering the windows in mWindows |
| 869 | private int findIdxBasedOnAppTokens(WindowState win) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 870 | WindowList windows = win.getWindowList(); |
| 871 | for(int j = windows.size() - 1; j >= 0; j--) { |
| 872 | WindowState wentry = windows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 873 | if(wentry.mAppToken == win.mAppToken) { |
| 874 | return j; |
| 875 | } |
| 876 | } |
| 877 | return -1; |
| 878 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 879 | |
Craig Mautner | efb735d | 2012-09-07 15:40:24 -0700 | [diff] [blame] | 880 | /** |
| 881 | * Return the list of Windows from the passed token on the given Display. |
| 882 | * @param token The token with all the windows. |
| 883 | * @param displayContent The display we are interested in. |
| 884 | * @return List of windows from token that are on displayContent. |
| 885 | */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 886 | WindowList getTokenWindowsOnDisplay(WindowToken token, DisplayContent displayContent) { |
| 887 | final WindowList windowList = new WindowList(); |
| 888 | final int count = token.windows.size(); |
| 889 | for (int i = 0; i < count; i++) { |
| 890 | final WindowState win = token.windows.get(i); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 891 | if (win.getDisplayContent() == displayContent) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 892 | windowList.add(win); |
| 893 | } |
| 894 | } |
| 895 | return windowList; |
| 896 | } |
| 897 | |
Craig Mautner | 7b1aa77 | 2012-11-30 16:14:45 -0800 | [diff] [blame] | 898 | /** |
| 899 | * Recursive search through a WindowList and all of its windows' children. |
| 900 | * @param targetWin The window to search for. |
| 901 | * @param windows The list to search. |
| 902 | * @return The index of win in windows or of the window that is an ancestor of win. |
| 903 | */ |
| 904 | private int indexOfWinInWindowList(WindowState targetWin, WindowList windows) { |
| 905 | for (int i = windows.size() - 1; i >= 0; i--) { |
| 906 | final WindowState w = windows.get(i); |
| 907 | if (w == targetWin) { |
| 908 | return i; |
| 909 | } |
| 910 | if (!w.mChildWindows.isEmpty()) { |
| 911 | if (indexOfWinInWindowList(targetWin, w.mChildWindows) >= 0) { |
| 912 | return i; |
| 913 | } |
| 914 | } |
| 915 | } |
| 916 | return -1; |
| 917 | } |
| 918 | |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 919 | private int addAppWindowToListLocked(final WindowState win) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | final IWindow client = win.mClient; |
| 921 | final WindowToken token = win.mToken; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 922 | final DisplayContent displayContent = win.getDisplayContent(); |
Craig Mautner | d3849f5 | 2014-03-27 13:19:29 -0700 | [diff] [blame] | 923 | if (displayContent == null) { |
| 924 | // It doesn't matter this display is going away. |
| 925 | return 0; |
| 926 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 927 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 928 | final WindowList windows = win.getWindowList(); |
| 929 | final int N = windows.size(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 930 | WindowList tokenWindowList = getTokenWindowsOnDisplay(token, displayContent); |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 931 | int tokenWindowsPos = 0; |
| 932 | int windowListPos = tokenWindowList.size(); |
| 933 | if (!tokenWindowList.isEmpty()) { |
| 934 | // If this application has existing windows, we |
| 935 | // simply place the new window on top of them... but |
| 936 | // keep the starting window on top. |
| 937 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 938 | // Base windows go behind everything else. |
| 939 | WindowState lowestWindow = tokenWindowList.get(0); |
| 940 | placeWindowBefore(lowestWindow, win); |
| 941 | tokenWindowsPos = indexOfWinInWindowList(lowestWindow, token.windows); |
| 942 | } else { |
| 943 | AppWindowToken atoken = win.mAppToken; |
| 944 | WindowState lastWindow = tokenWindowList.get(windowListPos - 1); |
| 945 | if (atoken != null && lastWindow == atoken.startingWindow) { |
| 946 | placeWindowBefore(lastWindow, win); |
| 947 | tokenWindowsPos = indexOfWinInWindowList(lastWindow, token.windows); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 948 | } else { |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 949 | int newIdx = findIdxBasedOnAppTokens(win); |
| 950 | //there is a window above this one associated with the same |
| 951 | //apptoken note that the window could be a floating window |
| 952 | //that was created later or a window at the top of the list of |
| 953 | //windows associated with this token. |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 954 | if (DEBUG_FOCUS_LIGHT || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, |
Craig Mautner | b1885b8 | 2013-09-16 22:50:50 -0700 | [diff] [blame] | 955 | "not Base app: Adding window " + win + " at " + (newIdx + 1) + " of " + |
| 956 | N); |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 957 | windows.add(newIdx + 1, win); |
| 958 | if (newIdx < 0) { |
| 959 | // No window from token found on win's display. |
| 960 | tokenWindowsPos = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 961 | } else { |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 962 | tokenWindowsPos = indexOfWinInWindowList( |
| 963 | windows.get(newIdx), token.windows) + 1; |
| 964 | } |
| 965 | mWindowsChanged = true; |
| 966 | } |
| 967 | } |
| 968 | return tokenWindowsPos; |
| 969 | } |
| 970 | |
| 971 | // No windows from this token on this display |
| 972 | if (localLOGV) Slog.v(TAG, "Figuring out where to add app window " + client.asBinder() |
| 973 | + " (token=" + token + ")"); |
| 974 | // Figure out where the window should go, based on the |
| 975 | // order of applications. |
| 976 | WindowState pos = null; |
| 977 | |
Craig Mautner | 018be3d | 2013-08-27 13:25:17 -0700 | [diff] [blame] | 978 | final ArrayList<Task> tasks = displayContent.getTasks(); |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 979 | int taskNdx; |
| 980 | int tokenNdx = -1; |
| 981 | for (taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 982 | AppTokenList tokens = tasks.get(taskNdx).mAppTokens; |
| 983 | for (tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) { |
| 984 | final AppWindowToken t = tokens.get(tokenNdx); |
| 985 | if (t == token) { |
| 986 | --tokenNdx; |
| 987 | if (tokenNdx < 0) { |
| 988 | --taskNdx; |
| 989 | if (taskNdx >= 0) { |
| 990 | tokenNdx = tasks.get(taskNdx).mAppTokens.size() - 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | } |
| 992 | } |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 993 | break; |
| 994 | } |
| 995 | |
| 996 | // We haven't reached the token yet; if this token |
| 997 | // is not going to the bottom and has windows on this display, we can |
| 998 | // use it as an anchor for when we do reach the token. |
| 999 | tokenWindowList = getTokenWindowsOnDisplay(t, displayContent); |
| 1000 | if (!t.sendingToBottom && tokenWindowList.size() > 0) { |
| 1001 | pos = tokenWindowList.get(0); |
| 1002 | } |
| 1003 | } |
| 1004 | if (tokenNdx >= 0) { |
| 1005 | // early exit |
| 1006 | break; |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | // We now know the index into the apps. If we found |
| 1011 | // an app window above, that gives us the position; else |
| 1012 | // we need to look some more. |
| 1013 | if (pos != null) { |
| 1014 | // Move behind any windows attached to this one. |
| 1015 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| 1016 | if (atoken != null) { |
| 1017 | tokenWindowList = |
| 1018 | getTokenWindowsOnDisplay(atoken, displayContent); |
| 1019 | final int NC = tokenWindowList.size(); |
| 1020 | if (NC > 0) { |
| 1021 | WindowState bottom = tokenWindowList.get(0); |
| 1022 | if (bottom.mSubLayer < 0) { |
| 1023 | pos = bottom; |
| 1024 | } |
| 1025 | } |
| 1026 | } |
| 1027 | placeWindowBefore(pos, win); |
| 1028 | return tokenWindowsPos; |
| 1029 | } |
| 1030 | |
| 1031 | // Continue looking down until we find the first |
| 1032 | // token that has windows on this display. |
| 1033 | for ( ; taskNdx >= 0; --taskNdx) { |
| 1034 | AppTokenList tokens = tasks.get(taskNdx).mAppTokens; |
| 1035 | for ( ; tokenNdx >= 0; --tokenNdx) { |
| 1036 | final AppWindowToken t = tokens.get(tokenNdx); |
| 1037 | tokenWindowList = getTokenWindowsOnDisplay(t, displayContent); |
| 1038 | final int NW = tokenWindowList.size(); |
| 1039 | if (NW > 0) { |
| 1040 | pos = tokenWindowList.get(NW-1); |
| 1041 | break; |
| 1042 | } |
| 1043 | } |
| 1044 | if (tokenNdx >= 0) { |
| 1045 | // found |
| 1046 | break; |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | if (pos != null) { |
| 1051 | // Move in front of any windows attached to this |
| 1052 | // one. |
| 1053 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| 1054 | if (atoken != null) { |
| 1055 | final int NC = atoken.windows.size(); |
| 1056 | if (NC > 0) { |
| 1057 | WindowState top = atoken.windows.get(NC-1); |
| 1058 | if (top.mSubLayer >= 0) { |
| 1059 | pos = top; |
| 1060 | } |
| 1061 | } |
| 1062 | } |
| 1063 | placeWindowAfter(pos, win); |
| 1064 | return tokenWindowsPos; |
| 1065 | } |
| 1066 | |
| 1067 | // Just search for the start of this layer. |
| 1068 | final int myLayer = win.mBaseLayer; |
| 1069 | int i; |
| 1070 | for (i = 0; i < N; i++) { |
| 1071 | WindowState w = windows.get(i); |
| 1072 | if (w.mBaseLayer > myLayer) { |
| 1073 | break; |
| 1074 | } |
| 1075 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 1076 | if (DEBUG_FOCUS_LIGHT || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, |
Craig Mautner | b1885b8 | 2013-09-16 22:50:50 -0700 | [diff] [blame] | 1077 | "Based on layer: Adding window " + win + " at " + i + " of " + N); |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 1078 | windows.add(i, win); |
| 1079 | mWindowsChanged = true; |
| 1080 | return tokenWindowsPos; |
| 1081 | } |
| 1082 | |
| 1083 | private void addFreeWindowToListLocked(final WindowState win) { |
| 1084 | final WindowList windows = win.getWindowList(); |
| 1085 | |
| 1086 | // Figure out where window should go, based on layer. |
| 1087 | final int myLayer = win.mBaseLayer; |
| 1088 | int i; |
| 1089 | for (i = windows.size() - 1; i >= 0; i--) { |
| 1090 | if (windows.get(i).mBaseLayer <= myLayer) { |
| 1091 | break; |
| 1092 | } |
| 1093 | } |
| 1094 | i++; |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 1095 | if (DEBUG_FOCUS_LIGHT || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, |
Craig Mautner | b1885b8 | 2013-09-16 22:50:50 -0700 | [diff] [blame] | 1096 | "Free window: Adding window " + win + " at " + i + " of " + windows.size()); |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 1097 | windows.add(i, win); |
| 1098 | mWindowsChanged = true; |
| 1099 | } |
| 1100 | |
| 1101 | private void addAttachedWindowToListLocked(final WindowState win, boolean addToToken) { |
| 1102 | final WindowToken token = win.mToken; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1103 | final DisplayContent displayContent = win.getDisplayContent(); |
Craig Mautner | d3849f5 | 2014-03-27 13:19:29 -0700 | [diff] [blame] | 1104 | if (displayContent == null) { |
| 1105 | return; |
| 1106 | } |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 1107 | final WindowState attached = win.mAttachedWindow; |
| 1108 | |
| 1109 | WindowList tokenWindowList = getTokenWindowsOnDisplay(token, displayContent); |
| 1110 | |
| 1111 | // Figure out this window's ordering relative to the window |
| 1112 | // it is attached to. |
| 1113 | final int NA = tokenWindowList.size(); |
| 1114 | final int sublayer = win.mSubLayer; |
| 1115 | int largestSublayer = Integer.MIN_VALUE; |
| 1116 | WindowState windowWithLargestSublayer = null; |
| 1117 | int i; |
| 1118 | for (i = 0; i < NA; i++) { |
| 1119 | WindowState w = tokenWindowList.get(i); |
| 1120 | final int wSublayer = w.mSubLayer; |
| 1121 | if (wSublayer >= largestSublayer) { |
| 1122 | largestSublayer = wSublayer; |
| 1123 | windowWithLargestSublayer = w; |
| 1124 | } |
| 1125 | if (sublayer < 0) { |
| 1126 | // For negative sublayers, we go below all windows |
| 1127 | // in the same sublayer. |
| 1128 | if (wSublayer >= sublayer) { |
| 1129 | if (addToToken) { |
| 1130 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token); |
| 1131 | token.windows.add(i, win); |
| 1132 | } |
| 1133 | placeWindowBefore(wSublayer >= 0 ? attached : w, win); |
| 1134 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1135 | } |
| 1136 | } else { |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 1137 | // For positive sublayers, we go above all windows |
| 1138 | // in the same sublayer. |
| 1139 | if (wSublayer > sublayer) { |
| 1140 | if (addToToken) { |
| 1141 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token); |
| 1142 | token.windows.add(i, win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1143 | } |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 1144 | placeWindowBefore(w, win); |
| 1145 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1146 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | } |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 1148 | } |
| 1149 | if (i >= NA) { |
| 1150 | if (addToToken) { |
| 1151 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token); |
| 1152 | token.windows.add(win); |
| 1153 | } |
| 1154 | if (sublayer < 0) { |
| 1155 | placeWindowBefore(attached, win); |
| 1156 | } else { |
| 1157 | placeWindowAfter(largestSublayer >= 0 |
| 1158 | ? windowWithLargestSublayer |
| 1159 | : attached, |
| 1160 | win); |
| 1161 | } |
| 1162 | } |
| 1163 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1164 | |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 1165 | private void addWindowToListInOrderLocked(final WindowState win, boolean addToToken) { |
Craig Mautner | b1885b8 | 2013-09-16 22:50:50 -0700 | [diff] [blame] | 1166 | if (DEBUG_FOCUS_LIGHT) Slog.d(TAG, "addWindowToListInOrderLocked: win=" + win + |
| 1167 | " Callers=" + Debug.getCallers(4)); |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 1168 | if (win.mAttachedWindow == null) { |
| 1169 | final WindowToken token = win.mToken; |
| 1170 | int tokenWindowsPos = 0; |
| 1171 | if (token.appWindowToken != null) { |
| 1172 | tokenWindowsPos = addAppWindowToListLocked(win); |
| 1173 | } else { |
| 1174 | addFreeWindowToListLocked(win); |
| 1175 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1176 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1177 | 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] | 1178 | token.windows.add(tokenWindowsPos, win); |
| 1179 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1180 | } else { |
Craig Mautner | a5eed0b | 2013-03-16 12:41:54 -0700 | [diff] [blame] | 1181 | addAttachedWindowToListLocked(win, addToToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1184 | if (win.mAppToken != null && addToToken) { |
| 1185 | win.mAppToken.allAppWindows.add(win); |
| 1186 | } |
| 1187 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1188 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1189 | static boolean canBeImeTarget(WindowState w) { |
| 1190 | final int fl = w.mAttrs.flags |
| 1191 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1192 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM) |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 1193 | || w.mAttrs.type == TYPE_APPLICATION_STARTING) { |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1194 | if (DEBUG_INPUT_METHOD) { |
| 1195 | Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding()); |
| 1196 | if (!w.isVisibleOrAdding()) { |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 1197 | Slog.i(TAG, " mSurface=" + w.mWinAnimator.mSurfaceControl |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1198 | + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 1199 | + " policyVis=" + w.mPolicyVisibility |
| 1200 | + " policyVisAfterAnim=" + w.mPolicyVisibilityAfterAnim |
| 1201 | + " attachHid=" + w.mAttachedHidden |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1202 | + " exiting=" + w.mExiting + " destroying=" + w.mDestroying); |
| 1203 | if (w.mAppToken != null) { |
| 1204 | Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested); |
| 1205 | } |
| 1206 | } |
| 1207 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1208 | return w.isVisibleOrAdding(); |
| 1209 | } |
| 1210 | return false; |
| 1211 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1212 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 1213 | /** |
| 1214 | * Dig through the WindowStates and find the one that the Input Method will target. |
| 1215 | * @param willMove |
| 1216 | * @return The index+1 in mWindows of the discovered target. |
| 1217 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1218 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1219 | // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the |
| 1220 | // same display. Or even when the current IME/target are not on the same screen as the next |
| 1221 | // IME/target. For now only look for input windows on the main screen. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 1222 | WindowList windows = getDefaultWindowListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1223 | WindowState w = null; |
Craig Mautner | 22b9a5e | 2013-09-17 14:50:56 -0700 | [diff] [blame] | 1224 | int i; |
| 1225 | for (i = windows.size() - 1; i >= 0; --i) { |
| 1226 | WindowState win = windows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1227 | |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1228 | if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i |
Craig Mautner | 22b9a5e | 2013-09-17 14:50:56 -0700 | [diff] [blame] | 1229 | + " " + win + " fl=0x" + Integer.toHexString(win.mAttrs.flags)); |
| 1230 | if (canBeImeTarget(win)) { |
| 1231 | w = win; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1232 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1234 | // Yet more tricksyness! If this window is a "starting" |
| 1235 | // window, we do actually want to be on top of it, but |
| 1236 | // it is not -really- where input will go. So if the caller |
| 1237 | // is not actually looking to move the IME, look down below |
| 1238 | // for a real window to target... |
| 1239 | if (!willMove |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 1240 | && w.mAttrs.type == TYPE_APPLICATION_STARTING |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1241 | && i > 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1242 | WindowState wb = windows.get(i-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1243 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1244 | i--; |
| 1245 | w = wb; |
| 1246 | } |
| 1247 | } |
| 1248 | break; |
| 1249 | } |
| 1250 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1251 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 1252 | // Now w is either mWindows[0] or an IME (or null if mWindows is empty). |
| 1253 | |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1254 | 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] | 1255 | |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1256 | // Now, a special case -- if the last target's window is in the |
| 1257 | // process of exiting, and is above the new target, keep on the |
| 1258 | // last target to avoid flicker. Consider for example a Dialog with |
| 1259 | // the IME shown: when the Dialog is dismissed, we want to keep |
| 1260 | // the IME above it until it is completely gone so it doesn't drop |
| 1261 | // behind the dialog or its full-screen scrim. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1262 | final WindowState curTarget = mInputMethodTarget; |
Craig Mautner | ae87962 | 2013-10-03 14:07:45 -0700 | [diff] [blame] | 1263 | if (curTarget != null |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1264 | && curTarget.isDisplayedLw() |
Craig Mautner | a987d43 | 2012-10-11 14:07:58 -0700 | [diff] [blame] | 1265 | && curTarget.isClosing() |
Craig Mautner | ae87962 | 2013-10-03 14:07:45 -0700 | [diff] [blame] | 1266 | && (w == null || curTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer)) { |
Craig Mautner | e6f7d50 | 2012-10-08 10:34:17 -0700 | [diff] [blame] | 1267 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, not changing"); |
| 1268 | return windows.indexOf(curTarget) + 1; |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1269 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1270 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1271 | 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] | 1272 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1274 | if (willMove && w != null) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1275 | AppWindowToken token = curTarget == null ? null : curTarget.mAppToken; |
| 1276 | if (token != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1277 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1278 | // Now some fun for dealing with window animations that |
| 1279 | // modify the Z order. We need to look at all windows below |
| 1280 | // the current target that are in this app, finding the highest |
| 1281 | // visible one in layering. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1282 | WindowState highestTarget = null; |
| 1283 | int highestPos = 0; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1284 | if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1285 | WindowList curWindows = curTarget.getWindowList(); |
| 1286 | int pos = curWindows.indexOf(curTarget); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1287 | while (pos >= 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1288 | WindowState win = curWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1289 | if (win.mAppToken != token) { |
| 1290 | break; |
| 1291 | } |
| 1292 | if (!win.mRemoved) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1293 | if (highestTarget == null || win.mWinAnimator.mAnimLayer > |
| 1294 | highestTarget.mWinAnimator.mAnimLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1295 | highestTarget = win; |
| 1296 | highestPos = pos; |
| 1297 | } |
| 1298 | } |
| 1299 | pos--; |
| 1300 | } |
| 1301 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1302 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1303 | if (highestTarget != null) { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1304 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, mAppTransition + " " + highestTarget |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1305 | + " animating=" + highestTarget.mWinAnimator.isAnimating() |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1306 | + " layer=" + highestTarget.mWinAnimator.mAnimLayer |
| 1307 | + " new layer=" + w.mWinAnimator.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1308 | |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1309 | if (mAppTransition.isTransitionSet()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1310 | // If we are currently setting up for an animation, |
| 1311 | // hold everything until we can find out what will happen. |
| 1312 | mInputMethodTargetWaitingAnim = true; |
| 1313 | mInputMethodTarget = highestTarget; |
| 1314 | return highestPos + 1; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1315 | } else if (highestTarget.mWinAnimator.isAnimating() && |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1316 | highestTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1317 | // If the window we are currently targeting is involved |
| 1318 | // with an animation, and it is on top of the next target |
| 1319 | // we will be over, then hold off on moving until |
| 1320 | // that is done. |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1321 | mInputMethodTargetWaitingAnim = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1322 | mInputMethodTarget = highestTarget; |
| 1323 | return highestPos + 1; |
| 1324 | } |
| 1325 | } |
| 1326 | } |
| 1327 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1328 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1329 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1330 | if (w != null) { |
| 1331 | if (willMove) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1332 | if (DEBUG_INPUT_METHOD) Slog.w(TAG, "Moving IM target from " + curTarget + " to " |
| 1333 | + w + (HIDE_STACK_CRAWLS ? "" : " Callers=" + Debug.getCallers(4))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1334 | mInputMethodTarget = w; |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1335 | mInputMethodTargetWaitingAnim = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1336 | if (w.mAppToken != null) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1337 | setInputMethodAnimLayerAdjustment(w.mAppToken.mAppAnimator.animLayerAdjustment); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1338 | } else { |
| 1339 | setInputMethodAnimLayerAdjustment(0); |
| 1340 | } |
| 1341 | } |
| 1342 | return i+1; |
| 1343 | } |
| 1344 | if (willMove) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1345 | if (DEBUG_INPUT_METHOD) Slog.w(TAG, "Moving IM target from " + curTarget + " to null." |
| 1346 | + (HIDE_STACK_CRAWLS ? "" : " Callers=" + Debug.getCallers(4))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1347 | mInputMethodTarget = null; |
| 1348 | setInputMethodAnimLayerAdjustment(0); |
| 1349 | } |
| 1350 | return -1; |
| 1351 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1353 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1354 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1355 | if (pos >= 0) { |
| 1356 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1357 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1358 | TAG, "Adding input method window " + win + " at " + pos); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1359 | // TODO(multidisplay): IMEs are only supported on the default display. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 1360 | getDefaultWindowListLocked().add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1361 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1362 | moveInputMethodDialogsLocked(pos+1); |
| 1363 | return; |
| 1364 | } |
| 1365 | win.mTargetAppToken = null; |
| 1366 | addWindowToListInOrderLocked(win, true); |
| 1367 | moveInputMethodDialogsLocked(pos); |
| 1368 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1369 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1370 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1371 | 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] | 1372 | mInputMethodAnimLayerAdjustment = adj; |
| 1373 | WindowState imw = mInputMethodWindow; |
| 1374 | if (imw != null) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1375 | imw.mWinAnimator.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1376 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1377 | + " anim layer: " + imw.mWinAnimator.mAnimLayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1378 | int wi = imw.mChildWindows.size(); |
| 1379 | while (wi > 0) { |
| 1380 | wi--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1381 | WindowState cw = imw.mChildWindows.get(wi); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1382 | cw.mWinAnimator.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1383 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1384 | + " anim layer: " + cw.mWinAnimator.mAnimLayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1385 | } |
| 1386 | } |
| 1387 | int di = mInputMethodDialogs.size(); |
| 1388 | while (di > 0) { |
| 1389 | di --; |
| 1390 | imw = mInputMethodDialogs.get(di); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1391 | imw.mWinAnimator.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1392 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1393 | + " anim layer: " + imw.mWinAnimator.mAnimLayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1394 | } |
| 1395 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1396 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1397 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1398 | WindowList windows = win.getWindowList(); |
| 1399 | int wpos = windows.indexOf(win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1400 | if (wpos >= 0) { |
| 1401 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1402 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1403 | windows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1404 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1405 | int NC = win.mChildWindows.size(); |
| 1406 | while (NC > 0) { |
| 1407 | NC--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1408 | WindowState cw = win.mChildWindows.get(NC); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1409 | int cpos = windows.indexOf(cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1410 | if (cpos >= 0) { |
| 1411 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1412 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1413 | + cpos + ": " + cw); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1414 | windows.remove(cpos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1415 | } |
| 1416 | } |
| 1417 | } |
| 1418 | return interestingPos; |
| 1419 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1420 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1421 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1422 | addWindowToListInOrderLocked(win, false); |
| 1423 | // This is a hack to get all of the child windows added as well |
| 1424 | // at the right position. Child windows should be rare and |
| 1425 | // 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] | 1426 | WindowList windows = win.getWindowList(); |
| 1427 | int wpos = windows.indexOf(win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1428 | if (wpos >= 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1429 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos + ": " + win); |
| 1430 | windows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1431 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | reAddWindowLocked(wpos, win); |
| 1433 | } |
| 1434 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1435 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1436 | void logWindowList(final WindowList windows, String prefix) { |
| 1437 | int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1438 | while (N > 0) { |
| 1439 | N--; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1440 | Slog.v(TAG, prefix + "#" + N + ": " + windows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1441 | } |
| 1442 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | void moveInputMethodDialogsLocked(int pos) { |
| 1445 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1446 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1447 | // TODO(multidisplay): IMEs are only supported on the default display. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 1448 | WindowList windows = getDefaultWindowListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1449 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1450 | 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] | 1451 | for (int i=0; i<N; i++) { |
| 1452 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1453 | } |
| 1454 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1455 | Slog.v(TAG, "Window list w/pos=" + pos); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1456 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | if (pos >= 0) { |
| 1460 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1461 | if (pos < windows.size()) { |
| 1462 | WindowState wp = windows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | if (wp == mInputMethodWindow) { |
| 1464 | pos++; |
| 1465 | } |
| 1466 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1467 | 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] | 1468 | for (int i=0; i<N; i++) { |
| 1469 | WindowState win = dialogs.get(i); |
| 1470 | win.mTargetAppToken = targetAppToken; |
| 1471 | pos = reAddWindowLocked(pos, win); |
| 1472 | } |
| 1473 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1474 | Slog.v(TAG, "Final window list:"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1475 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1476 | } |
| 1477 | return; |
| 1478 | } |
| 1479 | for (int i=0; i<N; i++) { |
| 1480 | WindowState win = dialogs.get(i); |
| 1481 | win.mTargetAppToken = null; |
| 1482 | reAddWindowToListInOrderLocked(win); |
| 1483 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1484 | Slog.v(TAG, "No IM target, final list:"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1485 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1486 | } |
| 1487 | } |
| 1488 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1490 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1491 | final WindowState imWin = mInputMethodWindow; |
| 1492 | final int DN = mInputMethodDialogs.size(); |
| 1493 | if (imWin == null && DN == 0) { |
| 1494 | return false; |
| 1495 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1496 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1497 | // TODO(multidisplay): IMEs are only supported on the default display. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 1498 | WindowList windows = getDefaultWindowListLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1499 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1500 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1501 | if (imPos >= 0) { |
| 1502 | // In this case, the input method windows are to be placed |
| 1503 | // immediately above the window they are targeting. |
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 | // First check to see if the input method windows are already |
| 1506 | // located here, and contiguous. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1507 | final int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1508 | WindowState firstImWin = imPos < N |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1509 | ? windows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | // Figure out the actual input method window that should be |
| 1512 | // at the bottom of their stack. |
| 1513 | WindowState baseImWin = imWin != null |
| 1514 | ? imWin : mInputMethodDialogs.get(0); |
| 1515 | if (baseImWin.mChildWindows.size() > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1516 | WindowState cw = baseImWin.mChildWindows.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1518 | } |
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 | if (firstImWin == baseImWin) { |
| 1521 | // The windows haven't moved... but are they still contiguous? |
| 1522 | // First find the top IM window. |
| 1523 | int pos = imPos+1; |
| 1524 | while (pos < N) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1525 | if (!(windows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1526 | break; |
| 1527 | } |
| 1528 | pos++; |
| 1529 | } |
| 1530 | pos++; |
| 1531 | // Now there should be no more input method windows above. |
| 1532 | while (pos < N) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1533 | if ((windows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1534 | break; |
| 1535 | } |
| 1536 | pos++; |
| 1537 | } |
| 1538 | if (pos >= N) { |
Carrie Xu | 5c97184 | 2012-10-30 17:28:39 +0800 | [diff] [blame] | 1539 | // Z order is good. |
| 1540 | // The IM target window may be changed, so update the mTargetAppToken. |
| 1541 | if (imWin != null) { |
| 1542 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1543 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1544 | return false; |
| 1545 | } |
| 1546 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1548 | if (imWin != null) { |
| 1549 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1550 | Slog.v(TAG, "Moving IM from " + imPos); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1551 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1552 | } |
| 1553 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1554 | if (DEBUG_INPUT_METHOD) { |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1555 | Slog.v(TAG, "List after removing with new pos " + imPos + ":"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1556 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1557 | } |
| 1558 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1559 | reAddWindowLocked(imPos, imWin); |
| 1560 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1561 | Slog.v(TAG, "List after moving IM to " + 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 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1565 | } else { |
| 1566 | moveInputMethodDialogsLocked(imPos); |
| 1567 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1569 | } else { |
| 1570 | // In this case, the input method windows go in a fixed layer, |
| 1571 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1573 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1574 | 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] | 1575 | tmpRemoveWindowLocked(0, imWin); |
| 1576 | imWin.mTargetAppToken = null; |
| 1577 | reAddWindowToListInOrderLocked(imWin); |
| 1578 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1579 | Slog.v(TAG, "List with no IM target:"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1580 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1581 | } |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 1582 | if (DN > 0) moveInputMethodDialogsLocked(-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1583 | } else { |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 1584 | moveInputMethodDialogsLocked(-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1585 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1587 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | if (needAssignLayers) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1590 | assignLayersLocked(windows); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1591 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1593 | return true; |
| 1594 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1595 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1596 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Craig Mautner | ad3a9bb | 2012-03-09 11:31:06 -0800 | [diff] [blame] | 1597 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target " + wallpaperTarget + ", obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1598 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1599 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1600 | ? wallpaperTarget.mAppToken.mAppAnimator.animation : null) |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1601 | + " upper=" + mUpperWallpaperTarget |
| 1602 | + " lower=" + mLowerWallpaperTarget); |
| 1603 | return (wallpaperTarget != null |
| 1604 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1605 | && wallpaperTarget.mAppToken.mAppAnimator.animation != null))) |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1606 | || mUpperWallpaperTarget != null |
| 1607 | || mLowerWallpaperTarget != null; |
| 1608 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1609 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1610 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1611 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1612 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1613 | int adjustWallpaperWindowsLocked() { |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 1614 | mInnerFields.mWallpaperMayChange = false; |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 1615 | boolean targetChanged = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1616 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1617 | // TODO(multidisplay): Wallpapers on main screen only. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 1618 | final DisplayInfo displayInfo = getDefaultDisplayContentLocked().getDisplayInfo(); |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 1619 | final int dw = displayInfo.logicalWidth; |
| 1620 | final int dh = displayInfo.logicalHeight; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1621 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1622 | // First find top-most window that has asked to be on top of the |
| 1623 | // wallpaper; all wallpapers go behind it. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 1624 | final WindowList windows = getDefaultWindowListLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1625 | int N = windows.size(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1626 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1627 | WindowState foundW = null; |
| 1628 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1629 | WindowState topCurW = null; |
| 1630 | int topCurI = 0; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1631 | int windowDetachedI = -1; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1632 | int i = N; |
| 1633 | while (i > 0) { |
| 1634 | i--; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1635 | w = windows.get(i); |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 1636 | if ((w.mAttrs.type == TYPE_WALLPAPER)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1637 | if (topCurW == null) { |
| 1638 | topCurW = w; |
| 1639 | topCurI = i; |
| 1640 | } |
| 1641 | continue; |
| 1642 | } |
| 1643 | topCurW = null; |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 1644 | if (w != mAnimator.mWindowDetachedWallpaper && w.mAppToken != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1645 | // If this window's app token is hidden and not animating, |
| 1646 | // it is of no interest to us. |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1647 | if (w.mAppToken.hidden && w.mAppToken.mAppAnimator.animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1648 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Craig Mautner | 1d961d4 | 2012-05-27 12:02:11 -0700 | [diff] [blame] | 1649 | "Skipping hidden and not animating token: " + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1650 | continue; |
| 1651 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1652 | } |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 1653 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win #" + i + " " + w + ": isOnScreen=" |
| 1654 | + w.isOnScreen() + " mDrawState=" + w.mWinAnimator.mDrawState); |
| 1655 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isOnScreen() |
| 1656 | && (mWallpaperTarget == w || w.isDrawFinishedLw())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1657 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 1658 | "Found wallpaper target: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1659 | foundW = w; |
| 1660 | foundI = i; |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 1661 | if (w == mWallpaperTarget && w.mWinAnimator.isAnimating()) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1662 | // The current wallpaper target is animating, so we'll |
| 1663 | // look behind it for another possible target and figure |
| 1664 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1665 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1666 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1667 | continue; |
| 1668 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1669 | break; |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 1670 | } else if (w == mAnimator.mWindowDetachedWallpaper) { |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1671 | windowDetachedI = i; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1672 | } |
| 1673 | } |
| 1674 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1675 | if (foundW == null && windowDetachedI >= 0) { |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 1676 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1677 | "Found animating detached wallpaper activity: #" + i + "=" + w); |
| 1678 | foundW = w; |
| 1679 | foundI = windowDetachedI; |
| 1680 | } |
| 1681 | |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 1682 | if (mWallpaperTarget != foundW |
| 1683 | && (mLowerWallpaperTarget == null || mLowerWallpaperTarget != foundW)) { |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 1684 | if (DEBUG_WALLPAPER_LIGHT) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1685 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1686 | + " oldTarget: " + mWallpaperTarget); |
| 1687 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1688 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1689 | mLowerWallpaperTarget = null; |
| 1690 | mUpperWallpaperTarget = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1691 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1692 | WindowState oldW = mWallpaperTarget; |
| 1693 | mWallpaperTarget = foundW; |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 1694 | targetChanged = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1695 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1696 | // Now what is happening... if the current and new targets are |
| 1697 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1698 | if (foundW != null && oldW != null) { |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 1699 | boolean oldAnim = oldW.isAnimatingLw(); |
| 1700 | boolean foundAnim = foundW.isAnimatingLw(); |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 1701 | if (DEBUG_WALLPAPER_LIGHT) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1702 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1703 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1704 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1705 | if (foundAnim && oldAnim) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1706 | int oldI = windows.indexOf(oldW); |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 1707 | if (DEBUG_WALLPAPER_LIGHT) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1708 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1709 | } |
| 1710 | if (oldI >= 0) { |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 1711 | if (DEBUG_WALLPAPER_LIGHT) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1712 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1713 | + "=" + oldW + "; new#" + foundI |
| 1714 | + "=" + foundW); |
| 1715 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1716 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1717 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1718 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 1719 | if (DEBUG_WALLPAPER_LIGHT) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1720 | Slog.v(TAG, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1721 | } |
| 1722 | mWallpaperTarget = oldW; |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1723 | foundW = oldW; |
| 1724 | foundI = oldI; |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 1725 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1726 | // Now set the upper and lower wallpaper targets |
| 1727 | // correctly, and make sure that we are positioning |
| 1728 | // the wallpaper below the lower. |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1729 | else if (foundI > oldI) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1730 | // The new target is on top of the old one. |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 1731 | if (DEBUG_WALLPAPER_LIGHT) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1732 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1733 | } |
| 1734 | mUpperWallpaperTarget = foundW; |
| 1735 | mLowerWallpaperTarget = oldW; |
| 1736 | foundW = oldW; |
| 1737 | foundI = oldI; |
| 1738 | } else { |
| 1739 | // The new target is below the old one. |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 1740 | if (DEBUG_WALLPAPER_LIGHT) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1741 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1742 | } |
| 1743 | mUpperWallpaperTarget = oldW; |
| 1744 | mLowerWallpaperTarget = foundW; |
| 1745 | } |
| 1746 | } |
| 1747 | } |
| 1748 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1749 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1750 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1751 | // Is it time to stop animating? |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 1752 | if (!mLowerWallpaperTarget.isAnimatingLw() || !mUpperWallpaperTarget.isAnimatingLw()) { |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 1753 | if (DEBUG_WALLPAPER_LIGHT) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1754 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1755 | } |
| 1756 | mLowerWallpaperTarget = null; |
| 1757 | mUpperWallpaperTarget = null; |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 1758 | mWallpaperTarget = foundW; |
| 1759 | targetChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1760 | } |
| 1761 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1762 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1763 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1764 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1765 | // The window is visible to the compositor... but is it visible |
| 1766 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1767 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1768 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1769 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1770 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1771 | // its layer adjustment. Only do this if we are not transfering |
| 1772 | // between two wallpaper targets. |
| 1773 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1774 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1775 | ? foundW.mAppToken.mAppAnimator.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1776 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1777 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1778 | * TYPE_LAYER_MULTIPLIER |
| 1779 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1780 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1781 | // Now w is the window we are supposed to be behind... but we |
| 1782 | // 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] | 1783 | // AND any starting window associated with it, AND below the |
| 1784 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1785 | while (foundI > 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1786 | WindowState wb = windows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1787 | if (wb.mBaseLayer < maxLayer && |
| 1788 | wb.mAttachedWindow != foundW && |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1789 | (foundW.mAttachedWindow == null || |
| 1790 | wb.mAttachedWindow != foundW.mAttachedWindow) && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1791 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1792 | foundW.mToken == null || wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1793 | // This window is not related to the previous one in any |
| 1794 | // interesting way, so stop here. |
| 1795 | break; |
| 1796 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1797 | foundW = wb; |
| 1798 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1799 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1800 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1801 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1802 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1803 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1804 | if (foundW == null && topCurW != null) { |
| 1805 | // There is no wallpaper target, so it goes at the bottom. |
| 1806 | // We will assume it is the same place as last time, if known. |
| 1807 | foundW = topCurW; |
| 1808 | foundI = topCurI+1; |
| 1809 | } else { |
| 1810 | // Okay i is the position immediately above the wallpaper. Look at |
| 1811 | // what is below it for later. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1812 | foundW = foundI > 0 ? windows.get(foundI-1) : null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1813 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1814 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1815 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1816 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1817 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1818 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1819 | } |
| 1820 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1821 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1822 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1823 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1824 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1825 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1826 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1827 | // are correctly placed. |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 1828 | int changed = 0; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1829 | int curTokenIndex = mWallpaperTokens.size(); |
| 1830 | while (curTokenIndex > 0) { |
| 1831 | curTokenIndex--; |
| 1832 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1833 | if (token.hidden == visible) { |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 1834 | if (DEBUG_WALLPAPER_LIGHT) Slog.d(TAG, |
| 1835 | "Wallpaper token " + token + " hidden=" + !visible); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1836 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1837 | token.hidden = !visible; |
| 1838 | // Need to do a layout to ensure the wallpaper now has the |
| 1839 | // correct size. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 1840 | getDefaultDisplayContentLocked().layoutNeeded = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1841 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1842 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1843 | int curWallpaperIndex = token.windows.size(); |
| 1844 | while (curWallpaperIndex > 0) { |
| 1845 | curWallpaperIndex--; |
| 1846 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1847 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1848 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1849 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1850 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1851 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1852 | // First, make sure the client has the current visibility |
| 1853 | // state. |
Craig Mautner | 507a2ee | 2012-06-13 08:39:38 -0700 | [diff] [blame] | 1854 | dispatchWallpaperVisibility(wallpaper, visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1855 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1856 | wallpaper.mWinAnimator.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 1857 | if (DEBUG_LAYERS || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "adjustWallpaper win " |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1858 | + wallpaper + " anim layer: " + wallpaper.mWinAnimator.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1859 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1860 | // First, if this window is at the current index, then all |
| 1861 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1862 | if (wallpaper == foundW) { |
| 1863 | foundI--; |
| 1864 | foundW = foundI > 0 |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1865 | ? windows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1866 | continue; |
| 1867 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1868 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1869 | // The window didn't match... the current wallpaper window, |
| 1870 | // wherever it is, is in the wrong place, so make sure it is |
| 1871 | // not in the list. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1872 | int oldIndex = windows.indexOf(wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1873 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1874 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1875 | + oldIndex + ": " + wallpaper); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1876 | windows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1877 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1878 | if (oldIndex < foundI) { |
| 1879 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1880 | } |
| 1881 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1882 | |
Craig Mautner | 5800443 | 2013-10-14 12:58:42 -0700 | [diff] [blame] | 1883 | // Now stick it in. For apps over wallpaper keep the wallpaper at the bottommost |
| 1884 | // layer. For keyguard over wallpaper put the wallpaper under the keyguard. |
| 1885 | int insertionIndex = 0; |
| 1886 | if (visible && foundW != null) { |
| 1887 | final int type = foundW.mAttrs.type; |
| 1888 | if (type == TYPE_KEYGUARD || type == TYPE_KEYGUARD_SCRIM) { |
| 1889 | insertionIndex = windows.indexOf(foundW); |
| 1890 | } |
| 1891 | } |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 1892 | if (DEBUG_WALLPAPER_LIGHT || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1893 | Slog.v(TAG, "Moving wallpaper " + wallpaper |
Craig Mautner | 5800443 | 2013-10-14 12:58:42 -0700 | [diff] [blame] | 1894 | + " from " + oldIndex + " to " + insertionIndex); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1895 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1896 | |
Craig Mautner | 5800443 | 2013-10-14 12:58:42 -0700 | [diff] [blame] | 1897 | windows.add(insertionIndex, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1898 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1899 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1900 | } |
| 1901 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1902 | |
Craig Mautner | 5457e61 | 2013-05-10 16:25:02 -0700 | [diff] [blame] | 1903 | /* |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1904 | final TaskStack targetStack = |
| 1905 | mWallpaperTarget == null ? null : mWallpaperTarget.getStack(); |
| 1906 | if ((changed & ADJUST_WALLPAPER_LAYERS_CHANGED) != 0 && |
| 1907 | targetStack != null && !targetStack.isHomeStack()) { |
| 1908 | // If the wallpaper target is not on the home stack then make sure that all windows |
| 1909 | // from other non-home stacks are above the wallpaper. |
| 1910 | for (i = foundI - 1; i >= 0; --i) { |
| 1911 | WindowState win = windows.get(i); |
| 1912 | if (!win.isVisibleLw()) { |
| 1913 | continue; |
| 1914 | } |
| 1915 | final TaskStack winStack = win.getStack(); |
| 1916 | if (winStack != null && !winStack.isHomeStack() && winStack != targetStack) { |
| 1917 | windows.remove(i); |
| 1918 | windows.add(foundI + 1, win); |
| 1919 | } |
| 1920 | } |
| 1921 | } |
Craig Mautner | 5457e61 | 2013-05-10 16:25:02 -0700 | [diff] [blame] | 1922 | */ |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1923 | |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 1924 | if (targetChanged && DEBUG_WALLPAPER_LIGHT) { |
| 1925 | Slog.d(TAG, "New wallpaper: target=" + mWallpaperTarget |
| 1926 | + " lower=" + mLowerWallpaperTarget + " upper=" |
| 1927 | + mUpperWallpaperTarget); |
| 1928 | } |
| 1929 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1930 | return changed; |
| 1931 | } |
| 1932 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1933 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1934 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1935 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1936 | mWallpaperAnimLayerAdjustment = adj; |
| 1937 | int curTokenIndex = mWallpaperTokens.size(); |
| 1938 | while (curTokenIndex > 0) { |
| 1939 | curTokenIndex--; |
| 1940 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1941 | int curWallpaperIndex = token.windows.size(); |
| 1942 | while (curWallpaperIndex > 0) { |
| 1943 | curWallpaperIndex--; |
| 1944 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1945 | wallpaper.mWinAnimator.mAnimLayer = wallpaper.mLayer + adj; |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 1946 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "setWallpaper win " |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1947 | + wallpaper + " anim layer: " + wallpaper.mWinAnimator.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1948 | } |
| 1949 | } |
| 1950 | } |
| 1951 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1952 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1953 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1954 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1955 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1956 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1957 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 1958 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1959 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1960 | changed = wallpaperWin.mXOffset != offset; |
| 1961 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1962 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1963 | + wallpaperWin + " x: " + offset); |
| 1964 | wallpaperWin.mXOffset = offset; |
| 1965 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1966 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1967 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1968 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1969 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1970 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1971 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1972 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1973 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1974 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1975 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1976 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1977 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1978 | + wallpaperWin + " y: " + offset); |
| 1979 | changed = true; |
| 1980 | wallpaperWin.mYOffset = offset; |
| 1981 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1982 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1983 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1984 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1985 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1986 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1987 | |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 1988 | if (rawChanged && (wallpaperWin.mAttrs.privateFlags & |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 1989 | WindowManager.LayoutParams.PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS) != 0) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1990 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1991 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1992 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1993 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1994 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1995 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1996 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1997 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1998 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1999 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2000 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2001 | if (mWaitingOnWallpaper != null) { |
| 2002 | long start = SystemClock.uptimeMillis(); |
| 2003 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 2004 | < start) { |
| 2005 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2006 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2007 | "Waiting for offset complete..."); |
| 2008 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 2009 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2010 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2011 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2012 | if ((start+WALLPAPER_TIMEOUT) |
| 2013 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2014 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2015 | + wallpaperWin); |
| 2016 | mLastWallpaperTimeoutTime = start; |
| 2017 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2018 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2019 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2020 | } |
| 2021 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2022 | } catch (RemoteException e) { |
| 2023 | } |
| 2024 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2025 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2026 | return changed; |
| 2027 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2028 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2029 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2030 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2031 | if (mWaitingOnWallpaper != null && |
| 2032 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2033 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2034 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2035 | } |
| 2036 | } |
| 2037 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2038 | |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 2039 | void updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2040 | final DisplayContent displayContent = changingTarget.getDisplayContent(); |
| 2041 | if (displayContent == null) { |
| 2042 | return; |
| 2043 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2044 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 2045 | final int dw = displayInfo.logicalWidth; |
| 2046 | final int dh = displayInfo.logicalHeight; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2047 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2048 | WindowState target = mWallpaperTarget; |
| 2049 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2050 | if (target.mWallpaperX >= 0) { |
| 2051 | mLastWallpaperX = target.mWallpaperX; |
| 2052 | } else if (changingTarget.mWallpaperX >= 0) { |
| 2053 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 2054 | } |
| 2055 | if (target.mWallpaperY >= 0) { |
| 2056 | mLastWallpaperY = target.mWallpaperY; |
| 2057 | } else if (changingTarget.mWallpaperY >= 0) { |
| 2058 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 2059 | } |
| 2060 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2061 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2062 | int curTokenIndex = mWallpaperTokens.size(); |
| 2063 | while (curTokenIndex > 0) { |
| 2064 | curTokenIndex--; |
| 2065 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2066 | int curWallpaperIndex = token.windows.size(); |
| 2067 | while (curWallpaperIndex > 0) { |
| 2068 | curWallpaperIndex--; |
| 2069 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2070 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2071 | WindowStateAnimator winAnimator = wallpaper.mWinAnimator; |
| 2072 | winAnimator.computeShownFrameLocked(); |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 2073 | // No need to lay out the windows - we can just set the wallpaper position |
| 2074 | // directly. |
Craig Mautner | 5810681 | 2012-12-28 12:27:40 -0800 | [diff] [blame] | 2075 | winAnimator.setWallpaperOffset(wallpaper.mShownFrame); |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2076 | // We only want to be synchronous with one wallpaper. |
| 2077 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2078 | } |
| 2079 | } |
| 2080 | } |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2081 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2082 | |
Craig Mautner | 507a2ee | 2012-06-13 08:39:38 -0700 | [diff] [blame] | 2083 | /** |
| 2084 | * Check wallpaper for visiblity change and notify window if so. |
| 2085 | * @param wallpaper The wallpaper to test and notify. |
| 2086 | * @param visible Current visibility. |
| 2087 | */ |
| 2088 | void dispatchWallpaperVisibility(final WindowState wallpaper, final boolean visible) { |
| 2089 | if (wallpaper.mWallpaperVisible != visible) { |
| 2090 | wallpaper.mWallpaperVisible = visible; |
| 2091 | try { |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 2092 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 2093 | "Updating vis of wallpaper " + wallpaper |
| 2094 | + ": " + visible + " from:\n" + Debug.getCallers(4, " ")); |
Craig Mautner | 507a2ee | 2012-06-13 08:39:38 -0700 | [diff] [blame] | 2095 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2096 | } catch (RemoteException e) { |
| 2097 | } |
| 2098 | } |
| 2099 | } |
| 2100 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2101 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2102 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2103 | final DisplayContent displayContent = mWallpaperTarget.getDisplayContent(); |
| 2104 | if (displayContent == null) { |
| 2105 | return; |
| 2106 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2107 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 2108 | final int dw = displayInfo.logicalWidth; |
| 2109 | final int dh = displayInfo.logicalHeight; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2110 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2111 | int curTokenIndex = mWallpaperTokens.size(); |
| 2112 | while (curTokenIndex > 0) { |
| 2113 | curTokenIndex--; |
| 2114 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2115 | if (token.hidden == visible) { |
| 2116 | token.hidden = !visible; |
| 2117 | // Need to do a layout to ensure the wallpaper now has the |
| 2118 | // correct size. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 2119 | getDefaultDisplayContentLocked().layoutNeeded = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2120 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2121 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2122 | int curWallpaperIndex = token.windows.size(); |
| 2123 | while (curWallpaperIndex > 0) { |
| 2124 | curWallpaperIndex--; |
| 2125 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2126 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2127 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2128 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2129 | |
Craig Mautner | 507a2ee | 2012-06-13 08:39:38 -0700 | [diff] [blame] | 2130 | dispatchWallpaperVisibility(wallpaper, visible); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2131 | } |
| 2132 | } |
| 2133 | } |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 2134 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2135 | public int addWindow(Session session, IWindow client, int seq, |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 2136 | WindowManager.LayoutParams attrs, int viewVisibility, int displayId, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2137 | Rect outContentInsets, InputChannel outInputChannel) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2138 | int[] appOp = new int[1]; |
| 2139 | int res = mPolicy.checkAddPermission(attrs, appOp); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2140 | if (res != WindowManagerGlobal.ADD_OKAY) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2141 | return res; |
| 2142 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2144 | boolean reportNewConfig = false; |
| 2145 | WindowState attachedWindow = null; |
| 2146 | WindowState win = null; |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2147 | long origId; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2148 | final int type = attrs.type; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2150 | synchronized(mWindowMap) { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 2151 | if (!mDisplayReady) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2152 | throw new IllegalStateException("Display has not been initialialized"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2153 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2154 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 2155 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
| 2156 | if (displayContent == null) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 2157 | Slog.w(TAG, "Attempted to add window to a display that does not exist: " |
| 2158 | + displayId + ". Aborting."); |
| 2159 | return WindowManagerGlobal.ADD_INVALID_DISPLAY; |
| 2160 | } |
| 2161 | if (!displayContent.hasAccess(session.mUid)) { |
| 2162 | Slog.w(TAG, "Attempted to add window to a display for which the application " |
| 2163 | + "does not have access: " + displayId + ". Aborting."); |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 2164 | return WindowManagerGlobal.ADD_INVALID_DISPLAY; |
| 2165 | } |
| 2166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2167 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2168 | Slog.w(TAG, "Window " + client + " is already added"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2169 | return WindowManagerGlobal.ADD_DUPLICATE_ADD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2170 | } |
| 2171 | |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2172 | if (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2173 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2174 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2175 | 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] | 2176 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2177 | return WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2178 | } |
| 2179 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2180 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2181 | 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] | 2182 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2183 | return WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2184 | } |
| 2185 | } |
| 2186 | |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2187 | if (type == TYPE_PRIVATE_PRESENTATION && !displayContent.isPrivate()) { |
| 2188 | Slog.w(TAG, "Attempted to add private presentation window to a non-private display. Aborting."); |
| 2189 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
| 2190 | } |
| 2191 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2192 | boolean addToken = false; |
| 2193 | WindowToken token = mTokenMap.get(attrs.token); |
| 2194 | if (token == null) { |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2195 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2196 | 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] | 2197 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2198 | return WindowManagerGlobal.ADD_BAD_APP_TOKEN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2199 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2200 | if (type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2201 | 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] | 2202 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2203 | return WindowManagerGlobal.ADD_BAD_APP_TOKEN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2204 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2205 | if (type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2206 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2207 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2208 | return WindowManagerGlobal.ADD_BAD_APP_TOKEN; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2209 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2210 | if (type == TYPE_DREAM) { |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 2211 | Slog.w(TAG, "Attempted to add Dream window with unknown token " |
| 2212 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2213 | return WindowManagerGlobal.ADD_BAD_APP_TOKEN; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 2214 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2215 | token = new WindowToken(this, attrs.token, -1, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2216 | addToken = true; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2217 | } else if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2218 | AppWindowToken atoken = token.appWindowToken; |
| 2219 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2220 | 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] | 2221 | + token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2222 | return WindowManagerGlobal.ADD_NOT_APP_TOKEN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2223 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2224 | 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] | 2225 | + token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2226 | return WindowManagerGlobal.ADD_APP_EXITING; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2227 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2228 | if (type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2229 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2230 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2231 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2232 | return WindowManagerGlobal.ADD_STARTING_NOT_NEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2233 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2234 | } else if (type == TYPE_INPUT_METHOD) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2235 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2236 | 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] | 2237 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2238 | return WindowManagerGlobal.ADD_BAD_APP_TOKEN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2239 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2240 | } else if (type == TYPE_WALLPAPER) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2241 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2242 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2243 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2244 | return WindowManagerGlobal.ADD_BAD_APP_TOKEN; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2245 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2246 | } else if (type == TYPE_DREAM) { |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 2247 | if (token.windowType != TYPE_DREAM) { |
| 2248 | Slog.w(TAG, "Attempted to add Dream window with bad token " |
| 2249 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2250 | return WindowManagerGlobal.ADD_BAD_APP_TOKEN; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 2251 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2252 | } |
| 2253 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2254 | win = new WindowState(this, session, client, token, |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2255 | attachedWindow, appOp[0], seq, attrs, viewVisibility, displayContent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2256 | if (win.mDeathRecipient == null) { |
| 2257 | // Client has apparently died, so there is no reason to |
| 2258 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2259 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2260 | + " that is dead, aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2261 | return WindowManagerGlobal.ADD_APP_EXITING; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2262 | } |
| 2263 | |
Craig Mautner | d3849f5 | 2014-03-27 13:19:29 -0700 | [diff] [blame] | 2264 | if (win.getDisplayContent() == null) { |
| 2265 | Slog.w(TAG, "Adding window to Display that has been removed."); |
| 2266 | return WindowManagerGlobal.ADD_INVALID_DISPLAY; |
| 2267 | } |
| 2268 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2269 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2270 | win.setShowToOwnerOnlyLocked(mPolicy.checkShowToOwnerOnly(attrs)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2272 | res = mPolicy.prepareAddWindowLw(win, attrs); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2273 | if (res != WindowManagerGlobal.ADD_OKAY) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2274 | return res; |
| 2275 | } |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 2276 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2277 | if (outInputChannel != null && (attrs.inputFeatures |
| 2278 | & WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2279 | String name = win.makeInputChannelName(); |
| 2280 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2281 | win.setInputChannel(inputChannels[0]); |
Jeff Brown | 0a0ab12 | 2011-08-12 18:08:08 -0700 | [diff] [blame] | 2282 | inputChannels[1].transferTo(outInputChannel); |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 2283 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 2284 | mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2285 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2286 | |
| 2287 | // From now on, no exceptions or errors allowed! |
| 2288 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2289 | res = WindowManagerGlobal.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2290 | |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2291 | origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2292 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2293 | if (addToken) { |
| 2294 | mTokenMap.put(attrs.token, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2295 | } |
| 2296 | win.attach(); |
| 2297 | mWindowMap.put(client.asBinder(), win); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2298 | if (win.mAppOp != AppOpsManager.OP_NONE) { |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2299 | if (mAppOps.startOpNoThrow(win.mAppOp, win.getOwningUid(), win.getOwningPackage()) |
| 2300 | != AppOpsManager.MODE_ALLOWED) { |
| 2301 | win.setAppOpVisibilityLw(false); |
| 2302 | } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2303 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2304 | |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2305 | if (type == TYPE_APPLICATION_STARTING && token.appWindowToken != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2306 | token.appWindowToken.startingWindow = win; |
Craig Mautner | 38b2478 | 2012-07-02 16:21:28 -0700 | [diff] [blame] | 2307 | if (DEBUG_STARTING_WINDOW) Slog.v (TAG, "addWindow: " + token.appWindowToken |
| 2308 | + " startingWindow=" + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2312 | |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2313 | if (type == TYPE_INPUT_METHOD) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 2314 | win.mGivenInsetsPending = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2315 | mInputMethodWindow = win; |
| 2316 | addInputMethodWindowToListLocked(win); |
| 2317 | imMayMove = false; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2318 | } else if (type == TYPE_INPUT_METHOD_DIALOG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2319 | mInputMethodDialogs.add(win); |
| 2320 | addWindowToListInOrderLocked(win, true); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 2321 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2322 | imMayMove = false; |
| 2323 | } else { |
| 2324 | addWindowToListInOrderLocked(win, true); |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2325 | if (type == TYPE_WALLPAPER) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2326 | mLastWallpaperTimeoutTime = 0; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 2327 | displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2328 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 2329 | displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 2330 | } else if (mWallpaperTarget != null |
| 2331 | && mWallpaperTarget.mLayer >= win.mBaseLayer) { |
| 2332 | // If there is currently a wallpaper being shown, and |
| 2333 | // the base layer of the new window is below the current |
| 2334 | // layer of the target window, then adjust the wallpaper. |
| 2335 | // This is to avoid a new window being placed between the |
| 2336 | // wallpaper and its target. |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 2337 | displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2338 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2339 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2340 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2341 | win.mWinAnimator.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2342 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2343 | if (displayContent.isDefaultDisplay) { |
| 2344 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| 2345 | } else { |
| 2346 | outContentInsets.setEmpty(); |
| 2347 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2349 | if (mInTouchMode) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2350 | res |= WindowManagerGlobal.ADD_FLAG_IN_TOUCH_MODE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2351 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 2352 | if (win.mAppToken == null || !win.mAppToken.clientHidden) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2353 | res |= WindowManagerGlobal.ADD_FLAG_APP_VISIBLE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2354 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2355 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2356 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 2357 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2358 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2359 | if (win.canReceiveKeys()) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2360 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS, |
| 2361 | false /*updateInputWindows*/); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2362 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2363 | imMayMove = false; |
| 2364 | } |
| 2365 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2367 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2368 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2369 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2370 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2371 | assignLayersLocked(displayContent.getWindowList()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2372 | // Don't do layout here, the window must call |
| 2373 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2374 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2375 | if (focusChanged) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2376 | finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2377 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2378 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2379 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2380 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2381 | TAG, "New client " + client.asBinder() |
| 2382 | + ": window=" + win); |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 2383 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2384 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2385 | reportNewConfig = true; |
| 2386 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2387 | } |
| 2388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2389 | if (reportNewConfig) { |
| 2390 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2391 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2392 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2393 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2394 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | return res; |
| 2396 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2397 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2398 | public void removeWindow(Session session, IWindow client) { |
| 2399 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2400 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2401 | if (win == null) { |
| 2402 | return; |
| 2403 | } |
| 2404 | removeWindowLocked(session, win); |
| 2405 | } |
| 2406 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2408 | public void removeWindowLocked(Session session, WindowState win) { |
Craig Mautner | 68cc241 | 2013-10-01 10:39:43 -0700 | [diff] [blame] | 2409 | if (win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 2410 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "Starting window removed " + win); |
Craig Mautner | 68cc241 | 2013-10-01 10:39:43 -0700 | [diff] [blame] | 2411 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2412 | |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 2413 | if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && win==mCurrentFocus) Slog.v( |
Craig Mautner | e2dd83a | 2013-10-07 17:01:41 -0700 | [diff] [blame] | 2414 | TAG, "Remove " + win + " client=" |
| 2415 | + Integer.toHexString(System.identityHashCode(win.mClient.asBinder())) |
| 2416 | + ", surface=" + win.mWinAnimator.mSurfaceControl + " Callers=" |
| 2417 | + Debug.getCallers(4)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2418 | |
| 2419 | final long origId = Binder.clearCallingIdentity(); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 2420 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2421 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2422 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2423 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 2424 | TAG, "Remove " + win + ": mSurface=" + win.mWinAnimator.mSurfaceControl |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2425 | + " mExiting=" + win.mExiting |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2426 | + " isAnimating=" + win.mWinAnimator.isAnimating() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2427 | + " app-animation=" |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 2428 | + (win.mAppToken != null ? win.mAppToken.mAppAnimator.animation : null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2429 | + " inPendingTransaction=" |
| 2430 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2431 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2432 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2433 | boolean wasVisible = false; |
| 2434 | // First, see if we need to run an animation. If we do, we have |
| 2435 | // to hold off on removing the window until the animation is done. |
| 2436 | // If the display is frozen, just remove immediately, since the |
| 2437 | // animation wouldn't be seen. |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2438 | if (win.mHasSurface && okToDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2439 | // If we are not currently running the exit animation, we |
| 2440 | // need to see about starting one. |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 2441 | wasVisible = win.isWinVisibleLw(); |
| 2442 | if (wasVisible) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2444 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 2445 | if (win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2446 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2447 | } |
| 2448 | // Try starting an animation. |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2449 | if (win.mWinAnimator.applyAnimationLocked(transit, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | win.mExiting = true; |
| 2451 | } |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 2452 | //TODO (multidisplay): Magnification is supported only for the default display. |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 2453 | if (mAccessibilityController != null |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 2454 | && win.getDisplayId() == Display.DEFAULT_DISPLAY) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 2455 | mAccessibilityController.onWindowTransitionLocked(win, transit); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2456 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2457 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2458 | if (win.mExiting || win.mWinAnimator.isAnimating()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2459 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2460 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2461 | win.mExiting = true; |
| 2462 | win.mRemoveOnExit = true; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2463 | final DisplayContent displayContent = win.getDisplayContent(); |
| 2464 | if (displayContent != null) { |
| 2465 | displayContent.layoutNeeded = true; |
| 2466 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2467 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2468 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2469 | performLayoutAndPlaceSurfacesLocked(); |
| 2470 | if (win.mAppToken != null) { |
| 2471 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2472 | } |
| 2473 | //dump(); |
| 2474 | Binder.restoreCallingIdentity(origId); |
| 2475 | return; |
| 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | removeWindowInnerLocked(session, win); |
| 2480 | // Removing a visible window will effect the computed orientation |
| 2481 | // So just update orientation if needed. |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 2482 | if (wasVisible && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2483 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2484 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2485 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2486 | Binder.restoreCallingIdentity(origId); |
| 2487 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2488 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2489 | private void removeWindowInnerLocked(Session session, WindowState win) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2490 | if (win.mRemoved) { |
| 2491 | // Nothing to do. |
| 2492 | return; |
| 2493 | } |
| 2494 | |
| 2495 | for (int i=win.mChildWindows.size()-1; i>=0; i--) { |
| 2496 | WindowState cwin = win.mChildWindows.get(i); |
| 2497 | Slog.w(TAG, "Force-removing child win " + cwin + " from container " |
| 2498 | + win); |
| 2499 | removeWindowInnerLocked(cwin.mSession, cwin); |
| 2500 | } |
| 2501 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2503 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2504 | if (mInputMethodTarget == win) { |
| 2505 | moveInputMethodWindowsIfNeededLocked(false); |
| 2506 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2507 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2508 | if (false) { |
| 2509 | RuntimeException e = new RuntimeException("here"); |
| 2510 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2511 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2512 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2514 | mPolicy.removeWindowLw(win); |
| 2515 | win.removeLocked(); |
| 2516 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2517 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2518 | mWindowMap.remove(win.mClient.asBinder()); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2519 | if (win.mAppOp != AppOpsManager.OP_NONE) { |
| 2520 | mAppOps.finishOp(win.mAppOp, win.getOwningUid(), win.getOwningPackage()); |
| 2521 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2522 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2523 | mPendingRemove.remove(win); |
Craig Mautner | 860f660 | 2012-10-18 09:38:10 -0700 | [diff] [blame] | 2524 | mResizingWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2525 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2526 | 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] | 2527 | |
| 2528 | if (mInputMethodWindow == win) { |
| 2529 | mInputMethodWindow = null; |
| 2530 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2531 | mInputMethodDialogs.remove(win); |
| 2532 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2533 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2534 | final WindowToken token = win.mToken; |
| 2535 | final AppWindowToken atoken = win.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2536 | 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] | 2537 | token.windows.remove(win); |
| 2538 | if (atoken != null) { |
| 2539 | atoken.allAppWindows.remove(win); |
| 2540 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2541 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2542 | TAG, "**** Removing window " + win + ": count=" |
| 2543 | + token.windows.size()); |
| 2544 | if (token.windows.size() == 0) { |
| 2545 | if (!token.explicit) { |
| 2546 | mTokenMap.remove(token.token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2547 | } else if (atoken != null) { |
| 2548 | atoken.firstWindowDrawn = false; |
| 2549 | } |
| 2550 | } |
| 2551 | |
| 2552 | if (atoken != null) { |
| 2553 | if (atoken.startingWindow == win) { |
Craig Mautner | 38b2478 | 2012-07-02 16:21:28 -0700 | [diff] [blame] | 2554 | 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] | 2555 | atoken.startingWindow = null; |
| 2556 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2557 | // If this is the last window and we had requested a starting |
| 2558 | // transition window, well there is no point now. |
Craig Mautner | 38b2478 | 2012-07-02 16:21:28 -0700 | [diff] [blame] | 2559 | 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] | 2560 | atoken.startingData = null; |
| 2561 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2562 | // If this is the last window except for a starting transition |
| 2563 | // window, we need to get rid of the starting transition. |
Craig Mautner | 68cc241 | 2013-10-01 10:39:43 -0700 | [diff] [blame] | 2564 | scheduleRemoveStartingWindow(atoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2565 | } |
| 2566 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2567 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2568 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2569 | mLastWallpaperTimeoutTime = 0; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 2570 | getDefaultDisplayContentLocked().pendingLayoutChanges |= |
| 2571 | WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2572 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 2573 | getDefaultDisplayContentLocked().pendingLayoutChanges |= |
| 2574 | WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2575 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2576 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2577 | final WindowList windows = win.getWindowList(); |
| 2578 | if (windows != null) { |
| 2579 | windows.remove(win); |
| 2580 | if (!mInLayout) { |
| 2581 | assignLayersLocked(windows); |
| 2582 | final DisplayContent displayContent = win.getDisplayContent(); |
| 2583 | if (displayContent != null) { |
| 2584 | displayContent.layoutNeeded = true; |
| 2585 | } |
| 2586 | performLayoutAndPlaceSurfacesLocked(); |
| 2587 | if (win.mAppToken != null) { |
| 2588 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2589 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2590 | } |
| 2591 | } |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 2592 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2593 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2594 | } |
| 2595 | |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2596 | public void updateAppOpsState() { |
| 2597 | synchronized(mWindowMap) { |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 2598 | final int numDisplays = mDisplayContents.size(); |
| 2599 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 2600 | final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList(); |
| 2601 | final int numWindows = windows.size(); |
| 2602 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 2603 | final WindowState win = windows.get(winNdx); |
| 2604 | if (win.mAppOp != AppOpsManager.OP_NONE) { |
| 2605 | final int mode = mAppOps.checkOpNoThrow(win.mAppOp, win.getOwningUid(), |
| 2606 | win.getOwningPackage()); |
| 2607 | win.setAppOpVisibilityLw(mode == AppOpsManager.MODE_ALLOWED); |
| 2608 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2609 | } |
| 2610 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2611 | } |
| 2612 | } |
| 2613 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2614 | static void logSurface(WindowState w, String msg, RuntimeException where) { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2615 | String str = " SURFACE " + msg + ": " + w; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2616 | if (where != null) { |
| 2617 | Slog.i(TAG, str, where); |
| 2618 | } else { |
| 2619 | Slog.i(TAG, str); |
| 2620 | } |
| 2621 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2622 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 2623 | static void logSurface(SurfaceControl s, String title, String msg, RuntimeException where) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2624 | String str = " SURFACE " + s + ": " + msg + " / " + title; |
| 2625 | if (where != null) { |
| 2626 | Slog.i(TAG, str, where); |
| 2627 | } else { |
| 2628 | Slog.i(TAG, str); |
| 2629 | } |
| 2630 | } |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 2631 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2632 | void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2633 | long origId = Binder.clearCallingIdentity(); |
| 2634 | try { |
| 2635 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2636 | WindowState w = windowForClientLocked(session, client, false); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2637 | if ((w != null) && w.mHasSurface) { |
Craig Mautner | ef65501 | 2013-01-03 11:20:24 -0800 | [diff] [blame] | 2638 | w.mWinAnimator.setTransparentRegionHintLocked(region); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2639 | } |
| 2640 | } |
| 2641 | } finally { |
| 2642 | Binder.restoreCallingIdentity(origId); |
| 2643 | } |
| 2644 | } |
| 2645 | |
| 2646 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2647 | int touchableInsets, Rect contentInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2648 | Rect visibleInsets, Region touchableRegion) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2649 | long origId = Binder.clearCallingIdentity(); |
| 2650 | try { |
| 2651 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2652 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2653 | if (w != null) { |
| 2654 | w.mGivenInsetsPending = false; |
| 2655 | w.mGivenContentInsets.set(contentInsets); |
| 2656 | w.mGivenVisibleInsets.set(visibleInsets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2657 | w.mGivenTouchableRegion.set(touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2658 | w.mTouchableInsets = touchableInsets; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2659 | if (w.mGlobalScale != 1) { |
| 2660 | w.mGivenContentInsets.scale(w.mGlobalScale); |
| 2661 | w.mGivenVisibleInsets.scale(w.mGlobalScale); |
| 2662 | w.mGivenTouchableRegion.scale(w.mGlobalScale); |
| 2663 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2664 | final DisplayContent displayContent = w.getDisplayContent(); |
| 2665 | if (displayContent != null) { |
| 2666 | displayContent.layoutNeeded = true; |
| 2667 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2668 | performLayoutAndPlaceSurfacesLocked(); |
| 2669 | } |
| 2670 | } |
| 2671 | } finally { |
| 2672 | Binder.restoreCallingIdentity(origId); |
| 2673 | } |
| 2674 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2675 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2676 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2677 | Rect outDisplayFrame) { |
| 2678 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2679 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2680 | if (win == null) { |
| 2681 | outDisplayFrame.setEmpty(); |
| 2682 | return; |
| 2683 | } |
| 2684 | outDisplayFrame.set(win.mDisplayFrame); |
| 2685 | } |
| 2686 | } |
| 2687 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2688 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2689 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2690 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2691 | window.mWallpaperX = x; |
| 2692 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2693 | window.mWallpaperXStep = xStep; |
| 2694 | window.mWallpaperYStep = yStep; |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 2695 | updateWallpaperOffsetLocked(window, true); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2696 | } |
| 2697 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2698 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2699 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2700 | synchronized (mWindowMap) { |
| 2701 | if (mWaitingOnWallpaper != null && |
| 2702 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2703 | mWaitingOnWallpaper = null; |
| 2704 | mWindowMap.notifyAll(); |
| 2705 | } |
| 2706 | } |
| 2707 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2708 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2709 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2710 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2711 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2712 | || window == mUpperWallpaperTarget) { |
| 2713 | boolean doWait = sync; |
| 2714 | int curTokenIndex = mWallpaperTokens.size(); |
| 2715 | while (curTokenIndex > 0) { |
| 2716 | curTokenIndex--; |
| 2717 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2718 | int curWallpaperIndex = token.windows.size(); |
| 2719 | while (curWallpaperIndex > 0) { |
| 2720 | curWallpaperIndex--; |
| 2721 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2722 | try { |
| 2723 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2724 | x, y, z, extras, sync); |
| 2725 | // We only want to be synchronous with one wallpaper. |
| 2726 | sync = false; |
| 2727 | } catch (RemoteException e) { |
| 2728 | } |
| 2729 | } |
| 2730 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2731 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2732 | if (doWait) { |
| 2733 | // XXX Need to wait for result. |
| 2734 | } |
| 2735 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2736 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2737 | return null; |
| 2738 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2739 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 2740 | public void setUniverseTransformLocked(WindowState window, float alpha, |
| 2741 | float offx, float offy, float dsdx, float dtdx, float dsdy, float dtdy) { |
| 2742 | Transformation transform = window.mWinAnimator.mUniverseTransform; |
| 2743 | transform.setAlpha(alpha); |
| 2744 | Matrix matrix = transform.getMatrix(); |
| 2745 | matrix.getValues(mTmpFloats); |
| 2746 | mTmpFloats[Matrix.MTRANS_X] = offx; |
| 2747 | mTmpFloats[Matrix.MTRANS_Y] = offy; |
| 2748 | mTmpFloats[Matrix.MSCALE_X] = dsdx; |
| 2749 | mTmpFloats[Matrix.MSKEW_Y] = dtdx; |
| 2750 | mTmpFloats[Matrix.MSKEW_X] = dsdy; |
| 2751 | mTmpFloats[Matrix.MSCALE_Y] = dtdy; |
| 2752 | matrix.setValues(mTmpFloats); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2753 | final DisplayContent displayContent = window.getDisplayContent(); |
| 2754 | if (displayContent == null) { |
| 2755 | return; |
| 2756 | } |
| 2757 | |
Craig Mautner | d3849f5 | 2014-03-27 13:19:29 -0700 | [diff] [blame] | 2758 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 2759 | final RectF dispRect = new RectF(0, 0, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2760 | displayInfo.logicalWidth, displayInfo.logicalHeight); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 2761 | matrix.mapRect(dispRect); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 2762 | window.mGivenTouchableRegion.set(0, 0, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2763 | displayInfo.logicalWidth, displayInfo.logicalHeight); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 2764 | window.mGivenTouchableRegion.op((int)dispRect.left, (int)dispRect.top, |
| 2765 | (int)dispRect.right, (int)dispRect.bottom, Region.Op.DIFFERENCE); |
| 2766 | window.mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2767 | displayContent.layoutNeeded = true; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 2768 | performLayoutAndPlaceSurfacesLocked(); |
| 2769 | } |
| 2770 | |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 2771 | public void onRectangleOnScreenRequested(IBinder token, Rect rectangle, boolean immediate) { |
| 2772 | synchronized (mWindowMap) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 2773 | if (mAccessibilityController != null) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 2774 | WindowState window = mWindowMap.get(token); |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 2775 | //TODO (multidisplay): Magnification is supported only for the default display. |
| 2776 | if (window != null && window.getDisplayId() == Display.DEFAULT_DISPLAY) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 2777 | mAccessibilityController.onRectangleOnScreenRequestedLocked(rectangle, |
| 2778 | immediate); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 2779 | } |
| 2780 | } |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 2781 | } |
| 2782 | } |
| 2783 | |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 2784 | public IWindowId getWindowId(IBinder token) { |
| 2785 | synchronized (mWindowMap) { |
| 2786 | WindowState window = mWindowMap.get(token); |
| 2787 | return window != null ? window.mWindowId : null; |
| 2788 | } |
| 2789 | } |
| 2790 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2791 | public int relayoutWindow(Session session, IWindow client, int seq, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2792 | WindowManager.LayoutParams attrs, int requestedWidth, |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2793 | int requestedHeight, int viewVisibility, int flags, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2794 | Rect outFrame, Rect outOverscanInsets, Rect outContentInsets, |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2795 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2796 | boolean toBeDisplayed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2797 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2798 | boolean configChanged; |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2799 | boolean surfaceChanged = false; |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 2800 | boolean animating; |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 2801 | |
| 2802 | // 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] | 2803 | int systemUiVisibility = 0; |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 2804 | if (attrs != null) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2805 | systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility); |
| 2806 | if ((systemUiVisibility & StatusBarManager.DISABLE_MASK) != 0) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2807 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR) |
| 2808 | != PackageManager.PERMISSION_GRANTED) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2809 | systemUiVisibility &= ~StatusBarManager.DISABLE_MASK; |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2810 | } |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 2811 | } |
| 2812 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2813 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2814 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2815 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2816 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2817 | if (win == null) { |
| 2818 | return 0; |
| 2819 | } |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2820 | WindowStateAnimator winAnimator = win.mWinAnimator; |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 2821 | if (win.mRequestedWidth != requestedWidth |
| 2822 | || win.mRequestedHeight != requestedHeight) { |
| 2823 | win.mLayoutNeeded = true; |
| 2824 | win.mRequestedWidth = requestedWidth; |
| 2825 | win.mRequestedHeight = requestedHeight; |
| 2826 | } |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2827 | if (attrs != null && seq == win.mSeq) { |
| 2828 | win.mSystemUiVisibility = systemUiVisibility; |
| 2829 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2830 | |
| 2831 | if (attrs != null) { |
| 2832 | mPolicy.adjustWindowParamsLw(attrs); |
| 2833 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2834 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2835 | winAnimator.mSurfaceDestroyDeferred = |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2836 | (flags&WindowManagerGlobal.RELAYOUT_DEFER_SURFACE_DESTROY) != 0; |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2837 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2838 | int attrChanges = 0; |
| 2839 | int flagChanges = 0; |
| 2840 | if (attrs != null) { |
Dianne Hackborn | 0e60db2 | 2011-09-01 11:17:57 -0700 | [diff] [blame] | 2841 | if (win.mAttrs.type != attrs.type) { |
| 2842 | throw new IllegalArgumentException( |
| 2843 | "Window type can not be changed after the window is added."); |
| 2844 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2845 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2846 | attrChanges = win.mAttrs.copyFrom(attrs); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2847 | if ((attrChanges & (WindowManager.LayoutParams.LAYOUT_CHANGED |
| 2848 | | WindowManager.LayoutParams.SYSTEM_UI_VISIBILITY_CHANGED)) != 0) { |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 2849 | win.mLayoutNeeded = true; |
| 2850 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2851 | } |
| 2852 | |
Dianne Hackborn | 7ff3011 | 2012-11-08 11:12:09 -0800 | [diff] [blame] | 2853 | if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": viewVisibility=" + viewVisibility |
Chet Haase | d5d11af | 2012-10-31 08:57:17 -0700 | [diff] [blame] | 2854 | + " req=" + requestedWidth + "x" + requestedHeight + " " + win.mAttrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2855 | |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2856 | win.mEnforceSizeCompat = |
| 2857 | (win.mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2858 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2859 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2860 | winAnimator.mAlpha = attrs.alpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | final boolean scaledWindow = |
| 2864 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2865 | |
| 2866 | if (scaledWindow) { |
| 2867 | // requested{Width|Height} Surface's physical size |
| 2868 | // attrs.{width|height} Size on screen |
| 2869 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2870 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2871 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2872 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2873 | } else { |
| 2874 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2875 | } |
| 2876 | |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 2877 | boolean imMayMove = (flagChanges & (FLAG_ALT_FOCUSABLE_IM | FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2878 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2879 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 2880 | boolean focusMayChange = isDefaultDisplay && (win.mViewVisibility != viewVisibility |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 2881 | || ((flagChanges & FLAG_NOT_FOCUSABLE) != 0) |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2882 | || (!win.mRelayoutCalled)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2883 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2884 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2885 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 2886 | wallpaperMayMove |= (flagChanges & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2887 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2888 | win.mRelayoutCalled = true; |
| 2889 | final int oldVisibility = win.mViewVisibility; |
| 2890 | win.mViewVisibility = viewVisibility; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 2891 | if (DEBUG_SCREEN_ON) { |
| 2892 | RuntimeException stack = new RuntimeException(); |
| 2893 | stack.fillInStackTrace(); |
| 2894 | Slog.i(TAG, "Relayout " + win + ": oldVis=" + oldVisibility |
| 2895 | + " newVis=" + viewVisibility, stack); |
| 2896 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2897 | if (viewVisibility == View.VISIBLE && |
| 2898 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2899 | toBeDisplayed = !win.isVisibleLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2900 | if (win.mExiting) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2901 | winAnimator.cancelExitAnimationForNextAnimationLocked(); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2902 | win.mExiting = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2903 | } |
| 2904 | if (win.mDestroying) { |
| 2905 | win.mDestroying = false; |
| 2906 | mDestroySurface.remove(win); |
| 2907 | } |
| 2908 | if (oldVisibility == View.GONE) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2909 | winAnimator.mEnterAnimationPending = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2910 | } |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2911 | if (toBeDisplayed) { |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 2912 | if (win.isDrawnLw() && okToDisplay()) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2913 | winAnimator.applyEnterAnimationLocked(); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2914 | } |
| 2915 | if ((win.mAttrs.flags |
| 2916 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2917 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2918 | "Relayout window turning screen on: " + win); |
| 2919 | win.mTurnOnScreen = true; |
| 2920 | } |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2921 | if (win.isConfigChanged()) { |
| 2922 | if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + win |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 2923 | + " visible with new config: " + mCurConfiguration); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2924 | outConfig.setTo(mCurConfiguration); |
| 2925 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2926 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2927 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2928 | // To change the format, we need to re-build the surface. |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 2929 | winAnimator.destroySurfaceLocked(); |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2930 | toBeDisplayed = true; |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2931 | surfaceChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2932 | } |
| 2933 | try { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2934 | if (!win.mHasSurface) { |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2935 | surfaceChanged = true; |
| 2936 | } |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 2937 | SurfaceControl surfaceControl = winAnimator.createSurfaceLocked(); |
| 2938 | if (surfaceControl != null) { |
| 2939 | outSurface.copyFrom(surfaceControl); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2940 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2941 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2942 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2943 | // For some reason there isn't a surface. Clear the |
| 2944 | // caller's object so they see the same state. |
| 2945 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2946 | } |
| 2947 | } catch (Exception e) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2948 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 2949 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2950 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2951 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2952 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2953 | Binder.restoreCallingIdentity(origId); |
| 2954 | return 0; |
| 2955 | } |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2956 | if (toBeDisplayed) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2957 | focusMayChange = isDefaultDisplay; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2958 | } |
| 2959 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2960 | && mInputMethodWindow == null) { |
| 2961 | mInputMethodWindow = win; |
| 2962 | imMayMove = true; |
| 2963 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2964 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2965 | && win.mAppToken != null |
| 2966 | && win.mAppToken.startingWindow != null) { |
| 2967 | // Special handling of starting window over the base |
| 2968 | // window of the app: propagate lock screen flags to it, |
| 2969 | // to provide the correct semantics while starting. |
| 2970 | final int mask = |
| 2971 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2972 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2973 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2974 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2975 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2976 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2977 | } else { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2978 | winAnimator.mEnterAnimationPending = false; |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 2979 | if (winAnimator.mSurfaceControl != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2980 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2981 | + ": mExiting=" + win.mExiting); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2982 | // If we are not currently running the exit animation, we |
| 2983 | // need to see about starting one. |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2984 | if (!win.mExiting) { |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2985 | surfaceChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | // Try starting an animation; if there isn't one, we |
| 2987 | // can destroy the surface right away. |
| 2988 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 2989 | if (win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2990 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2991 | } |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2992 | if (win.isWinVisibleLw() && |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2993 | winAnimator.applyAnimationLocked(transit, false)) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2994 | focusMayChange = isDefaultDisplay; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2995 | win.mExiting = true; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2996 | } else if (win.mWinAnimator.isAnimating()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2997 | // Currently in a hide animation... turn this into |
| 2998 | // an exit. |
| 2999 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3000 | } else if (win == mWallpaperTarget) { |
| 3001 | // If the wallpaper is currently behind this |
| 3002 | // window, we need to change both of them inside |
| 3003 | // of a transaction to avoid artifacts. |
| 3004 | win.mExiting = true; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 3005 | win.mWinAnimator.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3006 | } else { |
| 3007 | if (mInputMethodWindow == win) { |
| 3008 | mInputMethodWindow = null; |
| 3009 | } |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 3010 | winAnimator.destroySurfaceLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3011 | } |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 3012 | //TODO (multidisplay): Magnification is supported only for the default |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 3013 | if (mAccessibilityController != null |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 3014 | && win.getDisplayId() == Display.DEFAULT_DISPLAY) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 3015 | mAccessibilityController.onWindowTransitionLocked(win, transit); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 3016 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3017 | } |
| 3018 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3019 | |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 3020 | outSurface.release(); |
| 3021 | 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] | 3022 | } |
| 3023 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3024 | if (focusMayChange) { |
| 3025 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3026 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 3027 | false /*updateInputWindows*/)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3028 | imMayMove = false; |
| 3029 | } |
| 3030 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 3031 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3032 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 3033 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 3034 | // reassign them at this point if the IM window state gets shuffled |
Craig Mautner | b5eb550 | 2013-01-10 17:29:30 -0800 | [diff] [blame] | 3035 | if (imMayMove && (moveInputMethodWindowsIfNeededLocked(false) || toBeDisplayed)) { |
| 3036 | // Little hack here -- we -should- be able to rely on the |
| 3037 | // function to return true if the IME has moved and needs |
| 3038 | // its layer recomputed. However, if the IME was hidden |
| 3039 | // and isn't actually moved in the list, its layer may be |
| 3040 | // out of data so we make sure to recompute it. |
| 3041 | assignLayersLocked(win.getWindowList()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3042 | } |
Craig Mautner | b5eb550 | 2013-01-10 17:29:30 -0800 | [diff] [blame] | 3043 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3044 | if (wallpaperMayMove) { |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 3045 | getDefaultDisplayContentLocked().pendingLayoutChanges |= |
| 3046 | WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3047 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3048 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3049 | final DisplayContent displayContent = win.getDisplayContent(); |
| 3050 | if (displayContent != null) { |
| 3051 | displayContent.layoutNeeded = true; |
| 3052 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3053 | win.mGivenInsetsPending = (flags&WindowManagerGlobal.RELAYOUT_INSETS_PENDING) != 0; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3054 | configChanged = updateOrientationFromAppTokensLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3055 | performLayoutAndPlaceSurfacesLocked(); |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 3056 | if (toBeDisplayed && win.mIsWallpaper) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3057 | DisplayInfo displayInfo = getDefaultDisplayInfoLocked(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 3058 | updateWallpaperOffsetLocked(win, |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3059 | displayInfo.logicalWidth, displayInfo.logicalHeight, false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3060 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3061 | if (win.mAppToken != null) { |
| 3062 | win.mAppToken.updateReportedVisibilityLocked(); |
| 3063 | } |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3064 | outFrame.set(win.mCompatFrame); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3065 | outOverscanInsets.set(win.mOverscanInsets); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3066 | outContentInsets.set(win.mContentInsets); |
| 3067 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3068 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3069 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3070 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3071 | + ", requestedHeight=" + requestedHeight |
| 3072 | + ", viewVisibility=" + viewVisibility |
| 3073 | + "\nRelayout returning frame=" + outFrame |
| 3074 | + ", surface=" + outSurface); |
| 3075 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3076 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3077 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 3078 | |
| 3079 | inTouchMode = mInTouchMode; |
Dianne Hackborn | 021d243 | 2013-10-13 15:20:09 -0700 | [diff] [blame] | 3080 | animating = mAnimator.mAnimating && win.mWinAnimator.isAnimating(); |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 3081 | if (animating && !mRelayoutWhileAnimating.contains(win)) { |
| 3082 | mRelayoutWhileAnimating.add(win); |
| 3083 | } |
| 3084 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 3085 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Chet Haase | d5d11af | 2012-10-31 08:57:17 -0700 | [diff] [blame] | 3086 | |
| 3087 | if (DEBUG_LAYOUT) { |
| 3088 | Slog.v(TAG, "Relayout complete " + win + ": outFrame=" + outFrame.toShortString()); |
| 3089 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3090 | } |
| 3091 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3092 | if (configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3093 | sendNewConfiguration(); |
| 3094 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3095 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3096 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3097 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3098 | return (inTouchMode ? WindowManagerGlobal.RELAYOUT_RES_IN_TOUCH_MODE : 0) |
| 3099 | | (toBeDisplayed ? WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME : 0) |
| 3100 | | (surfaceChanged ? WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED : 0) |
| 3101 | | (animating ? WindowManagerGlobal.RELAYOUT_RES_ANIMATING : 0); |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | public void performDeferredDestroyWindow(Session session, IWindow client) { |
| 3105 | long origId = Binder.clearCallingIdentity(); |
| 3106 | |
| 3107 | try { |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 3108 | synchronized (mWindowMap) { |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 3109 | WindowState win = windowForClientLocked(session, client, false); |
| 3110 | if (win == null) { |
| 3111 | return; |
| 3112 | } |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 3113 | win.mWinAnimator.destroyDeferredSurfaceLocked(); |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 3114 | } |
| 3115 | } finally { |
| 3116 | Binder.restoreCallingIdentity(origId); |
| 3117 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3118 | } |
| 3119 | |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3120 | public boolean outOfMemoryWindow(Session session, IWindow client) { |
| 3121 | long origId = Binder.clearCallingIdentity(); |
| 3122 | |
| 3123 | try { |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 3124 | synchronized (mWindowMap) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3125 | WindowState win = windowForClientLocked(session, client, false); |
| 3126 | if (win == null) { |
| 3127 | return false; |
| 3128 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 3129 | return reclaimSomeSurfaceMemoryLocked(win.mWinAnimator, "from-client", false); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3130 | } |
| 3131 | } finally { |
| 3132 | Binder.restoreCallingIdentity(origId); |
| 3133 | } |
| 3134 | } |
| 3135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3136 | public void finishDrawingWindow(Session session, IWindow client) { |
| 3137 | final long origId = Binder.clearCallingIdentity(); |
Craig Mautner | ef65501 | 2013-01-03 11:20:24 -0800 | [diff] [blame] | 3138 | try { |
| 3139 | synchronized (mWindowMap) { |
| 3140 | WindowState win = windowForClientLocked(session, client, false); |
| 3141 | if (win != null && win.mWinAnimator.finishDrawingLocked()) { |
| 3142 | if ((win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 3143 | getDefaultDisplayContentLocked().pendingLayoutChanges |= |
| 3144 | WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
| 3145 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3146 | final DisplayContent displayContent = win.getDisplayContent(); |
| 3147 | if (displayContent != null) { |
| 3148 | displayContent.layoutNeeded = true; |
| 3149 | } |
Craig Mautner | ef65501 | 2013-01-03 11:20:24 -0800 | [diff] [blame] | 3150 | requestTraversalLocked(); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 3151 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3152 | } |
Craig Mautner | ef65501 | 2013-01-03 11:20:24 -0800 | [diff] [blame] | 3153 | } finally { |
| 3154 | Binder.restoreCallingIdentity(origId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3155 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3156 | } |
| 3157 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3158 | private boolean applyAnimationLocked(AppWindowToken atoken, |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3159 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3160 | // Only apply an animation if the display isn't frozen. If it is |
| 3161 | // frozen, there is no reason to animate and it can cause strange |
| 3162 | // artifacts when we unfreeze the display if some different animation |
| 3163 | // is running. |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 3164 | if (okToDisplay()) { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 3165 | DisplayInfo displayInfo = getDefaultDisplayInfoLocked(); |
Craig Mautner | 9339c40 | 2012-11-30 11:23:56 -0800 | [diff] [blame] | 3166 | final int width = displayInfo.appWidth; |
| 3167 | final int height = displayInfo.appHeight; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 3168 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "applyAnimation: atoken=" |
| 3169 | + atoken); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 3170 | |
| 3171 | // Determine the visible rect to calculate the thumbnail clip |
| 3172 | WindowState win = atoken.findMainWindow(); |
| 3173 | Rect containingFrame = new Rect(0, 0, width, height); |
| 3174 | Rect contentInsets = new Rect(); |
| 3175 | if (win != null) { |
| 3176 | if (win.mContainingFrame != null) { |
| 3177 | containingFrame.set(win.mContainingFrame); |
| 3178 | } |
| 3179 | if (win.mContentInsets != null) { |
| 3180 | contentInsets.set(win.mContentInsets); |
| 3181 | } |
| 3182 | } |
| 3183 | |
| 3184 | Animation a = mAppTransition.loadAnimation(lp, transit, enter, width, height, |
| 3185 | containingFrame, contentInsets); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3186 | if (a != null) { |
| 3187 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3188 | RuntimeException e = null; |
| 3189 | if (!HIDE_STACK_CRAWLS) { |
| 3190 | e = new RuntimeException(); |
| 3191 | e.fillInStackTrace(); |
| 3192 | } |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3193 | Slog.v(TAG, "Loaded animation " + a + " for " + atoken, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3194 | } |
Craig Mautner | 9339c40 | 2012-11-30 11:23:56 -0800 | [diff] [blame] | 3195 | atoken.mAppAnimator.setAnimation(a, width, height); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3196 | } |
| 3197 | } else { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3198 | atoken.mAppAnimator.clearAnimation(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3199 | } |
| 3200 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3201 | return atoken.mAppAnimator.animation != null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | // ------------------------------------------------------------- |
| 3205 | // Application Window Tokens |
| 3206 | // ------------------------------------------------------------- |
| 3207 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 3208 | public void validateAppTokens(int stackId, List<TaskGroup> tasks) { |
Craig Mautner | 343ad71 | 2013-02-13 22:37:26 -0800 | [diff] [blame] | 3209 | synchronized (mWindowMap) { |
| 3210 | int t = tasks.size() - 1; |
| 3211 | if (t < 0) { |
| 3212 | Slog.w(TAG, "validateAppTokens: empty task list"); |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 3213 | return; |
| 3214 | } |
| 3215 | |
Craig Mautner | 343ad71 | 2013-02-13 22:37:26 -0800 | [diff] [blame] | 3216 | TaskGroup task = tasks.get(0); |
| 3217 | int taskId = task.taskId; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 3218 | Task targetTask = mTaskIdToTask.get(taskId); |
| 3219 | DisplayContent displayContent = targetTask.getDisplayContent(); |
Craig Mautner | 343ad71 | 2013-02-13 22:37:26 -0800 | [diff] [blame] | 3220 | if (displayContent == null) { |
| 3221 | Slog.w(TAG, "validateAppTokens: no Display for taskId=" + taskId); |
| 3222 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3223 | } |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 3224 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 3225 | final ArrayList<Task> localTasks = mStackIdToStack.get(stackId).getTasks(); |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3226 | int taskNdx; |
| 3227 | for (taskNdx = localTasks.size() - 1; taskNdx >= 0 && t >= 0; --taskNdx, --t) { |
| 3228 | AppTokenList localTokens = localTasks.get(taskNdx).mAppTokens; |
Craig Mautner | 343ad71 | 2013-02-13 22:37:26 -0800 | [diff] [blame] | 3229 | task = tasks.get(t); |
| 3230 | List<IApplicationToken> tokens = task.tokens; |
Craig Mautner | 343ad71 | 2013-02-13 22:37:26 -0800 | [diff] [blame] | 3231 | |
| 3232 | DisplayContent lastDisplayContent = displayContent; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 3233 | displayContent = mTaskIdToTask.get(taskId).getDisplayContent(); |
Craig Mautner | 343ad71 | 2013-02-13 22:37:26 -0800 | [diff] [blame] | 3234 | if (displayContent != lastDisplayContent) { |
| 3235 | Slog.w(TAG, "validateAppTokens: displayContent changed in TaskGroup list!"); |
| 3236 | return; |
| 3237 | } |
| 3238 | |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3239 | int tokenNdx; |
| 3240 | int v; |
| 3241 | for (tokenNdx = localTokens.size() - 1, v = task.tokens.size() - 1; |
| 3242 | tokenNdx >= 0 && v >= 0; ) { |
| 3243 | final AppWindowToken atoken = localTokens.get(tokenNdx); |
Craig Mautner | 343ad71 | 2013-02-13 22:37:26 -0800 | [diff] [blame] | 3244 | if (atoken.removed) { |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3245 | --tokenNdx; |
Craig Mautner | 343ad71 | 2013-02-13 22:37:26 -0800 | [diff] [blame] | 3246 | continue; |
| 3247 | } |
| 3248 | if (tokens.get(v) != atoken.token) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 3249 | break; |
Craig Mautner | 343ad71 | 2013-02-13 22:37:26 -0800 | [diff] [blame] | 3250 | } |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3251 | --tokenNdx; |
Craig Mautner | 343ad71 | 2013-02-13 22:37:26 -0800 | [diff] [blame] | 3252 | v--; |
| 3253 | } |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3254 | |
| 3255 | if (tokenNdx >= 0 || v >= 0) { |
| 3256 | break; |
| 3257 | } |
Craig Mautner | 343ad71 | 2013-02-13 22:37:26 -0800 | [diff] [blame] | 3258 | } |
| 3259 | |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3260 | if (taskNdx >= 0 || t >= 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3261 | Slog.w(TAG, "validateAppTokens: Mismatch! ActivityManager=" + tasks); |
Craig Mautner | 1d001b6 | 2013-06-18 16:52:43 -0700 | [diff] [blame] | 3262 | Slog.w(TAG, "validateAppTokens: Mismatch! WindowManager=" + localTasks); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 3263 | Slog.w(TAG, "validateAppTokens: Mismatch! Callers=" + Debug.getCallers(4)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3264 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3265 | } |
| 3266 | } |
| 3267 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 3268 | public void validateStackOrder(Integer[] remoteStackIds) { |
| 3269 | // TODO: |
| 3270 | } |
| 3271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3272 | boolean checkCallingPermission(String permission, String func) { |
| 3273 | // Quick check: if the calling permission is me, it's all okay. |
| 3274 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3275 | return true; |
| 3276 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3277 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3278 | if (mContext.checkCallingPermission(permission) |
| 3279 | == PackageManager.PERMISSION_GRANTED) { |
| 3280 | return true; |
| 3281 | } |
| 3282 | String msg = "Permission Denial: " + func + " from pid=" |
| 3283 | + Binder.getCallingPid() |
| 3284 | + ", uid=" + Binder.getCallingUid() |
| 3285 | + " requires " + permission; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3286 | Slog.w(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3287 | return false; |
| 3288 | } |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 3289 | |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 3290 | boolean okToDisplay() { |
| 3291 | return !mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOnFully(); |
| 3292 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3294 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3295 | WindowToken wtoken = mTokenMap.get(token); |
| 3296 | if (wtoken == null) { |
| 3297 | return null; |
| 3298 | } |
| 3299 | return wtoken.appWindowToken; |
| 3300 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3301 | |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 3302 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3303 | public void addWindowToken(IBinder token, int type) { |
| 3304 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3305 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3306 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3307 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3309 | synchronized(mWindowMap) { |
| 3310 | WindowToken wtoken = mTokenMap.get(token); |
| 3311 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3312 | 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] | 3313 | return; |
| 3314 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3315 | wtoken = new WindowToken(this, token, type, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3316 | mTokenMap.put(token, wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3317 | if (type == TYPE_WALLPAPER) { |
| 3318 | mWallpaperTokens.add(wtoken); |
| 3319 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3320 | } |
| 3321 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3322 | |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 3323 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3324 | public void removeWindowToken(IBinder token) { |
| 3325 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3326 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3327 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | final long origId = Binder.clearCallingIdentity(); |
| 3331 | synchronized(mWindowMap) { |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 3332 | DisplayContent displayContent = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | WindowToken wtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3334 | if (wtoken != null) { |
| 3335 | boolean delayed = false; |
| 3336 | if (!wtoken.hidden) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3337 | final int N = wtoken.windows.size(); |
| 3338 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | for (int i=0; i<N; i++) { |
| 3341 | WindowState win = wtoken.windows.get(i); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3342 | displayContent = win.getDisplayContent(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 3344 | if (win.mWinAnimator.isAnimating()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3345 | delayed = true; |
| 3346 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3347 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3348 | if (win.isVisibleNow()) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3349 | win.mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, |
| 3350 | false); |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 3351 | //TODO (multidisplay): Magnification is supported only for the default |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 3352 | if (mAccessibilityController != null && win.isDefaultDisplay()) { |
| 3353 | mAccessibilityController.onWindowTransitionLocked(win, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 3354 | WindowManagerPolicy.TRANSIT_EXIT); |
| 3355 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3356 | changed = true; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3357 | if (displayContent != null) { |
| 3358 | displayContent.layoutNeeded = true; |
| 3359 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3360 | } |
| 3361 | } |
| 3362 | |
Craig Mautner | 4b5aa78 | 2012-10-02 18:11:25 -0700 | [diff] [blame] | 3363 | wtoken.hidden = true; |
| 3364 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3365 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3366 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3367 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, |
| 3368 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3369 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3371 | if (delayed) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3372 | if (displayContent != null) { |
| 3373 | displayContent.mExitingTokens.add(wtoken); |
| 3374 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3375 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3376 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3377 | } |
| 3378 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3379 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 3380 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3381 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3382 | 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] | 3383 | } |
| 3384 | } |
| 3385 | Binder.restoreCallingIdentity(origId); |
| 3386 | } |
| 3387 | |
Craig Mautner | 31482a7 | 2013-10-02 10:04:13 -0700 | [diff] [blame] | 3388 | private Task createTask(int taskId, int stackId, int userId, AppWindowToken atoken) { |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 3389 | if (DEBUG_STACK) Slog.i(TAG, "createTask: taskId=" + taskId + " stackId=" + stackId |
| 3390 | + " atoken=" + atoken); |
Craig Mautner | 31482a7 | 2013-10-02 10:04:13 -0700 | [diff] [blame] | 3391 | final TaskStack stack = mStackIdToStack.get(stackId); |
| 3392 | if (stack == null) { |
| 3393 | throw new IllegalArgumentException("addAppToken: invalid stackId=" + stackId); |
| 3394 | } |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 3395 | EventLog.writeEvent(EventLogTags.WM_TASK_CREATED, taskId, stackId); |
Craig Mautner | 31482a7 | 2013-10-02 10:04:13 -0700 | [diff] [blame] | 3396 | Task task = new Task(atoken, stack, userId); |
Craig Mautner | 8e79734 | 2013-10-09 16:18:29 -0700 | [diff] [blame] | 3397 | mTaskIdToTask.put(taskId, task); |
Craig Mautner | 31482a7 | 2013-10-02 10:04:13 -0700 | [diff] [blame] | 3398 | stack.addTask(task, true); |
Craig Mautner | 31482a7 | 2013-10-02 10:04:13 -0700 | [diff] [blame] | 3399 | return task; |
| 3400 | } |
| 3401 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 3402 | @Override |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 3403 | public void addAppToken(int addPos, IApplicationToken token, int taskId, int stackId, |
Craig Mautner | 5d9f547 | 2013-11-12 14:02:52 -0800 | [diff] [blame] | 3404 | int requestedOrientation, boolean fullscreen, boolean showWhenLocked, int userId, |
| 3405 | int configChanges) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3406 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3407 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3408 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3409 | } |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 3410 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3411 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3412 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3413 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3414 | // here we would run the chance of introducing a deadlock between the window manager |
| 3415 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3416 | // (which holds locks while querying the application token). |
| 3417 | long inputDispatchingTimeoutNanos; |
| 3418 | try { |
| 3419 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3420 | } catch (RemoteException ex) { |
| 3421 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3422 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3423 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3425 | synchronized(mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3426 | AppWindowToken atoken = findAppWindowToken(token.asBinder()); |
| 3427 | if (atoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3428 | 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] | 3429 | return; |
| 3430 | } |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3431 | atoken = new AppWindowToken(this, token); |
| 3432 | atoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 3433 | atoken.groupId = taskId; |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3434 | atoken.appFullscreen = fullscreen; |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 3435 | atoken.showWhenLocked = showWhenLocked; |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3436 | atoken.requestedOrientation = requestedOrientation; |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 3437 | atoken.layoutConfigChanges = (configChanges & |
| 3438 | (ActivityInfo.CONFIG_SCREEN_SIZE | ActivityInfo.CONFIG_ORIENTATION)) != 0; |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3439 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + atoken |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3440 | + " to stack=" + stackId + " task=" + taskId + " at " + addPos); |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 3441 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 3442 | Task task = mTaskIdToTask.get(taskId); |
| 3443 | if (task == null) { |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 3444 | createTask(taskId, stackId, userId, atoken); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 3445 | } else { |
| 3446 | task.addAppToken(addPos, atoken); |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 3447 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 3448 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3449 | mTokenMap.put(token.asBinder(), atoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3451 | // Application tokens start out hidden. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3452 | atoken.hidden = true; |
| 3453 | atoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3455 | //dump(); |
| 3456 | } |
| 3457 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3458 | |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 3459 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3460 | public void setAppGroupId(IBinder token, int groupId) { |
| 3461 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 3462 | "setAppGroupId()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3463 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3464 | } |
| 3465 | |
| 3466 | synchronized(mWindowMap) { |
Craig Mautner | 32b44d0 | 2013-02-21 08:26:06 -0800 | [diff] [blame] | 3467 | final AppWindowToken atoken = findAppWindowToken(token); |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3468 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3469 | 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] | 3470 | return; |
| 3471 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3472 | final Task oldTask = mTaskIdToTask.get(atoken.groupId); |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 3473 | removeAppFromTaskLocked(atoken); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 3474 | |
| 3475 | atoken.groupId = groupId; |
| 3476 | Task newTask = mTaskIdToTask.get(groupId); |
| 3477 | if (newTask == null) { |
Craig Mautner | 31482a7 | 2013-10-02 10:04:13 -0700 | [diff] [blame] | 3478 | newTask = createTask(groupId, oldTask.mStack.mStackId, oldTask.mUserId, atoken); |
Yevgen Pronenko | c36a5b9 | 2014-02-19 10:33:07 +0100 | [diff] [blame] | 3479 | } else { |
| 3480 | newTask.mAppTokens.add(atoken); |
Craig Mautner | 32b44d0 | 2013-02-21 08:26:06 -0800 | [diff] [blame] | 3481 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3482 | } |
| 3483 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3484 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3485 | public int getOrientationFromWindowsLocked() { |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3486 | if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) { |
| 3487 | // If the display is frozen, some activities may be in the middle |
| 3488 | // of restarting, and thus have removed their old window. If the |
| 3489 | // window has the flag to hide the lock screen, then the lock screen |
| 3490 | // can re-appear and inflict its own orientation on us. Keep the |
| 3491 | // orientation stable until this all settles down. |
| 3492 | return mLastWindowForcedOrientation; |
| 3493 | } |
| 3494 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3495 | // TODO(multidisplay): Change to the correct display. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3496 | final WindowList windows = getDefaultWindowListLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3497 | int pos = windows.size() - 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3498 | while (pos >= 0) { |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 3499 | WindowState win = windows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3500 | pos--; |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 3501 | if (win.mAppToken != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3502 | // We hit an application window. so the orientation will be determined by the |
| 3503 | // app window. No point in continuing further. |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3504 | return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3505 | } |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 3506 | if (!win.isVisibleLw() || !win.mPolicyVisibilityAfterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3507 | continue; |
| 3508 | } |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 3509 | int req = win.mAttrs.screenOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3510 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3511 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3512 | continue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3513 | } |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 3514 | |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 3515 | if (DEBUG_ORIENTATION) Slog.v(TAG, win + " forcing orientation to " + req); |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 3516 | return (mLastWindowForcedOrientation=req); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3517 | } |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3518 | return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3519 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3520 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3521 | public int getOrientationFromAppTokensLocked() { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3522 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3523 | boolean findingBehind = false; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3524 | boolean lastFullscreen = false; |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 3525 | // TODO: Multi window. |
| 3526 | DisplayContent displayContent = getDefaultDisplayContentLocked(); |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 3527 | final ArrayList<Task> tasks = displayContent.getTasks(); |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3528 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3529 | AppTokenList tokens = tasks.get(taskNdx).mAppTokens; |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 3530 | final int firstToken = tokens.size() - 1; |
| 3531 | for (int tokenNdx = firstToken; tokenNdx >= 0; --tokenNdx) { |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3532 | final AppWindowToken atoken = tokens.get(tokenNdx); |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 3533 | |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3534 | if (DEBUG_APP_ORIENTATION) Slog.v(TAG, "Checking app orientation: " + atoken); |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 3535 | |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3536 | // if we're about to tear down this window and not seek for |
| 3537 | // the behind activity, don't use it for orientation |
| 3538 | if (!findingBehind |
| 3539 | && (!atoken.hidden && atoken.hiddenRequested)) { |
| 3540 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping " + atoken |
| 3541 | + " -- going to hide"); |
| 3542 | continue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3543 | } |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 3544 | |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 3545 | if (tokenNdx == firstToken) { |
| 3546 | // If we have hit a new Task, and the bottom |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3547 | // of the previous group didn't explicitly say to use |
| 3548 | // the orientation behind it, and the last app was |
| 3549 | // full screen, then we'll stick with the |
| 3550 | // user's orientation. |
| 3551 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3552 | && lastFullscreen) { |
| 3553 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + atoken |
| 3554 | + " -- end of group, return " + lastOrientation); |
| 3555 | return lastOrientation; |
| 3556 | } |
| 3557 | } |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 3558 | |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3559 | // We ignore any hidden applications on the top. |
| 3560 | if (atoken.hiddenRequested || atoken.willBeHidden) { |
| 3561 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping " + atoken |
| 3562 | + " -- hidden on top"); |
| 3563 | continue; |
| 3564 | } |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 3565 | |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 3566 | if (tokenNdx == 0) { |
| 3567 | // Last token in this task. |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3568 | lastOrientation = atoken.requestedOrientation; |
| 3569 | } |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 3570 | |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 3571 | int or = atoken.requestedOrientation; |
| 3572 | // If this application is fullscreen, and didn't explicitly say |
| 3573 | // to use the orientation behind it, then just take whatever |
| 3574 | // orientation it has and ignores whatever is under it. |
| 3575 | lastFullscreen = atoken.appFullscreen; |
| 3576 | if (lastFullscreen |
| 3577 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3578 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + atoken |
| 3579 | + " -- full screen, return " + or); |
| 3580 | return or; |
| 3581 | } |
| 3582 | // If this application has requested an explicit orientation, |
| 3583 | // then use it. |
| 3584 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3585 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3586 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + atoken |
| 3587 | + " -- explicitly set, return " + or); |
| 3588 | return or; |
| 3589 | } |
| 3590 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3591 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3592 | } |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3593 | if (DEBUG_ORIENTATION) Slog.v(TAG, "No app is requesting an orientation"); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3594 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3595 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3596 | |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 3597 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3598 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3599 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3600 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3601 | "updateOrientationFromAppTokens()")) { |
| 3602 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3603 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3604 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3605 | Configuration config = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3606 | long ident = Binder.clearCallingIdentity(); |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 3607 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3608 | synchronized(mWindowMap) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 3609 | config = updateOrientationFromAppTokensLocked(currentConfig, |
| 3610 | freezeThisOneIfNeeded); |
| 3611 | } |
| 3612 | |
| 3613 | Binder.restoreCallingIdentity(ident); |
| 3614 | return config; |
| 3615 | } |
| 3616 | |
| 3617 | private Configuration updateOrientationFromAppTokensLocked( |
| 3618 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| 3619 | Configuration config = null; |
| 3620 | |
| 3621 | if (updateOrientationFromAppTokensLocked(false)) { |
| 3622 | if (freezeThisOneIfNeeded != null) { |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 3623 | AppWindowToken atoken = findAppWindowToken(freezeThisOneIfNeeded); |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3624 | if (atoken != null) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3625 | startAppFreezingScreenLocked(atoken); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3626 | } |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 3627 | } |
| 3628 | config = computeNewConfigurationLocked(); |
| 3629 | |
| 3630 | } else if (currentConfig != null) { |
| 3631 | // No obvious action we need to take, but if our current |
| 3632 | // state mismatches the activity manager's, update it, |
| 3633 | // disregarding font scale, which should remain set to |
| 3634 | // the value of the previous configuration. |
| 3635 | mTempConfiguration.setToDefaults(); |
| 3636 | mTempConfiguration.fontScale = currentConfig.fontScale; |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 3637 | if (computeScreenConfigurationLocked(mTempConfiguration)) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 3638 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3639 | mWaitingForConfig = true; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3640 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
| 3641 | displayContent.layoutNeeded = true; |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3642 | int anim[] = new int[2]; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3643 | if (displayContent.isDimming()) { |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 3644 | anim[0] = anim[1] = 0; |
| 3645 | } else { |
| 3646 | mPolicy.selectRotationAnimationLw(anim); |
| 3647 | } |
| 3648 | startFreezingDisplayLocked(false, anim[0], anim[1]); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 3649 | config = new Configuration(mTempConfiguration); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3650 | } |
| 3651 | } |
| 3652 | } |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 3653 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3654 | return config; |
| 3655 | } |
| 3656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3657 | /* |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3658 | * Determine the new desired orientation of the display, returning |
| 3659 | * a non-null new Configuration if it has changed from the current |
| 3660 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3661 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3662 | * SCREEN. This will typically be done for you if you call |
| 3663 | * sendNewConfiguration(). |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 3664 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3665 | * The orientation is computed from non-application windows first. If none of |
| 3666 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3667 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3668 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3669 | * android.os.IBinder) |
| 3670 | */ |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3671 | boolean updateOrientationFromAppTokensLocked(boolean inTransaction) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3672 | long ident = Binder.clearCallingIdentity(); |
| 3673 | try { |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 3674 | int req = getOrientationFromWindowsLocked(); |
| 3675 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3676 | req = getOrientationFromAppTokensLocked(); |
| 3677 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3678 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3679 | if (req != mForcedAppOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3680 | mForcedAppOrientation = req; |
| 3681 | //send a message to Policy indicating orientation change to take |
| 3682 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3683 | mPolicy.setCurrentOrientationLw(req); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 3684 | if (updateRotationUncheckedLocked(inTransaction)) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 3685 | // changed |
| 3686 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3687 | } |
| 3688 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3689 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 3690 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3691 | } finally { |
| 3692 | Binder.restoreCallingIdentity(ident); |
| 3693 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3694 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3695 | |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 3696 | @Override |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3697 | public void setNewConfiguration(Configuration config) { |
| 3698 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3699 | "setNewConfiguration()")) { |
| 3700 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3701 | } |
| 3702 | |
| 3703 | synchronized(mWindowMap) { |
| 3704 | mCurConfiguration = new Configuration(config); |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 3705 | if (mWaitingForConfig) { |
| 3706 | mWaitingForConfig = false; |
| 3707 | mLastFinishedFreezeSource = "new-config"; |
| 3708 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3709 | performLayoutAndPlaceSurfacesLocked(); |
| 3710 | } |
| 3711 | } |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 3712 | |
| 3713 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3714 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3715 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3716 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3717 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3718 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3719 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3720 | synchronized(mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3721 | AppWindowToken atoken = findAppWindowToken(token.asBinder()); |
| 3722 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3723 | 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] | 3724 | return; |
| 3725 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3726 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3727 | atoken.requestedOrientation = requestedOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3728 | } |
| 3729 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3730 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 3731 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3732 | public int getAppOrientation(IApplicationToken token) { |
| 3733 | synchronized(mWindowMap) { |
| 3734 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3735 | if (wtoken == null) { |
| 3736 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3737 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3738 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3739 | return wtoken.requestedOrientation; |
| 3740 | } |
| 3741 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3742 | |
Craig Mautner | f766646 | 2013-04-28 08:58:21 -0700 | [diff] [blame] | 3743 | /** Call while in a Surface transaction. */ |
| 3744 | void setFocusedStackLayer() { |
| 3745 | mFocusedStackLayer = 0; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3746 | if (mFocusedApp != null) { |
| 3747 | final WindowList windows = mFocusedApp.allAppWindows; |
| 3748 | for (int i = windows.size() - 1; i >= 0; --i) { |
| 3749 | final WindowState win = windows.get(i); |
| 3750 | final int animLayer = win.mWinAnimator.mAnimLayer; |
| 3751 | if (win.mAttachedWindow == null && win.isVisibleLw() && |
| 3752 | animLayer > mFocusedStackLayer) { |
| 3753 | mFocusedStackLayer = animLayer + LAYER_OFFSET_FOCUSED_STACK; |
| 3754 | } |
Craig Mautner | f766646 | 2013-04-28 08:58:21 -0700 | [diff] [blame] | 3755 | } |
| 3756 | } |
| 3757 | if (DEBUG_LAYERS) Slog.v(TAG, "Setting FocusedStackFrame to layer=" + |
| 3758 | mFocusedStackLayer); |
| 3759 | mFocusedStackFrame.setLayer(mFocusedStackLayer); |
| 3760 | } |
| 3761 | |
| 3762 | void setFocusedStackFrame() { |
| 3763 | final TaskStack stack; |
| 3764 | if (mFocusedApp != null) { |
| 3765 | Task task = mTaskIdToTask.get(mFocusedApp.groupId); |
| 3766 | stack = task.mStack; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3767 | final DisplayContent displayContent = task.getDisplayContent(); |
| 3768 | if (displayContent != null) { |
| 3769 | displayContent.setTouchExcludeRegion(stack); |
| 3770 | } |
Craig Mautner | f766646 | 2013-04-28 08:58:21 -0700 | [diff] [blame] | 3771 | } else { |
| 3772 | stack = null; |
| 3773 | } |
Craig Mautner | a9a3fb1 | 2013-04-18 10:01:00 -0700 | [diff] [blame] | 3774 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setFocusedStackFrame"); |
| 3775 | SurfaceControl.openTransaction(); |
| 3776 | try { |
| 3777 | if (stack == null) { |
| 3778 | mFocusedStackFrame.setVisibility(false); |
| 3779 | } else { |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 3780 | mFocusedStackFrame.setBounds(stack); |
| 3781 | final boolean multipleStacks = !stack.isFullscreen(); |
Craig Mautner | a9a3fb1 | 2013-04-18 10:01:00 -0700 | [diff] [blame] | 3782 | mFocusedStackFrame.setVisibility(multipleStacks); |
| 3783 | } |
| 3784 | } finally { |
| 3785 | SurfaceControl.closeTransaction(); |
| 3786 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> CLOSE TRANSACTION setFocusedStackFrame"); |
| 3787 | } |
| 3788 | } |
| 3789 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 3790 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3791 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3792 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3793 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3794 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3795 | } |
| 3796 | |
| 3797 | synchronized(mWindowMap) { |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 3798 | final AppWindowToken newFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3799 | if (token == null) { |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 3800 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp); |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 3801 | newFocus = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3802 | } else { |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 3803 | newFocus = findAppWindowToken(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3804 | if (newFocus == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3805 | 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] | 3806 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 3807 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "Set focused app to: " + newFocus |
| 3808 | + " old focus=" + mFocusedApp + " moveFocusNow=" + moveFocusNow); |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | final boolean changed = mFocusedApp != newFocus; |
| 3812 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3813 | mFocusedApp = newFocus; |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 3814 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3815 | } |
| 3816 | |
| 3817 | if (moveFocusNow && changed) { |
| 3818 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3819 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3820 | Binder.restoreCallingIdentity(origId); |
| 3821 | } |
| 3822 | } |
| 3823 | } |
| 3824 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 3825 | @Override |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3826 | public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3827 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3828 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3829 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3830 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3831 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3832 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3833 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3834 | TAG, "Prepare app transition: transit=" + transit |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 3835 | + " " + mAppTransition |
Craig Mautner | 1d961d4 | 2012-05-27 12:02:11 -0700 | [diff] [blame] | 3836 | + " alwaysKeepCurrent=" + alwaysKeepCurrent |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 3837 | + " Callers=" + Debug.getCallers(3)); |
Craig Mautner | 8e975be | 2013-09-21 16:12:13 -0700 | [diff] [blame] | 3838 | if (!mAppTransition.isTransitionSet() || mAppTransition.isTransitionNone()) { |
| 3839 | mAppTransition.setAppTransition(transit); |
| 3840 | } else if (!alwaysKeepCurrent) { |
| 3841 | if (transit == AppTransition.TRANSIT_TASK_OPEN |
| 3842 | && mAppTransition.isTransitionEqual( |
| 3843 | AppTransition.TRANSIT_TASK_CLOSE)) { |
| 3844 | // Opening a new task always supersedes a close for the anim. |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 3845 | mAppTransition.setAppTransition(transit); |
Craig Mautner | 8e975be | 2013-09-21 16:12:13 -0700 | [diff] [blame] | 3846 | } else if (transit == AppTransition.TRANSIT_ACTIVITY_OPEN |
| 3847 | && mAppTransition.isTransitionEqual( |
| 3848 | AppTransition.TRANSIT_ACTIVITY_CLOSE)) { |
| 3849 | // Opening a new activity always supersedes a close for the anim. |
| 3850 | mAppTransition.setAppTransition(transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3851 | } |
Craig Mautner | 8e975be | 2013-09-21 16:12:13 -0700 | [diff] [blame] | 3852 | } |
| 3853 | if (okToDisplay()) { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 3854 | mAppTransition.prepare(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3855 | mStartingIconInTransition = false; |
| 3856 | mSkipAppTransitionAnimation = false; |
| 3857 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
You Kim | cb6291c | 2012-12-04 23:22:28 +0900 | [diff] [blame] | 3858 | mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, 5000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3859 | } |
| 3860 | } |
| 3861 | } |
| 3862 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3863 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3864 | public int getPendingAppTransition() { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 3865 | return mAppTransition.getAppTransition(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 3866 | } |
| 3867 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3868 | @Override |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3869 | public void overridePendingAppTransition(String packageName, |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 3870 | int enterAnim, int exitAnim, IRemoteCallback startedCallback) { |
| 3871 | synchronized(mWindowMap) { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 3872 | mAppTransition.overridePendingAppTransition(packageName, enterAnim, exitAnim, |
| 3873 | startedCallback); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3874 | } |
| 3875 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3876 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 3877 | @Override |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3878 | public void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth, |
| 3879 | int startHeight) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 3880 | synchronized(mWindowMap) { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 3881 | mAppTransition.overridePendingAppTransitionScaleUp(startX, startY, startWidth, |
| 3882 | startHeight); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3883 | } |
| 3884 | } |
| 3885 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 3886 | @Override |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3887 | public void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 3888 | int startY, IRemoteCallback startedCallback, boolean scaleUp) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 3889 | synchronized(mWindowMap) { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 3890 | mAppTransition.overridePendingAppTransitionThumb(srcThumb, startX, startY, |
| 3891 | startedCallback, scaleUp); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3892 | } |
| 3893 | } |
| 3894 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 3895 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3896 | public void executeAppTransition() { |
| 3897 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3898 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3899 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3900 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3901 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3902 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3903 | if (DEBUG_APP_TRANSITIONS) { |
| 3904 | RuntimeException e = new RuntimeException("here"); |
| 3905 | e.fillInStackTrace(); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 3906 | Slog.w(TAG, "Execute app transition: " + mAppTransition, e); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3907 | } |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 3908 | if (mAppTransition.isTransitionSet()) { |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 3909 | mAppTransition.setReady(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3910 | final long origId = Binder.clearCallingIdentity(); |
| 3911 | performLayoutAndPlaceSurfacesLocked(); |
| 3912 | Binder.restoreCallingIdentity(origId); |
| 3913 | } |
| 3914 | } |
| 3915 | } |
| 3916 | |
Craig Mautner | e6f7d50 | 2012-10-08 10:34:17 -0700 | [diff] [blame] | 3917 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3918 | public void setAppStartingWindow(IBinder token, String pkg, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 3919 | int theme, CompatibilityInfo compatInfo, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 3920 | CharSequence nonLocalizedLabel, int labelRes, int icon, int logo, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3921 | int windowFlags, IBinder transferFrom, boolean createIfNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3922 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 3923 | "setAppStartingWindow()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3924 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3925 | } |
| 3926 | |
| 3927 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3928 | if (DEBUG_STARTING_WINDOW) Slog.v( |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 3929 | TAG, "setAppStartingWindow: token=" + token + " pkg=" + pkg |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3930 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3931 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3932 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3933 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3934 | 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] | 3935 | return; |
| 3936 | } |
| 3937 | |
| 3938 | // If the display is frozen, we won't do anything until the |
| 3939 | // actual window is displayed so there is no reason to put in |
| 3940 | // the starting window. |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 3941 | if (!okToDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3942 | return; |
| 3943 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3944 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3945 | if (wtoken.startingData != null) { |
| 3946 | return; |
| 3947 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3949 | if (transferFrom != null) { |
| 3950 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3951 | if (ttoken != null) { |
| 3952 | WindowState startingWindow = ttoken.startingWindow; |
| 3953 | if (startingWindow != null) { |
| 3954 | if (mStartingIconInTransition) { |
| 3955 | // In this case, the starting icon has already |
| 3956 | // been displayed, so start letting windows get |
| 3957 | // shown immediately without any more transitions. |
| 3958 | mSkipAppTransitionAnimation = true; |
| 3959 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3960 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 3961 | "Moving existing starting " + startingWindow + " from " + ttoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3962 | + " to " + wtoken); |
| 3963 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3964 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3965 | // Transfer the starting window over to the new |
| 3966 | // token. |
| 3967 | wtoken.startingData = ttoken.startingData; |
| 3968 | wtoken.startingView = ttoken.startingView; |
Craig Mautner | f412095 | 2012-06-21 18:25:39 -0700 | [diff] [blame] | 3969 | wtoken.startingDisplayed = ttoken.startingDisplayed; |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 3970 | ttoken.startingDisplayed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3971 | wtoken.startingWindow = startingWindow; |
Craig Mautner | f412095 | 2012-06-21 18:25:39 -0700 | [diff] [blame] | 3972 | wtoken.reportedVisible = ttoken.reportedVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3973 | ttoken.startingData = null; |
| 3974 | ttoken.startingView = null; |
| 3975 | ttoken.startingWindow = null; |
| 3976 | ttoken.startingMoved = true; |
| 3977 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3978 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3979 | startingWindow.mAppToken = wtoken; |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 3980 | startingWindow.mWinAnimator.mAppAnimator = wtoken.mAppAnimator; |
| 3981 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 3982 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) { |
| 3983 | Slog.v(TAG, "Removing starting window: " + startingWindow); |
| 3984 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3985 | startingWindow.getWindowList().remove(startingWindow); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3986 | mWindowsChanged = true; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 3987 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, |
| 3988 | "Removing starting " + startingWindow + " from " + ttoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3989 | ttoken.windows.remove(startingWindow); |
| 3990 | ttoken.allAppWindows.remove(startingWindow); |
| 3991 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3993 | // Propagate other interesting state between the |
| 3994 | // tokens. If the old token is displayed, we should |
| 3995 | // immediately force the new one to be displayed. If |
| 3996 | // it is animating, we need to move that animation to |
| 3997 | // the new one. |
| 3998 | if (ttoken.allDrawn) { |
| 3999 | wtoken.allDrawn = true; |
Craig Mautner | 7636dfb | 2012-11-16 15:24:11 -0800 | [diff] [blame] | 4000 | wtoken.deferClearAllDrawn = ttoken.deferClearAllDrawn; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4001 | } |
| 4002 | if (ttoken.firstWindowDrawn) { |
| 4003 | wtoken.firstWindowDrawn = true; |
| 4004 | } |
| 4005 | if (!ttoken.hidden) { |
| 4006 | wtoken.hidden = false; |
| 4007 | wtoken.hiddenRequested = false; |
| 4008 | wtoken.willBeHidden = false; |
| 4009 | } |
| 4010 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 4011 | wtoken.clientHidden = ttoken.clientHidden; |
| 4012 | wtoken.sendAppVisibilityToClients(); |
| 4013 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4014 | final AppWindowAnimator tAppAnimator = ttoken.mAppAnimator; |
| 4015 | final AppWindowAnimator wAppAnimator = wtoken.mAppAnimator; |
| 4016 | if (tAppAnimator.animation != null) { |
| 4017 | wAppAnimator.animation = tAppAnimator.animation; |
| 4018 | wAppAnimator.animating = tAppAnimator.animating; |
| 4019 | wAppAnimator.animLayerAdjustment = tAppAnimator.animLayerAdjustment; |
| 4020 | tAppAnimator.animation = null; |
| 4021 | tAppAnimator.animLayerAdjustment = 0; |
| 4022 | wAppAnimator.updateLayers(); |
| 4023 | tAppAnimator.updateLayers(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4024 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4025 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4026 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4027 | true /*updateInputWindows*/); |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 4028 | getDefaultDisplayContentLocked().layoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4029 | performLayoutAndPlaceSurfacesLocked(); |
| 4030 | Binder.restoreCallingIdentity(origId); |
| 4031 | return; |
| 4032 | } else if (ttoken.startingData != null) { |
| 4033 | // The previous app was getting ready to show a |
| 4034 | // starting window, but hasn't yet done so. Steal it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4035 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4036 | "Moving pending starting from " + ttoken |
| 4037 | + " to " + wtoken); |
| 4038 | wtoken.startingData = ttoken.startingData; |
| 4039 | ttoken.startingData = null; |
| 4040 | ttoken.startingMoved = true; |
| 4041 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 4042 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 4043 | // want to process the message ASAP, before any other queued |
| 4044 | // messages. |
| 4045 | mH.sendMessageAtFrontOfQueue(m); |
| 4046 | return; |
| 4047 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4048 | final AppWindowAnimator tAppAnimator = ttoken.mAppAnimator; |
| 4049 | final AppWindowAnimator wAppAnimator = wtoken.mAppAnimator; |
| 4050 | if (tAppAnimator.thumbnail != null) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4051 | // The old token is animating with a thumbnail, transfer |
| 4052 | // that to the new token. |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4053 | if (wAppAnimator.thumbnail != null) { |
| 4054 | wAppAnimator.thumbnail.destroy(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4055 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4056 | wAppAnimator.thumbnail = tAppAnimator.thumbnail; |
| 4057 | wAppAnimator.thumbnailX = tAppAnimator.thumbnailX; |
| 4058 | wAppAnimator.thumbnailY = tAppAnimator.thumbnailY; |
| 4059 | wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer; |
| 4060 | wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation; |
| 4061 | tAppAnimator.thumbnail = null; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4062 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4063 | } |
| 4064 | } |
| 4065 | |
| 4066 | // There is no existing starting window, and the caller doesn't |
| 4067 | // want us to create one, so that's it! |
| 4068 | if (!createIfNeeded) { |
| 4069 | return; |
| 4070 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4071 | |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 4072 | // If this is a translucent window, then don't |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 4073 | // show a starting window -- the current effect (a full-screen |
| 4074 | // opaque starting window that fades away to the real contents |
| 4075 | // when it is ready) does not work for this. |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4076 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Checking theme of starting window: 0x" |
| 4077 | + Integer.toHexString(theme)); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 4078 | if (theme != 0) { |
| 4079 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
Amith Yamasani | 4befbec | 2013-07-10 16:18:01 -0700 | [diff] [blame] | 4080 | com.android.internal.R.styleable.Window, mCurrentUserId); |
Dianne Hackborn | 0b80019 | 2012-06-21 15:29:36 -0700 | [diff] [blame] | 4081 | if (ent == null) { |
| 4082 | // Whoops! App doesn't exist. Um. Okay. We'll just |
| 4083 | // pretend like we didn't see that. |
| 4084 | return; |
| 4085 | } |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4086 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Translucent=" |
| 4087 | + ent.array.getBoolean( |
| 4088 | com.android.internal.R.styleable.Window_windowIsTranslucent, false) |
| 4089 | + " Floating=" |
| 4090 | + ent.array.getBoolean( |
| 4091 | com.android.internal.R.styleable.Window_windowIsFloating, false) |
| 4092 | + " ShowWallpaper=" |
| 4093 | + ent.array.getBoolean( |
| 4094 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 4095 | if (ent.array.getBoolean( |
| 4096 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 4097 | return; |
| 4098 | } |
| 4099 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 4100 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 4101 | return; |
| 4102 | } |
| 4103 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 4104 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 4105 | if (mWallpaperTarget == null) { |
| 4106 | // If this theme is requesting a wallpaper, and the wallpaper |
| 4107 | // is not curently visible, then this effectively serves as |
| 4108 | // an opaque window and our starting window transition animation |
| 4109 | // can still work. We just need to make sure the starting window |
| 4110 | // is also showing the wallpaper. |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 4111 | windowFlags |= FLAG_SHOW_WALLPAPER; |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 4112 | } else { |
| 4113 | return; |
| 4114 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 4115 | } |
| 4116 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4117 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4118 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Creating StartingData"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4119 | mStartingIconInTransition = true; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4120 | wtoken.startingData = new StartingData(pkg, theme, compatInfo, nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 4121 | labelRes, icon, logo, windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4122 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 4123 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 4124 | // want to process the message ASAP, before any other queued |
| 4125 | // messages. |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4126 | 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] | 4127 | mH.sendMessageAtFrontOfQueue(m); |
| 4128 | } |
| 4129 | } |
| 4130 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 4131 | public void removeAppStartingWindow(IBinder token) { |
| 4132 | synchronized (mWindowMap) { |
| 4133 | AppWindowToken wtoken = mTokenMap.get(token).appWindowToken; |
| 4134 | if (wtoken.startingWindow != null) { |
| 4135 | scheduleRemoveStartingWindow(wtoken); |
| 4136 | } |
| 4137 | } |
| 4138 | } |
| 4139 | |
Craig Mautner | 312eac4 | 2012-11-13 10:56:22 -0800 | [diff] [blame] | 4140 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4141 | public void setAppWillBeHidden(IBinder token) { |
| 4142 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4143 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4144 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4145 | } |
| 4146 | |
| 4147 | AppWindowToken wtoken; |
| 4148 | |
| 4149 | synchronized(mWindowMap) { |
| 4150 | wtoken = findAppWindowToken(token); |
| 4151 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4152 | 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] | 4153 | return; |
| 4154 | } |
| 4155 | wtoken.willBeHidden = true; |
| 4156 | } |
| 4157 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4158 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 4159 | public void setAppFullscreen(IBinder token, boolean toOpaque) { |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 4160 | AppWindowToken atoken = findAppWindowToken(token); |
| 4161 | if (atoken != null) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 4162 | atoken.appFullscreen = toOpaque; |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 4163 | // When making translucent, wait until windows below have been drawn. |
| 4164 | if (toOpaque) { |
| 4165 | // Making opaque so do it now. |
| 4166 | setWindowOpaque(token, true); |
| 4167 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 4168 | requestTraversal(); |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 4169 | } |
| 4170 | } |
| 4171 | |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 4172 | public void setWindowOpaque(IBinder token, boolean isOpaque) { |
| 4173 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4174 | if (wtoken != null) { |
| 4175 | WindowState win = wtoken.findMainWindow(); |
| 4176 | if (win != null) { |
| 4177 | win.mWinAnimator.setOpaque(isOpaque); |
| 4178 | } |
| 4179 | } |
| 4180 | } |
| 4181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4182 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 4183 | boolean visible, int transit, boolean performLayout) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4184 | boolean delayed = false; |
| 4185 | |
| 4186 | if (wtoken.clientHidden == visible) { |
| 4187 | wtoken.clientHidden = !visible; |
| 4188 | wtoken.sendAppVisibilityToClients(); |
| 4189 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4191 | wtoken.willBeHidden = false; |
| 4192 | if (wtoken.hidden == visible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4193 | boolean changed = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4194 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4195 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 4196 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4197 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4198 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4199 | |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 4200 | if (transit != AppTransition.TRANSIT_UNSET) { |
Craig Mautner | fbf378c | 2012-04-23 17:24:21 -0700 | [diff] [blame] | 4201 | if (wtoken.mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4202 | wtoken.mAppAnimator.animation = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4203 | } |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 4204 | if (applyAnimationLocked(wtoken, lp, transit, visible)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4205 | delayed = runningAppAnimation = true; |
| 4206 | } |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 4207 | WindowState window = wtoken.findMainWindow(); |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 4208 | //TODO (multidisplay): Magnification is supported only for the default display. |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 4209 | if (window != null && mAccessibilityController != null |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 4210 | && window.getDisplayId() == Display.DEFAULT_DISPLAY) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 4211 | mAccessibilityController.onAppWindowTransitionLocked(window, transit); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 4212 | } |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 4213 | changed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4214 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4215 | |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 4216 | final int N = wtoken.allAppWindows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4217 | for (int i=0; i<N; i++) { |
| 4218 | WindowState win = wtoken.allAppWindows.get(i); |
| 4219 | if (win == wtoken.startingWindow) { |
| 4220 | continue; |
| 4221 | } |
| 4222 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4223 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4224 | //win.dump(" "); |
| 4225 | if (visible) { |
| 4226 | if (!win.isVisibleNow()) { |
| 4227 | if (!runningAppAnimation) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 4228 | win.mWinAnimator.applyAnimationLocked( |
| 4229 | WindowManagerPolicy.TRANSIT_ENTER, true); |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 4230 | //TODO (multidisplay): Magnification is supported only for the default |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 4231 | if (mAccessibilityController != null |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 4232 | && win.getDisplayId() == Display.DEFAULT_DISPLAY) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 4233 | mAccessibilityController.onWindowTransitionLocked(win, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 4234 | WindowManagerPolicy.TRANSIT_ENTER); |
| 4235 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4236 | } |
| 4237 | changed = true; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4238 | final DisplayContent displayContent = win.getDisplayContent(); |
| 4239 | if (displayContent != null) { |
| 4240 | displayContent.layoutNeeded = true; |
| 4241 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4242 | } |
| 4243 | } else if (win.isVisibleNow()) { |
| 4244 | if (!runningAppAnimation) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 4245 | win.mWinAnimator.applyAnimationLocked( |
| 4246 | WindowManagerPolicy.TRANSIT_EXIT, false); |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 4247 | //TODO (multidisplay): Magnification is supported only for the default |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 4248 | if (mAccessibilityController != null |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 4249 | && win.getDisplayId() == Display.DEFAULT_DISPLAY) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 4250 | mAccessibilityController.onWindowTransitionLocked(win, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 4251 | WindowManagerPolicy.TRANSIT_EXIT); |
| 4252 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4253 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4254 | changed = true; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4255 | final DisplayContent displayContent = win.getDisplayContent(); |
| 4256 | if (displayContent != null) { |
| 4257 | displayContent.layoutNeeded = true; |
| 4258 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4259 | } |
| 4260 | } |
| 4261 | |
| 4262 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 4263 | if (!visible) { |
| 4264 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4265 | } else { |
| 4266 | // If we are being set visible, and the starting window is |
| 4267 | // not yet displayed, then make sure it doesn't get displayed. |
| 4268 | WindowState swin = wtoken.startingWindow; |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 4269 | if (swin != null && !swin.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4270 | swin.mPolicyVisibility = false; |
| 4271 | swin.mPolicyVisibilityAfterAnim = false; |
| 4272 | } |
| 4273 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4274 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4275 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4276 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 4277 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4278 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4279 | if (changed) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4280 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4281 | if (performLayout) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4282 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4283 | false /*updateInputWindows*/); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4284 | performLayoutAndPlaceSurfacesLocked(); |
| 4285 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4286 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4287 | } |
| 4288 | } |
| 4289 | |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4290 | if (wtoken.mAppAnimator.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4291 | delayed = true; |
| 4292 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4293 | |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 4294 | for (int i = wtoken.allAppWindows.size() - 1; i >= 0 && !delayed; i--) { |
| 4295 | if (wtoken.allAppWindows.get(i).mWinAnimator.isWindowAnimating()) { |
| 4296 | delayed = true; |
| 4297 | } |
| 4298 | } |
| 4299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4300 | return delayed; |
| 4301 | } |
| 4302 | |
Craig Mautner | 312eac4 | 2012-11-13 10:56:22 -0800 | [diff] [blame] | 4303 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4304 | public void setAppVisibility(IBinder token, boolean visible) { |
| 4305 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4306 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4307 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4308 | } |
| 4309 | |
| 4310 | AppWindowToken wtoken; |
| 4311 | |
| 4312 | synchronized(mWindowMap) { |
| 4313 | wtoken = findAppWindowToken(token); |
| 4314 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4315 | 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] | 4316 | return; |
| 4317 | } |
| 4318 | |
| 4319 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4320 | RuntimeException e = null; |
| 4321 | if (!HIDE_STACK_CRAWLS) { |
| 4322 | e = new RuntimeException(); |
| 4323 | e.fillInStackTrace(); |
| 4324 | } |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 4325 | Slog.v(TAG, "setAppVisibility(" + token + ", visible=" + visible |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 4326 | + "): " + mAppTransition |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4327 | + " hidden=" + wtoken.hidden |
| 4328 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 4329 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4331 | // If we are preparing an app transition, then delay changing |
| 4332 | // the visibility of this token until we execute that transition. |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 4333 | if (okToDisplay() && mAppTransition.isTransitionSet()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4334 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4335 | |
Craig Mautner | f412095 | 2012-06-21 18:25:39 -0700 | [diff] [blame] | 4336 | if (!wtoken.startingDisplayed) { |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 4337 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| 4338 | TAG, "Setting dummy animation on: " + wtoken); |
Craig Mautner | f412095 | 2012-06-21 18:25:39 -0700 | [diff] [blame] | 4339 | wtoken.mAppAnimator.setDummyAnimation(); |
| 4340 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4341 | mOpeningApps.remove(wtoken); |
| 4342 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4343 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4344 | wtoken.inPendingTransaction = true; |
| 4345 | if (visible) { |
| 4346 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4347 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4348 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4349 | // If the token is currently hidden (should be the |
| 4350 | // common case), then we need to set up to wait for |
| 4351 | // its windows to be ready. |
| 4352 | if (wtoken.hidden) { |
| 4353 | wtoken.allDrawn = false; |
Craig Mautner | 7636dfb | 2012-11-16 15:24:11 -0800 | [diff] [blame] | 4354 | wtoken.deferClearAllDrawn = false; |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4355 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4356 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4357 | if (wtoken.clientHidden) { |
| 4358 | // In the case where we are making an app visible |
| 4359 | // but holding off for a transition, we still need |
| 4360 | // to tell the client to make its windows visible so |
| 4361 | // they get drawn. Otherwise, we will wait on |
| 4362 | // performing the transition until all windows have |
| 4363 | // been drawn, they never will be, and we are sad. |
| 4364 | wtoken.clientHidden = false; |
| 4365 | wtoken.sendAppVisibilityToClients(); |
| 4366 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4367 | } |
| 4368 | } else { |
| 4369 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4370 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4371 | // If the token is currently visible (should be the |
| 4372 | // common case), then set up to wait for it to be hidden. |
| 4373 | if (!wtoken.hidden) { |
| 4374 | wtoken.waitingToHide = true; |
| 4375 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4376 | } |
| 4377 | return; |
| 4378 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4380 | final long origId = Binder.clearCallingIdentity(); |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 4381 | setTokenVisibilityLocked(wtoken, null, visible, AppTransition.TRANSIT_UNSET, |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 4382 | true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4383 | wtoken.updateReportedVisibilityLocked(); |
| 4384 | Binder.restoreCallingIdentity(origId); |
| 4385 | } |
| 4386 | } |
| 4387 | |
| 4388 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4389 | boolean unfreezeSurfaceNow, boolean force) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4390 | if (wtoken.mAppAnimator.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4391 | 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] | 4392 | + " force=" + force); |
| 4393 | final int N = wtoken.allAppWindows.size(); |
| 4394 | boolean unfrozeWindows = false; |
| 4395 | for (int i=0; i<N; i++) { |
| 4396 | WindowState w = wtoken.allAppWindows.get(i); |
| 4397 | if (w.mAppFreezing) { |
| 4398 | w.mAppFreezing = false; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 4399 | if (w.mHasSurface && !w.mOrientationChanging) { |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 4400 | 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] | 4401 | w.mOrientationChanging = true; |
Craig Mautner | 3255a28 | 2012-04-16 15:42:47 -0700 | [diff] [blame] | 4402 | mInnerFields.mOrientationChangeComplete = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4403 | } |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 4404 | w.mLastFreezeDuration = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4405 | unfrozeWindows = true; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4406 | final DisplayContent displayContent = w.getDisplayContent(); |
| 4407 | if (displayContent != null) { |
| 4408 | displayContent.layoutNeeded = true; |
| 4409 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4410 | } |
| 4411 | } |
| 4412 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4413 | if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4414 | wtoken.mAppAnimator.freezingScreen = false; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 4415 | wtoken.mAppAnimator.lastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
| 4416 | - mDisplayFreezeTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4417 | mAppsFreezingScreen--; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 4418 | mLastFinishedFreezeSource = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4419 | } |
| 4420 | if (unfreezeSurfaceNow) { |
| 4421 | if (unfrozeWindows) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4422 | performLayoutAndPlaceSurfacesLocked(); |
| 4423 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4424 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4425 | } |
| 4426 | } |
| 4427 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4428 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4429 | private void startAppFreezingScreenLocked(AppWindowToken wtoken) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4430 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4431 | RuntimeException e = null; |
| 4432 | if (!HIDE_STACK_CRAWLS) { |
| 4433 | e = new RuntimeException(); |
| 4434 | e.fillInStackTrace(); |
| 4435 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4436 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4437 | + ": hidden=" + wtoken.hidden + " freezing=" |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4438 | + wtoken.mAppAnimator.freezingScreen, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4439 | } |
| 4440 | if (!wtoken.hiddenRequested) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4441 | if (!wtoken.mAppAnimator.freezingScreen) { |
| 4442 | wtoken.mAppAnimator.freezingScreen = true; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 4443 | wtoken.mAppAnimator.lastFreezeDuration = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4444 | mAppsFreezingScreen++; |
| 4445 | if (mAppsFreezingScreen == 1) { |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 4446 | startFreezingDisplayLocked(false, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4447 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
You Kim | cb6291c | 2012-12-04 23:22:28 +0900 | [diff] [blame] | 4448 | mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 5000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4449 | } |
| 4450 | } |
| 4451 | final int N = wtoken.allAppWindows.size(); |
| 4452 | for (int i=0; i<N; i++) { |
| 4453 | WindowState w = wtoken.allAppWindows.get(i); |
| 4454 | w.mAppFreezing = true; |
| 4455 | } |
| 4456 | } |
| 4457 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4458 | |
Craig Mautner | 312eac4 | 2012-11-13 10:56:22 -0800 | [diff] [blame] | 4459 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4460 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 4461 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4462 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4463 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4464 | } |
| 4465 | |
| 4466 | synchronized(mWindowMap) { |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 4467 | if (configChanges == 0 && okToDisplay()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4468 | 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] | 4469 | return; |
| 4470 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4471 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4472 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4473 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4474 | 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] | 4475 | return; |
| 4476 | } |
| 4477 | final long origId = Binder.clearCallingIdentity(); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4478 | startAppFreezingScreenLocked(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4479 | Binder.restoreCallingIdentity(origId); |
| 4480 | } |
| 4481 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4482 | |
Craig Mautner | 312eac4 | 2012-11-13 10:56:22 -0800 | [diff] [blame] | 4483 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4484 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 4485 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4486 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4487 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | synchronized(mWindowMap) { |
| 4491 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4492 | if (wtoken == null || wtoken.appToken == null) { |
| 4493 | return; |
| 4494 | } |
| 4495 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4496 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4497 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.mAppAnimator.freezingScreen); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4498 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4499 | Binder.restoreCallingIdentity(origId); |
| 4500 | } |
| 4501 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4502 | |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 4503 | void removeAppFromTaskLocked(AppWindowToken wtoken) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4504 | final Task task = mTaskIdToTask.get(wtoken.groupId); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 4505 | if (task != null) { |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 4506 | if (!task.removeAppToken(wtoken)) { |
| 4507 | Slog.e(TAG, "removeAppFromTaskLocked: token=" + wtoken + " not found."); |
| 4508 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4509 | } |
| 4510 | } |
| 4511 | |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 4512 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4513 | public void removeAppToken(IBinder token) { |
| 4514 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4515 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4516 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | AppWindowToken wtoken = null; |
| 4520 | AppWindowToken startingToken = null; |
| 4521 | boolean delayed = false; |
| 4522 | |
| 4523 | final long origId = Binder.clearCallingIdentity(); |
| 4524 | synchronized(mWindowMap) { |
| 4525 | WindowToken basewtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4526 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4527 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4528 | delayed = setTokenVisibilityLocked(wtoken, null, false, |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 4529 | AppTransition.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4530 | wtoken.inPendingTransaction = false; |
| 4531 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4532 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4533 | if (mClosingApps.contains(wtoken)) { |
| 4534 | delayed = true; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 4535 | } else if (mAppTransition.isTransitionSet()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4536 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4537 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4538 | delayed = true; |
| 4539 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4540 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4541 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4542 | + " animation=" + wtoken.mAppAnimator.animation |
| 4543 | + " animating=" + wtoken.mAppAnimator.animating); |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 4544 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "removeAppToken: " |
| 4545 | + wtoken + " delayed=" + delayed + " Callers=" + Debug.getCallers(4)); |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 4546 | final TaskStack stack = mTaskIdToTask.get(wtoken.groupId).mStack; |
| 4547 | if (delayed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4548 | // 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] | 4549 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4550 | "removeAppToken make exiting: " + wtoken); |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 4551 | stack.mExitingAppTokens.add(wtoken); |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 4552 | wtoken.mDeferRemoval = true; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4553 | } else { |
| 4554 | // Make sure there is no animation running on this token, |
| 4555 | // so any windows associated with it will be removed as |
| 4556 | // soon as their animations are complete |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4557 | wtoken.mAppAnimator.clearAnimation(); |
| 4558 | wtoken.mAppAnimator.animating = false; |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 4559 | removeAppFromTaskLocked(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4560 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4562 | wtoken.removed = true; |
| 4563 | if (wtoken.startingData != null) { |
| 4564 | startingToken = wtoken; |
| 4565 | } |
| 4566 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4567 | if (mFocusedApp == wtoken) { |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 4568 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "Removing focused app token:" + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4569 | mFocusedApp = null; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4570 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4571 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4572 | } |
| 4573 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4574 | 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] | 4575 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4576 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4577 | if (!delayed && wtoken != null) { |
| 4578 | wtoken.updateReportedVisibilityLocked(); |
| 4579 | } |
| 4580 | } |
| 4581 | Binder.restoreCallingIdentity(origId); |
| 4582 | |
Craig Mautner | 68cc241 | 2013-10-01 10:39:43 -0700 | [diff] [blame] | 4583 | // Will only remove if startingToken non null. |
| 4584 | scheduleRemoveStartingWindow(startingToken); |
| 4585 | } |
| 4586 | |
Craig Mautner | 68cc241 | 2013-10-01 10:39:43 -0700 | [diff] [blame] | 4587 | void scheduleRemoveStartingWindow(AppWindowToken wtoken) { |
| 4588 | if (wtoken != null && wtoken.startingWindow != null) { |
| 4589 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, Debug.getCallers(1) + |
| 4590 | ": Schedule remove starting " + wtoken + (wtoken != null ? |
| 4591 | " startingWindow=" + wtoken.startingWindow : "")); |
Craig Mautner | 68cc241 | 2013-10-01 10:39:43 -0700 | [diff] [blame] | 4592 | Message m = mH.obtainMessage(H.REMOVE_STARTING, wtoken); |
| 4593 | mH.sendMessage(m); |
| 4594 | } |
| 4595 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4596 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4597 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4598 | WindowList windows = token.windows; |
| 4599 | final int NW = windows.size(); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4600 | if (NW > 0) { |
| 4601 | mWindowsChanged = true; |
| 4602 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4603 | for (int i = 0; i < NW; i++) { |
| 4604 | WindowState win = windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4605 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4606 | win.getWindowList().remove(win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4607 | int j = win.mChildWindows.size(); |
| 4608 | while (j > 0) { |
| 4609 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4610 | WindowState cwin = win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4611 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4612 | "Tmp removing child window " + cwin); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4613 | cwin.getWindowList().remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4614 | } |
| 4615 | } |
| 4616 | return NW > 0; |
| 4617 | } |
| 4618 | |
| 4619 | void dumpAppTokensLocked() { |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 4620 | final int numStacks = mStackIdToStack.size(); |
| 4621 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 4622 | final TaskStack stack = mStackIdToStack.valueAt(stackNdx); |
| 4623 | Slog.v(TAG, " Stack #" + stack.mStackId + " tasks from bottom to top:"); |
| 4624 | final ArrayList<Task> tasks = stack.getTasks(); |
| 4625 | final int numTasks = tasks.size(); |
| 4626 | for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { |
| 4627 | final Task task = tasks.get(taskNdx); |
| 4628 | Slog.v(TAG, " Task #" + task.taskId + " activities from bottom to top:"); |
| 4629 | AppTokenList tokens = task.mAppTokens; |
| 4630 | final int numTokens = tokens.size(); |
| 4631 | for (int tokenNdx = 0; tokenNdx < numTokens; ++tokenNdx) { |
| 4632 | Slog.v(TAG, " activity #" + tokenNdx + ": " + tokens.get(tokenNdx).token); |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 4633 | } |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 4634 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4635 | } |
| 4636 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4637 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4638 | void dumpWindowsLocked() { |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 4639 | final int numDisplays = mDisplayContents.size(); |
| 4640 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4641 | final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx); |
| 4642 | Slog.v(TAG, " Display #" + displayContent.getDisplayId()); |
| 4643 | final WindowList windows = displayContent.getWindowList(); |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 4644 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4645 | Slog.v(TAG, " #" + winNdx + ": " + windows.get(winNdx)); |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 4646 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4647 | } |
| 4648 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4649 | |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4650 | private int findAppWindowInsertionPointLocked(AppWindowToken target) { |
| 4651 | final int taskId = target.groupId; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4652 | Task targetTask = mTaskIdToTask.get(taskId); |
| 4653 | if (targetTask == null) { |
| 4654 | Slog.w(TAG, "findAppWindowInsertionPointLocked: no Task for " + target + " taskId=" |
| 4655 | + taskId); |
| 4656 | return 0; |
| 4657 | } |
| 4658 | DisplayContent displayContent = targetTask.getDisplayContent(); |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4659 | if (displayContent == null) { |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4660 | Slog.w(TAG, "findAppWindowInsertionPointLocked: no DisplayContent for " + target); |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4661 | return 0; |
| 4662 | } |
| 4663 | final WindowList windows = displayContent.getWindowList(); |
| 4664 | final int NW = windows.size(); |
| 4665 | |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 4666 | boolean found = false; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4667 | final ArrayList<Task> tasks = displayContent.getTasks(); |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 4668 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4669 | final Task task = tasks.get(taskNdx); |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 4670 | if (!found && task.taskId != taskId) { |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4671 | continue; |
| 4672 | } |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 4673 | AppTokenList tokens = task.mAppTokens; |
| 4674 | for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) { |
| 4675 | final AppWindowToken wtoken = tokens.get(tokenNdx); |
| 4676 | if (!found && wtoken == target) { |
| 4677 | found = true; |
| 4678 | } |
| 4679 | if (found) { |
| 4680 | // Find the first app token below the new position that has |
| 4681 | // a window displayed. |
| 4682 | if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows in " + wtoken.token); |
| 4683 | if (wtoken.sendingToBottom) { |
| 4684 | if (DEBUG_REORDER) Slog.v(TAG, "Skipping token -- currently sending to bottom"); |
| 4685 | continue; |
| 4686 | } |
| 4687 | for (int i = wtoken.windows.size() - 1; i >= 0; --i) { |
| 4688 | WindowState win = wtoken.windows.get(i); |
| 4689 | for (int j = win.mChildWindows.size() - 1; j >= 0; --j) { |
| 4690 | WindowState cwin = win.mChildWindows.get(j); |
| 4691 | if (cwin.mSubLayer >= 0) { |
| 4692 | for (int pos = NW - 1; pos >= 0; pos--) { |
| 4693 | if (windows.get(pos) == cwin) { |
| 4694 | if (DEBUG_REORDER) Slog.v(TAG, |
| 4695 | "Found child win @" + (pos + 1)); |
| 4696 | return pos + 1; |
| 4697 | } |
| 4698 | } |
| 4699 | } |
| 4700 | } |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4701 | for (int pos = NW - 1; pos >= 0; pos--) { |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 4702 | if (windows.get(pos) == win) { |
| 4703 | if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos + 1)); |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4704 | return pos + 1; |
| 4705 | } |
| 4706 | } |
| 4707 | } |
| 4708 | } |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4709 | } |
| 4710 | } |
Craig Mautner | 7c495cb | 2013-10-13 23:19:45 +0000 | [diff] [blame] | 4711 | // Never put an app window underneath wallpaper. |
| 4712 | for (int pos = NW - 1; pos >= 0; pos--) { |
| 4713 | if (windows.get(pos).mIsWallpaper) { |
| 4714 | if (DEBUG_REORDER) Slog.v(TAG, "Found wallpaper @" + pos); |
| 4715 | return pos + 1; |
| 4716 | } |
| 4717 | } |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4718 | return 0; |
| 4719 | } |
| 4720 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4721 | private final int reAddWindowLocked(int index, WindowState win) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4722 | final WindowList windows = win.getWindowList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4723 | final int NCW = win.mChildWindows.size(); |
| 4724 | boolean added = false; |
| 4725 | for (int j=0; j<NCW; j++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4726 | WindowState cwin = win.mChildWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4727 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4728 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4729 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4730 | win.mRebuilding = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4731 | windows.add(index, win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4732 | index++; |
| 4733 | added = true; |
| 4734 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4735 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4736 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4737 | cwin.mRebuilding = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4738 | windows.add(index, cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4739 | index++; |
| 4740 | } |
| 4741 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4742 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4743 | + index + ": " + win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4744 | win.mRebuilding = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4745 | windows.add(index, win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4746 | index++; |
| 4747 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4748 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4749 | return index; |
| 4750 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4751 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4752 | private final int reAddAppWindowsLocked(final DisplayContent displayContent, int index, |
| 4753 | WindowToken token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4754 | final int NW = token.windows.size(); |
| 4755 | for (int i=0; i<NW; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4756 | final WindowState win = token.windows.get(i); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4757 | final DisplayContent winDisplayContent = win.getDisplayContent(); |
| 4758 | if (winDisplayContent == displayContent || winDisplayContent == null) { |
| 4759 | win.mDisplayContent = displayContent; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4760 | index = reAddWindowLocked(index, win); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4761 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4762 | } |
| 4763 | return index; |
| 4764 | } |
| 4765 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4766 | void tmpRemoveTaskWindowsLocked(Task task) { |
| 4767 | AppTokenList tokens = task.mAppTokens; |
| 4768 | for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) { |
| 4769 | tmpRemoveAppWindowsLocked(tokens.get(tokenNdx)); |
| 4770 | } |
| 4771 | } |
| 4772 | |
Craig Mautner | 77df2ee | 2013-10-24 12:47:07 -0700 | [diff] [blame] | 4773 | void moveStackWindowsLocked(DisplayContent displayContent) { |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4774 | // First remove all of the windows from the list. |
Craig Mautner | 77df2ee | 2013-10-24 12:47:07 -0700 | [diff] [blame] | 4775 | final ArrayList<Task> tasks = displayContent.getTasks(); |
Craig Mautner | 5457e61 | 2013-05-10 16:25:02 -0700 | [diff] [blame] | 4776 | final int numTasks = tasks.size(); |
| 4777 | for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4778 | tmpRemoveTaskWindowsLocked(tasks.get(taskNdx)); |
Craig Mautner | 05d6272 | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4779 | } |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4780 | |
| 4781 | // And now add them back at the correct place. |
| 4782 | // Where to start adding? |
Craig Mautner | 5457e61 | 2013-05-10 16:25:02 -0700 | [diff] [blame] | 4783 | for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { |
| 4784 | AppTokenList tokens = tasks.get(taskNdx).mAppTokens; |
| 4785 | int pos = findAppWindowInsertionPointLocked(tokens.get(0)); |
| 4786 | final int numTokens = tokens.size(); |
| 4787 | for (int tokenNdx = 0; tokenNdx < numTokens; ++tokenNdx) { |
| 4788 | final AppWindowToken wtoken = tokens.get(tokenNdx); |
| 4789 | if (wtoken != null) { |
| 4790 | final int newPos = reAddAppWindowsLocked(displayContent, pos, wtoken); |
| 4791 | if (newPos != pos) { |
| 4792 | displayContent.layoutNeeded = true; |
| 4793 | } |
| 4794 | pos = newPos; |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4795 | } |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4796 | } |
| 4797 | } |
Craig Mautner | 5457e61 | 2013-05-10 16:25:02 -0700 | [diff] [blame] | 4798 | |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4799 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 4800 | false /*updateInputWindows*/)) { |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4801 | assignLayersLocked(displayContent.getWindowList()); |
| 4802 | } |
| 4803 | |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4804 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 4805 | performLayoutAndPlaceSurfacesLocked(); |
| 4806 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| 4807 | |
| 4808 | //dump(); |
| 4809 | } |
| 4810 | |
| 4811 | public void moveTaskToTop(int taskId) { |
| 4812 | final long origId = Binder.clearCallingIdentity(); |
| 4813 | try { |
| 4814 | synchronized(mWindowMap) { |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4815 | Task task = mTaskIdToTask.get(taskId); |
| 4816 | if (task == null) { |
Craig Mautner | 31482a7 | 2013-10-02 10:04:13 -0700 | [diff] [blame] | 4817 | // Normal behavior, addAppToken will be called next and task will be created. |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4818 | return; |
| 4819 | } |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 4820 | final TaskStack stack = task.mStack; |
| 4821 | final DisplayContent displayContent = task.getDisplayContent(); |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4822 | displayContent.moveStack(stack, true); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4823 | if (displayContent.isDefaultDisplay) { |
| 4824 | final TaskStack homeStack = displayContent.getHomeStack(); |
| 4825 | if (homeStack != stack) { |
| 4826 | // When a non-home stack moves to the top, the home stack moves to the |
| 4827 | // bottom. |
| 4828 | displayContent.moveStack(homeStack, false); |
| 4829 | } |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 4830 | } |
| 4831 | stack.moveTaskToTop(task); |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4832 | } |
| 4833 | } finally { |
| 4834 | Binder.restoreCallingIdentity(origId); |
| 4835 | } |
Craig Mautner | 05d6272 | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4836 | } |
| 4837 | |
| 4838 | public void moveTaskToBottom(int taskId) { |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4839 | final long origId = Binder.clearCallingIdentity(); |
| 4840 | try { |
| 4841 | synchronized(mWindowMap) { |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4842 | Task task = mTaskIdToTask.get(taskId); |
| 4843 | if (task == null) { |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4844 | Slog.e(TAG, "moveTaskToBottom: taskId=" + taskId |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4845 | + " not found in mTaskIdToTask"); |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4846 | return; |
| 4847 | } |
Craig Mautner | 5457e61 | 2013-05-10 16:25:02 -0700 | [diff] [blame] | 4848 | final TaskStack stack = task.mStack; |
| 4849 | stack.moveTaskToBottom(task); |
Craig Mautner | 77df2ee | 2013-10-24 12:47:07 -0700 | [diff] [blame] | 4850 | moveStackWindowsLocked(stack.getDisplayContent()); |
Craig Mautner | 926f383 | 2013-02-13 11:56:07 -0800 | [diff] [blame] | 4851 | } |
| 4852 | } finally { |
| 4853 | Binder.restoreCallingIdentity(origId); |
Craig Mautner | 05d6272 | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4854 | } |
Craig Mautner | 05d6272 | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4855 | } |
| 4856 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4857 | /** |
Craig Mautner | 93884a5 | 2014-01-10 13:28:10 -0800 | [diff] [blame] | 4858 | * Create a new TaskStack and place it on a DisplayContent. |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4859 | * @param stackId The unique identifier of the new stack. |
Craig Mautner | 93884a5 | 2014-01-10 13:28:10 -0800 | [diff] [blame] | 4860 | * @param displayId The unique identifier of the DisplayContent. |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4861 | */ |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4862 | public void attachStack(int stackId, int displayId) { |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 4863 | final long origId = Binder.clearCallingIdentity(); |
| 4864 | try { |
| 4865 | synchronized (mWindowMap) { |
Craig Mautner | 93884a5 | 2014-01-10 13:28:10 -0800 | [diff] [blame] | 4866 | final DisplayContent displayContent = mDisplayContents.get(displayId); |
| 4867 | if (displayContent != null) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4868 | TaskStack stack = mStackIdToStack.get(stackId); |
| 4869 | if (stack == null) { |
| 4870 | if (DEBUG_STACK) Slog.d(TAG, "attachStack: stackId=" + stackId); |
| 4871 | stack = new TaskStack(this, stackId); |
| 4872 | mStackIdToStack.put(stackId, stack); |
| 4873 | } |
| 4874 | stack.attachDisplayContent(displayContent); |
| 4875 | displayContent.attachStack(stack); |
| 4876 | moveStackWindowsLocked(displayContent); |
| 4877 | final WindowList windows = displayContent.getWindowList(); |
| 4878 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 4879 | windows.get(winNdx).reportResized(); |
| 4880 | } |
Craig Mautner | 4cd0c13 | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 4881 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 4882 | } |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 4883 | } finally { |
| 4884 | Binder.restoreCallingIdentity(origId); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4885 | } |
| 4886 | } |
| 4887 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 4888 | void detachStackLocked(DisplayContent displayContent, TaskStack stack) { |
| 4889 | displayContent.detachStack(stack); |
| 4890 | stack.detachDisplay(); |
| 4891 | } |
| 4892 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4893 | public void detachStack(int stackId) { |
| 4894 | synchronized (mWindowMap) { |
| 4895 | TaskStack stack = mStackIdToStack.get(stackId); |
| 4896 | if (stack != null) { |
| 4897 | final DisplayContent displayContent = stack.getDisplayContent(); |
| 4898 | if (displayContent != null) { |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 4899 | if (stack.isAnimating()) { |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 4900 | stack.mDeferDetach = true; |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 4901 | return; |
| 4902 | } |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 4903 | detachStackLocked(displayContent, stack); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4904 | } |
| 4905 | } |
| 4906 | } |
| 4907 | } |
| 4908 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 4909 | public void removeStack(int stackId) { |
| 4910 | mStackIdToStack.remove(stackId); |
| 4911 | } |
| 4912 | |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 4913 | void removeTaskLocked(Task task) { |
| 4914 | final int taskId = task.taskId; |
| 4915 | final TaskStack stack = task.mStack; |
| 4916 | if (stack.isAnimating()) { |
| 4917 | if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + taskId); |
| 4918 | task.mDeferRemoval = true; |
| 4919 | return; |
| 4920 | } |
| 4921 | if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + taskId); |
| 4922 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, taskId, "removeTask"); |
| 4923 | task.mDeferRemoval = false; |
| 4924 | task.mStack.removeTask(task); |
| 4925 | mTaskIdToTask.delete(task.taskId); |
| 4926 | } |
| 4927 | |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 4928 | public void removeTask(int taskId) { |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4929 | synchronized (mWindowMap) { |
| 4930 | Task task = mTaskIdToTask.get(taskId); |
Craig Mautner | 4cd0c13 | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 4931 | if (task == null) { |
Craig Mautner | 1d001b6 | 2013-06-18 16:52:43 -0700 | [diff] [blame] | 4932 | if (DEBUG_STACK) Slog.i(TAG, "removeTask: could not find taskId=" + taskId); |
Craig Mautner | 4cd0c13 | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 4933 | return; |
| 4934 | } |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 4935 | removeTaskLocked(task); |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 4936 | } |
| 4937 | } |
Craig Mautner | 4cd0c13 | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 4938 | |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 4939 | public void addTask(int taskId, int stackId, boolean toTop) { |
| 4940 | synchronized (mWindowMap) { |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 4941 | if (DEBUG_STACK) Slog.i(TAG, "addTask: adding taskId=" + taskId |
| 4942 | + " to " + (toTop ? "top" : "bottom")); |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 4943 | Task task = mTaskIdToTask.get(taskId); |
| 4944 | if (task == null) { |
| 4945 | return; |
| 4946 | } |
Craig Mautner | 4cd0c13 | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 4947 | TaskStack stack = mStackIdToStack.get(stackId); |
| 4948 | stack.addTask(task, toTop); |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 4949 | final DisplayContent displayContent = stack.getDisplayContent(); |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 4950 | displayContent.layoutNeeded = true; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4951 | performLayoutAndPlaceSurfacesLocked(); |
| 4952 | } |
| 4953 | } |
| 4954 | |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4955 | public void resizeStack(int stackId, Rect bounds) { |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4956 | synchronized (mWindowMap) { |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4957 | final TaskStack stack = mStackIdToStack.get(stackId); |
| 4958 | if (stack == null) { |
| 4959 | throw new IllegalArgumentException("resizeStack: stackId " + stackId |
| 4960 | + " not found."); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4961 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4962 | if (stack.setBounds(bounds)) { |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 4963 | stack.resizeWindows(); |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4964 | stack.getDisplayContent().layoutNeeded = true; |
| 4965 | performLayoutAndPlaceSurfacesLocked(); |
| 4966 | } |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 4967 | } |
| 4968 | } |
| 4969 | |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4970 | public void getStackBounds(int stackId, Rect bounds) { |
| 4971 | final TaskStack stack = mStackIdToStack.get(stackId); |
| 4972 | if (stack != null) { |
| 4973 | stack.getBounds(bounds); |
| 4974 | return; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 4975 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4976 | bounds.setEmpty(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 4977 | } |
| 4978 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4979 | // ------------------------------------------------------------- |
| 4980 | // Misc IWindowSession methods |
| 4981 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4982 | |
Craig Mautner | 5642a48 | 2012-08-23 12:16:53 -0700 | [diff] [blame] | 4983 | @Override |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 4984 | public void startFreezingScreen(int exitAnim, int enterAnim) { |
| 4985 | if (!checkCallingPermission(android.Manifest.permission.FREEZE_SCREEN, |
| 4986 | "startFreezingScreen()")) { |
| 4987 | throw new SecurityException("Requires FREEZE_SCREEN permission"); |
| 4988 | } |
| 4989 | |
| 4990 | synchronized(mWindowMap) { |
| 4991 | if (!mClientFreezingScreen) { |
| 4992 | mClientFreezingScreen = true; |
| 4993 | final long origId = Binder.clearCallingIdentity(); |
| 4994 | try { |
| 4995 | startFreezingDisplayLocked(false, exitAnim, enterAnim); |
| 4996 | mH.removeMessages(H.CLIENT_FREEZE_TIMEOUT); |
You Kim | cb6291c | 2012-12-04 23:22:28 +0900 | [diff] [blame] | 4997 | mH.sendEmptyMessageDelayed(H.CLIENT_FREEZE_TIMEOUT, 5000); |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 4998 | } finally { |
| 4999 | Binder.restoreCallingIdentity(origId); |
| 5000 | } |
| 5001 | } |
| 5002 | } |
| 5003 | } |
| 5004 | |
| 5005 | @Override |
| 5006 | public void stopFreezingScreen() { |
| 5007 | if (!checkCallingPermission(android.Manifest.permission.FREEZE_SCREEN, |
| 5008 | "stopFreezingScreen()")) { |
| 5009 | throw new SecurityException("Requires FREEZE_SCREEN permission"); |
| 5010 | } |
| 5011 | |
| 5012 | synchronized(mWindowMap) { |
| 5013 | if (mClientFreezingScreen) { |
| 5014 | mClientFreezingScreen = false; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 5015 | mLastFinishedFreezeSource = "client"; |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 5016 | final long origId = Binder.clearCallingIdentity(); |
| 5017 | try { |
| 5018 | stopFreezingDisplayLocked(); |
| 5019 | } finally { |
| 5020 | Binder.restoreCallingIdentity(origId); |
| 5021 | } |
| 5022 | } |
| 5023 | } |
| 5024 | } |
| 5025 | |
| 5026 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5027 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 5028 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5029 | != PackageManager.PERMISSION_GRANTED) { |
| 5030 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 5031 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 5032 | |
Craig Mautner | 5642a48 | 2012-08-23 12:16:53 -0700 | [diff] [blame] | 5033 | mKeyguardDisableHandler.sendMessage(mKeyguardDisableHandler.obtainMessage( |
| 5034 | KeyguardDisableHandler.KEYGUARD_DISABLE, new Pair<IBinder, String>(token, tag))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5035 | } |
| 5036 | |
Craig Mautner | 5642a48 | 2012-08-23 12:16:53 -0700 | [diff] [blame] | 5037 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5038 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 5039 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5040 | != PackageManager.PERMISSION_GRANTED) { |
| 5041 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 5042 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5043 | |
Craig Mautner | 5642a48 | 2012-08-23 12:16:53 -0700 | [diff] [blame] | 5044 | mKeyguardDisableHandler.sendMessage(mKeyguardDisableHandler.obtainMessage( |
| 5045 | KeyguardDisableHandler.KEYGUARD_REENABLE, token)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5046 | } |
| 5047 | |
| 5048 | /** |
| 5049 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 5050 | */ |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 5051 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5052 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 5053 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5054 | != PackageManager.PERMISSION_GRANTED) { |
| 5055 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 5056 | } |
| 5057 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 5058 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5059 | public void onKeyguardExitResult(boolean success) { |
| 5060 | try { |
| 5061 | callback.onKeyguardExitResult(success); |
| 5062 | } catch (RemoteException e) { |
| 5063 | // Client has died, we don't care. |
| 5064 | } |
| 5065 | } |
| 5066 | }); |
| 5067 | } |
| 5068 | |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 5069 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5070 | public boolean inKeyguardRestrictedInputMode() { |
| 5071 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 5072 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5073 | |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 5074 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5075 | public boolean isKeyguardLocked() { |
| 5076 | return mPolicy.isKeyguardLocked(); |
| 5077 | } |
| 5078 | |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 5079 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5080 | public boolean isKeyguardSecure() { |
| 5081 | return mPolicy.isKeyguardSecure(); |
| 5082 | } |
| 5083 | |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 5084 | @Override |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5085 | public void dismissKeyguard() { |
| 5086 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| 5087 | != PackageManager.PERMISSION_GRANTED) { |
| 5088 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 5089 | } |
| 5090 | synchronized(mWindowMap) { |
| 5091 | mPolicy.dismissKeyguardLw(); |
| 5092 | } |
| 5093 | } |
| 5094 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 5095 | @Override |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 5096 | public void closeSystemDialogs(String reason) { |
| 5097 | synchronized(mWindowMap) { |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 5098 | final int numDisplays = mDisplayContents.size(); |
| 5099 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 5100 | final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList(); |
| 5101 | final int numWindows = windows.size(); |
| 5102 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 5103 | final WindowState w = windows.get(winNdx); |
| 5104 | if (w.mHasSurface) { |
| 5105 | try { |
| 5106 | w.mClient.closeSystemDialogs(reason); |
| 5107 | } catch (RemoteException e) { |
| 5108 | } |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 5109 | } |
| 5110 | } |
| 5111 | } |
| 5112 | } |
| 5113 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5114 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5115 | static float fixScale(float scale) { |
| 5116 | if (scale < 0) scale = 0; |
| 5117 | else if (scale > 20) scale = 20; |
| 5118 | return Math.abs(scale); |
| 5119 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5120 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 5121 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5122 | public void setAnimationScale(int which, float scale) { |
| 5123 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 5124 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5125 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5126 | } |
| 5127 | |
Cyril Mottier | 5f5882f | 2013-07-15 10:29:48 +0200 | [diff] [blame] | 5128 | scale = fixScale(scale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5129 | switch (which) { |
Cyril Mottier | 5f5882f | 2013-07-15 10:29:48 +0200 | [diff] [blame] | 5130 | case 0: mWindowAnimationScale = scale; break; |
| 5131 | case 1: mTransitionAnimationScale = scale; break; |
| 5132 | case 2: mAnimatorDurationScale = scale; break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5133 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5134 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5135 | // Persist setting |
You Kim | cb6291c | 2012-12-04 23:22:28 +0900 | [diff] [blame] | 5136 | mH.sendEmptyMessage(H.PERSIST_ANIMATION_SCALE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5137 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5138 | |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 5139 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5140 | public void setAnimationScales(float[] scales) { |
| 5141 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 5142 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5143 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5144 | } |
| 5145 | |
| 5146 | if (scales != null) { |
| 5147 | if (scales.length >= 1) { |
| 5148 | mWindowAnimationScale = fixScale(scales[0]); |
| 5149 | } |
| 5150 | if (scales.length >= 2) { |
| 5151 | mTransitionAnimationScale = fixScale(scales[1]); |
| 5152 | } |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 5153 | if (scales.length >= 3) { |
Jeff Brown | ff7e6ef | 2012-08-15 02:05:18 -0700 | [diff] [blame] | 5154 | setAnimatorDurationScale(fixScale(scales[2])); |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 5155 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5156 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5158 | // Persist setting |
You Kim | cb6291c | 2012-12-04 23:22:28 +0900 | [diff] [blame] | 5159 | mH.sendEmptyMessage(H.PERSIST_ANIMATION_SCALE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5160 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5161 | |
Jeff Brown | ff7e6ef | 2012-08-15 02:05:18 -0700 | [diff] [blame] | 5162 | private void setAnimatorDurationScale(float scale) { |
| 5163 | mAnimatorDurationScale = scale; |
| 5164 | ValueAnimator.setDurationScale(scale); |
| 5165 | } |
| 5166 | |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 5167 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5168 | public float getAnimationScale(int which) { |
| 5169 | switch (which) { |
| 5170 | case 0: return mWindowAnimationScale; |
| 5171 | case 1: return mTransitionAnimationScale; |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 5172 | case 2: return mAnimatorDurationScale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5173 | } |
| 5174 | return 0; |
| 5175 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5176 | |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 5177 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5178 | public float[] getAnimationScales() { |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 5179 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale, |
| 5180 | mAnimatorDurationScale }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5181 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5182 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 5183 | @Override |
| 5184 | public void registerPointerEventListener(PointerEventListener listener) { |
| 5185 | mPointerEventDispatcher.registerInputEventListener(listener); |
| 5186 | } |
| 5187 | |
| 5188 | @Override |
| 5189 | public void unregisterPointerEventListener(PointerEventListener listener) { |
| 5190 | mPointerEventDispatcher.unregisterInputEventListener(listener); |
| 5191 | } |
| 5192 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5193 | // Called by window manager policy. Not exposed externally. |
| 5194 | @Override |
| 5195 | public int getLidState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5196 | int sw = mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, |
| 5197 | InputManagerService.SW_LID); |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5198 | if (sw > 0) { |
Jeff Brown | 27fd342 | 2012-04-09 11:05:16 -0700 | [diff] [blame] | 5199 | // Switch state: AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL. |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5200 | return LID_CLOSED; |
Jeff Brown | 27fd342 | 2012-04-09 11:05:16 -0700 | [diff] [blame] | 5201 | } else if (sw == 0) { |
| 5202 | // Switch state: AKEY_STATE_UP. |
| 5203 | return LID_OPEN; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5204 | } else { |
Jeff Brown | 27fd342 | 2012-04-09 11:05:16 -0700 | [diff] [blame] | 5205 | // Switch state: AKEY_STATE_UNKNOWN. |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5206 | return LID_ABSENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5207 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5208 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5209 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5210 | // Called by window manager policy. Not exposed externally. |
| 5211 | @Override |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 5212 | public void switchKeyboardLayout(int deviceId, int direction) { |
| 5213 | mInputManager.switchKeyboardLayout(deviceId, direction); |
| 5214 | } |
| 5215 | |
| 5216 | // Called by window manager policy. Not exposed externally. |
| 5217 | @Override |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 5218 | public void shutdown(boolean confirm) { |
| 5219 | ShutdownThread.shutdown(mContext, confirm); |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | // Called by window manager policy. Not exposed externally. |
| 5223 | @Override |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 5224 | public void rebootSafeMode(boolean confirm) { |
| 5225 | ShutdownThread.rebootSafeMode(mContext, confirm); |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 5226 | } |
| 5227 | |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 5228 | public void updateRelatedUserIds(final int[] relatedUserIds) { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5229 | synchronized (mWindowMap) { |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 5230 | mRelatedUserIds = relatedUserIds; |
| 5231 | } |
| 5232 | } |
| 5233 | |
| 5234 | public void setCurrentUser(final int newUserId, final int[] relatedUserIds) { |
| 5235 | synchronized (mWindowMap) { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5236 | mCurrentUserId = newUserId; |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 5237 | mRelatedUserIds = relatedUserIds; |
Amith Yamasani | 4befbec | 2013-07-10 16:18:01 -0700 | [diff] [blame] | 5238 | mAppTransition.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5239 | mPolicy.setCurrentUserLw(newUserId); |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 5240 | |
| 5241 | // Hide windows that should not be seen by the new user. |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 5242 | final int numDisplays = mDisplayContents.size(); |
| 5243 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 5244 | final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx); |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 5245 | displayContent.switchUserStacks(newUserId); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 5246 | rebuildAppWindowListLocked(displayContent); |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 5247 | } |
| 5248 | performLayoutAndPlaceSurfacesLocked(); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5249 | } |
| 5250 | } |
| 5251 | |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 5252 | /* Called by WindowState */ |
| 5253 | boolean isRelatedToOrCurrentUserLocked(int userId) { |
| 5254 | if (userId == mCurrentUserId) return true; |
| 5255 | for (int i = 0; i < mRelatedUserIds.length; i++) { |
| 5256 | if (mRelatedUserIds[i] == userId) return true; |
| 5257 | } |
| 5258 | return false; |
| 5259 | } |
| 5260 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5261 | public void enableScreenAfterBoot() { |
| 5262 | synchronized(mWindowMap) { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5263 | if (DEBUG_BOOT) { |
| 5264 | RuntimeException here = new RuntimeException("here"); |
| 5265 | here.fillInStackTrace(); |
| 5266 | Slog.i(TAG, "enableScreenAfterBoot: mDisplayEnabled=" + mDisplayEnabled |
| 5267 | + " mForceDisplayEnabled=" + mForceDisplayEnabled |
| 5268 | + " mShowingBootMessages=" + mShowingBootMessages |
| 5269 | + " mSystemBooted=" + mSystemBooted, here); |
| 5270 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5271 | if (mSystemBooted) { |
| 5272 | return; |
| 5273 | } |
| 5274 | mSystemBooted = true; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5275 | hideBootMessagesLocked(); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5276 | // If the screen still doesn't come up after 30 seconds, give |
| 5277 | // up and turn it on. |
You Kim | cb6291c | 2012-12-04 23:22:28 +0900 | [diff] [blame] | 5278 | mH.sendEmptyMessageDelayed(H.BOOT_TIMEOUT, 30*1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5279 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5280 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5281 | mPolicy.systemBooted(); |
| 5282 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5283 | performEnableScreen(); |
| 5284 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5285 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5286 | void enableScreenIfNeededLocked() { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5287 | if (DEBUG_BOOT) { |
| 5288 | RuntimeException here = new RuntimeException("here"); |
| 5289 | here.fillInStackTrace(); |
| 5290 | Slog.i(TAG, "enableScreenIfNeededLocked: mDisplayEnabled=" + mDisplayEnabled |
| 5291 | + " mForceDisplayEnabled=" + mForceDisplayEnabled |
| 5292 | + " mShowingBootMessages=" + mShowingBootMessages |
| 5293 | + " mSystemBooted=" + mSystemBooted, here); |
| 5294 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5295 | if (mDisplayEnabled) { |
| 5296 | return; |
| 5297 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5298 | if (!mSystemBooted && !mShowingBootMessages) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5299 | return; |
| 5300 | } |
You Kim | cb6291c | 2012-12-04 23:22:28 +0900 | [diff] [blame] | 5301 | mH.sendEmptyMessage(H.ENABLE_SCREEN); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5302 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5303 | |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5304 | public void performBootTimeout() { |
| 5305 | synchronized(mWindowMap) { |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 5306 | if (mDisplayEnabled) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5307 | return; |
| 5308 | } |
| 5309 | Slog.w(TAG, "***** BOOT TIMEOUT: forcing display enabled"); |
| 5310 | mForceDisplayEnabled = true; |
| 5311 | } |
| 5312 | performEnableScreen(); |
| 5313 | } |
| 5314 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5315 | public void performEnableScreen() { |
| 5316 | synchronized(mWindowMap) { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5317 | if (DEBUG_BOOT) { |
| 5318 | RuntimeException here = new RuntimeException("here"); |
| 5319 | here.fillInStackTrace(); |
| 5320 | Slog.i(TAG, "performEnableScreen: mDisplayEnabled=" + mDisplayEnabled |
| 5321 | + " mForceDisplayEnabled=" + mForceDisplayEnabled |
| 5322 | + " mShowingBootMessages=" + mShowingBootMessages |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 5323 | + " mSystemBooted=" + mSystemBooted |
| 5324 | + " mOnlyCore=" + mOnlyCore, here); |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5325 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5326 | if (mDisplayEnabled) { |
| 5327 | return; |
| 5328 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5329 | if (!mSystemBooted && !mShowingBootMessages) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5330 | return; |
| 5331 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5332 | |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5333 | if (!mForceDisplayEnabled) { |
| 5334 | // Don't enable the screen until all existing windows |
| 5335 | // have been drawn. |
| 5336 | boolean haveBootMsg = false; |
| 5337 | boolean haveApp = false; |
Justin Mattson | 4233f26 | 2012-04-09 18:23:16 -0700 | [diff] [blame] | 5338 | // if the wallpaper service is disabled on the device, we're never going to have |
| 5339 | // wallpaper, don't bother waiting for it |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5340 | boolean haveWallpaper = false; |
Justin Mattson | 4233f26 | 2012-04-09 18:23:16 -0700 | [diff] [blame] | 5341 | boolean wallpaperEnabled = mContext.getResources().getBoolean( |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 5342 | com.android.internal.R.bool.config_enableWallpaperService) |
| 5343 | && !mOnlyCore; |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5344 | boolean haveKeyguard = true; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5345 | // TODO(multidisplay): Expand to all displays? |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 5346 | final WindowList windows = getDefaultWindowListLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5347 | final int N = windows.size(); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5348 | for (int i=0; i<N; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5349 | WindowState w = windows.get(i); |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 5350 | if (w.mAttrs.type == TYPE_KEYGUARD) { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5351 | // Only if there is a keyguard attached to the window manager |
| 5352 | // will we consider ourselves as having a keyguard. If it |
| 5353 | // isn't attached, we don't know if it wants to be shown or |
| 5354 | // hidden. If it is attached, we will say we have a keyguard |
| 5355 | // if the window doesn't want to be visible, because in that |
| 5356 | // case it explicitly doesn't want to be shown so we should |
| 5357 | // not delay turning the screen on for it. |
| 5358 | boolean vis = w.mViewVisibility == View.VISIBLE |
| 5359 | && w.mPolicyVisibility; |
| 5360 | haveKeyguard = !vis; |
| 5361 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5362 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| 5363 | return; |
| 5364 | } |
| 5365 | if (w.isDrawnLw()) { |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 5366 | if (w.mAttrs.type == TYPE_BOOT_PROGRESS) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5367 | haveBootMsg = true; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 5368 | } else if (w.mAttrs.type == TYPE_APPLICATION) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5369 | haveApp = true; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 5370 | } else if (w.mAttrs.type == TYPE_WALLPAPER) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5371 | haveWallpaper = true; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 5372 | } else if (w.mAttrs.type == TYPE_KEYGUARD) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5373 | haveKeyguard = true; |
| 5374 | } |
| 5375 | } |
| 5376 | } |
| 5377 | |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5378 | if (DEBUG_SCREEN_ON || DEBUG_BOOT) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5379 | Slog.i(TAG, "******** booted=" + mSystemBooted + " msg=" + mShowingBootMessages |
| 5380 | + " haveBoot=" + haveBootMsg + " haveApp=" + haveApp |
Justin Mattson | 4233f26 | 2012-04-09 18:23:16 -0700 | [diff] [blame] | 5381 | + " haveWall=" + haveWallpaper + " wallEnabled=" + wallpaperEnabled |
| 5382 | + " haveKeyguard=" + haveKeyguard); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5383 | } |
| 5384 | |
| 5385 | // If we are turning on the screen to show the boot message, |
| 5386 | // don't do it until the boot message is actually displayed. |
| 5387 | if (!mSystemBooted && !haveBootMsg) { |
| 5388 | return; |
| 5389 | } |
Craig Mautner | 312eac4 | 2012-11-13 10:56:22 -0800 | [diff] [blame] | 5390 | |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5391 | // If we are turning on the screen after the boot is completed |
| 5392 | // normally, don't do so until we have the application and |
| 5393 | // wallpaper. |
Justin Mattson | 4233f26 | 2012-04-09 18:23:16 -0700 | [diff] [blame] | 5394 | if (mSystemBooted && ((!haveApp && !haveKeyguard) || |
| 5395 | (wallpaperEnabled && !haveWallpaper))) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5396 | return; |
| 5397 | } |
| 5398 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5400 | mDisplayEnabled = true; |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5401 | 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] | 5402 | if (false) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5403 | StringWriter sw = new StringWriter(); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 5404 | PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5405 | this.dump(null, pw, null); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 5406 | pw.flush(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5407 | Slog.i(TAG, sw.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5408 | } |
| 5409 | try { |
| 5410 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 5411 | if (surfaceFlinger != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5412 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5413 | Parcel data = Parcel.obtain(); |
| 5414 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
Jeff Brown | c042ee2 | 2012-05-08 13:03:42 -0700 | [diff] [blame] | 5415 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, // BOOT_FINISHED |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5416 | data, null, 0); |
| 5417 | data.recycle(); |
| 5418 | } |
| 5419 | } catch (RemoteException ex) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5420 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5421 | } |
Jeff Brown | 08a746a | 2012-06-24 12:14:49 -0700 | [diff] [blame] | 5422 | |
| 5423 | // Enable input dispatch. |
| 5424 | mInputMonitor.setEventDispatchingLw(mEventDispatchingEnabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5425 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5427 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5428 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5429 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5430 | updateRotationUnchecked(false, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5431 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5432 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5433 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 5434 | boolean first = false; |
| 5435 | synchronized(mWindowMap) { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5436 | if (DEBUG_BOOT) { |
| 5437 | RuntimeException here = new RuntimeException("here"); |
| 5438 | here.fillInStackTrace(); |
| 5439 | Slog.i(TAG, "showBootMessage: msg=" + msg + " always=" + always |
| 5440 | + " mAllowBootMessages=" + mAllowBootMessages |
| 5441 | + " mShowingBootMessages=" + mShowingBootMessages |
| 5442 | + " mSystemBooted=" + mSystemBooted, here); |
| 5443 | } |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 5444 | if (!mAllowBootMessages) { |
| 5445 | return; |
| 5446 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5447 | if (!mShowingBootMessages) { |
| 5448 | if (!always) { |
| 5449 | return; |
| 5450 | } |
| 5451 | first = true; |
| 5452 | } |
| 5453 | if (mSystemBooted) { |
| 5454 | return; |
| 5455 | } |
| 5456 | mShowingBootMessages = true; |
| 5457 | mPolicy.showBootMessage(msg, always); |
| 5458 | } |
| 5459 | if (first) { |
| 5460 | performEnableScreen(); |
| 5461 | } |
| 5462 | } |
| 5463 | |
| 5464 | public void hideBootMessagesLocked() { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5465 | if (DEBUG_BOOT) { |
| 5466 | RuntimeException here = new RuntimeException("here"); |
| 5467 | here.fillInStackTrace(); |
| 5468 | Slog.i(TAG, "hideBootMessagesLocked: mDisplayEnabled=" + mDisplayEnabled |
| 5469 | + " mForceDisplayEnabled=" + mForceDisplayEnabled |
| 5470 | + " mShowingBootMessages=" + mShowingBootMessages |
| 5471 | + " mSystemBooted=" + mSystemBooted, here); |
| 5472 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5473 | if (mShowingBootMessages) { |
| 5474 | mShowingBootMessages = false; |
| 5475 | mPolicy.hideBootMessages(); |
| 5476 | } |
| 5477 | } |
| 5478 | |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 5479 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5480 | public void setInTouchMode(boolean mode) { |
| 5481 | synchronized(mWindowMap) { |
| 5482 | mInTouchMode = mode; |
| 5483 | } |
| 5484 | } |
| 5485 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5486 | // TODO: more accounting of which pid(s) turned it on, keep count, |
| 5487 | // only allow disables from pids which have count on, etc. |
Craig Mautner | 0447a81 | 2012-05-22 16:01:31 -0700 | [diff] [blame] | 5488 | @Override |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5489 | public void showStrictModeViolation(boolean on) { |
Chris Craik | 3198ef3 | 2012-10-10 14:52:30 -0700 | [diff] [blame] | 5490 | int pid = Binder.getCallingPid(); |
| 5491 | mH.sendMessage(mH.obtainMessage(H.SHOW_STRICT_MODE_VIOLATION, on ? 1 : 0, pid)); |
Craig Mautner | 0447a81 | 2012-05-22 16:01:31 -0700 | [diff] [blame] | 5492 | } |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5493 | |
Chris Craik | 3198ef3 | 2012-10-10 14:52:30 -0700 | [diff] [blame] | 5494 | private void showStrictModeViolation(int arg, int pid) { |
Craig Mautner | 0447a81 | 2012-05-22 16:01:31 -0700 | [diff] [blame] | 5495 | final boolean on = arg != 0; |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5496 | synchronized(mWindowMap) { |
| 5497 | // Ignoring requests to enable the red border from clients |
| 5498 | // which aren't on screen. (e.g. Broadcast Receivers in |
| 5499 | // the background..) |
| 5500 | if (on) { |
| 5501 | boolean isVisible = false; |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 5502 | final int numDisplays = mDisplayContents.size(); |
| 5503 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 5504 | final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList(); |
| 5505 | final int numWindows = windows.size(); |
| 5506 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 5507 | final WindowState ws = windows.get(winNdx); |
| 5508 | if (ws.mSession.mPid == pid && ws.isVisibleLw()) { |
| 5509 | isVisible = true; |
| 5510 | break; |
| 5511 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5512 | } |
| 5513 | } |
| 5514 | if (!isVisible) { |
| 5515 | return; |
| 5516 | } |
| 5517 | } |
| 5518 | |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 5519 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 5520 | ">>> OPEN TRANSACTION showStrictModeViolation"); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 5521 | SurfaceControl.openTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5522 | try { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 5523 | // TODO(multi-display): support multiple displays |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5524 | if (mStrictModeFlash == null) { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 5525 | mStrictModeFlash = new StrictModeFlash( |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 5526 | getDefaultDisplayContentLocked().getDisplay(), mFxSession); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5527 | } |
| 5528 | mStrictModeFlash.setVisibility(on); |
| 5529 | } finally { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 5530 | SurfaceControl.closeTransaction(); |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 5531 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 5532 | "<<< CLOSE TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5533 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5534 | } |
| 5535 | } |
| 5536 | |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 5537 | @Override |
Brad Fitzpatrick | c1a968a | 2010-11-24 08:56:40 -0800 | [diff] [blame] | 5538 | public void setStrictModeVisualIndicatorPreference(String value) { |
| 5539 | SystemProperties.set(StrictMode.VISUAL_PROPERTY, value); |
| 5540 | } |
| 5541 | |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5542 | /** |
| 5543 | * Takes a snapshot of the screen. In landscape mode this grabs the whole screen. |
| 5544 | * In portrait mode, it grabs the upper region of the screen based on the vertical dimension |
| 5545 | * of the target image. |
Craig Mautner | 312eac4 | 2012-11-13 10:56:22 -0800 | [diff] [blame] | 5546 | * |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5547 | * @param displayId the Display to take a screenshot of. |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5548 | * @param width the width of the target bitmap |
| 5549 | * @param height the height of the target bitmap |
John Reck | 172e87c | 2013-10-02 16:55:16 -0700 | [diff] [blame] | 5550 | * @param force565 if true the returned bitmap will be RGB_565, otherwise it |
| 5551 | * will be the same config as the surface |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5552 | */ |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 5553 | @Override |
John Reck | 172e87c | 2013-10-02 16:55:16 -0700 | [diff] [blame] | 5554 | public Bitmap screenshotApplications(IBinder appToken, int displayId, int width, |
| 5555 | int height, boolean force565) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5556 | if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER, |
| 5557 | "screenshotApplications()")) { |
| 5558 | throw new SecurityException("Requires READ_FRAME_BUFFER permission"); |
| 5559 | } |
| 5560 | |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5561 | Bitmap rawss = null; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5562 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5563 | int maxLayer = 0; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5564 | final Rect frame = new Rect(); |
| 5565 | |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5566 | float scale = 0; |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5567 | int dw, dh; |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5568 | int rot = Surface.ROTATION_0; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5569 | |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5570 | boolean screenshotReady; |
| 5571 | int minLayer; |
| 5572 | if (appToken == null) { |
| 5573 | screenshotReady = true; |
| 5574 | minLayer = 0; |
| 5575 | } else { |
| 5576 | screenshotReady = false; |
| 5577 | minLayer = Integer.MAX_VALUE; |
| 5578 | } |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5579 | |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5580 | int retryCount = 0; |
| 5581 | WindowState appWin = null; |
| 5582 | |
| 5583 | do { |
| 5584 | if (retryCount++ > 0) { |
| 5585 | try { |
| 5586 | Thread.sleep(100); |
| 5587 | } catch (InterruptedException e) { |
| 5588 | } |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 5589 | } |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5590 | synchronized(mWindowMap) { |
| 5591 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
| 5592 | if (displayContent == null) { |
| 5593 | return null; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5594 | } |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5595 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 5596 | dw = displayInfo.logicalWidth; |
| 5597 | dh = displayInfo.logicalHeight; |
| 5598 | |
| 5599 | int aboveAppLayer = mPolicy.windowTypeToLayerLw(TYPE_APPLICATION) |
| 5600 | * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET; |
| 5601 | aboveAppLayer += TYPE_LAYER_MULTIPLIER; |
| 5602 | |
| 5603 | boolean isImeTarget = mInputMethodTarget != null |
| 5604 | && mInputMethodTarget.mAppToken != null |
| 5605 | && mInputMethodTarget.mAppToken.appToken != null |
| 5606 | && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken; |
| 5607 | |
| 5608 | // Figure out the part of the screen that is actually the app. |
| 5609 | boolean including = false; |
| 5610 | appWin = null; |
| 5611 | final WindowList windows = displayContent.getWindowList(); |
Craig Mautner | 76ea224 | 2013-05-15 11:40:05 -0700 | [diff] [blame] | 5612 | final Rect stackBounds = new Rect(); |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5613 | for (int i = windows.size() - 1; i >= 0; i--) { |
| 5614 | WindowState ws = windows.get(i); |
| 5615 | if (!ws.mHasSurface) { |
| 5616 | continue; |
| 5617 | } |
| 5618 | if (ws.mLayer >= aboveAppLayer) { |
| 5619 | continue; |
| 5620 | } |
| 5621 | // When we will skip windows: when we are not including |
| 5622 | // ones behind a window we didn't skip, and we are actually |
| 5623 | // taking a screenshot of a specific app. |
| 5624 | if (!including && appToken != null) { |
| 5625 | // Also, we can possibly skip this window if it is not |
| 5626 | // an IME target or the application for the screenshot |
| 5627 | // is not the current IME target. |
| 5628 | if (!ws.mIsImWindow || !isImeTarget) { |
| 5629 | // And finally, this window is of no interest if it |
| 5630 | // is not associated with the screenshot app. |
| 5631 | if (ws.mAppToken == null || ws.mAppToken.token != appToken) { |
| 5632 | continue; |
| 5633 | } |
| 5634 | appWin = ws; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 5635 | ws.getStackBounds(stackBounds); |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5636 | } |
| 5637 | } |
| 5638 | |
| 5639 | // We keep on including windows until we go past a full-screen |
| 5640 | // window. |
Sangkyu Lee | 7ccba97 | 2013-11-21 15:20:33 +0900 | [diff] [blame] | 5641 | including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh); |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5642 | |
| 5643 | final WindowStateAnimator winAnim = ws.mWinAnimator; |
| 5644 | if (maxLayer < winAnim.mSurfaceLayer) { |
| 5645 | maxLayer = winAnim.mSurfaceLayer; |
| 5646 | } |
Craig Mautner | 4238e3e | 2013-03-28 15:28:55 -0700 | [diff] [blame] | 5647 | if (minLayer > winAnim.mSurfaceLayer) { |
| 5648 | minLayer = winAnim.mSurfaceLayer; |
| 5649 | } |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5650 | |
| 5651 | // Don't include wallpaper in bounds calculation |
| 5652 | if (!ws.mIsWallpaper) { |
| 5653 | final Rect wf = ws.mFrame; |
| 5654 | final Rect cr = ws.mContentInsets; |
| 5655 | int left = wf.left + cr.left; |
| 5656 | int top = wf.top + cr.top; |
| 5657 | int right = wf.right - cr.right; |
| 5658 | int bottom = wf.bottom - cr.bottom; |
| 5659 | frame.union(left, top, right, bottom); |
Craig Mautner | 76ea224 | 2013-05-15 11:40:05 -0700 | [diff] [blame] | 5660 | frame.intersect(stackBounds); |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5661 | } |
| 5662 | |
Craig Mautner | 4238e3e | 2013-03-28 15:28:55 -0700 | [diff] [blame] | 5663 | if (ws.mAppToken != null && ws.mAppToken.token == appToken && |
| 5664 | ws.isDisplayedLw()) { |
| 5665 | screenshotReady = true; |
| 5666 | } |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5667 | } |
| 5668 | |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5669 | if (appToken != null && appWin == null) { |
| 5670 | // Can't find a window to snapshot. |
| 5671 | if (DEBUG_SCREENSHOT) Slog.i(TAG, |
| 5672 | "Screenshot: Couldn't find a surface matching " + appToken); |
| 5673 | return null; |
| 5674 | } |
| 5675 | if (!screenshotReady) { |
| 5676 | // Delay and hope that window gets drawn. |
| 5677 | if (DEBUG_SCREENSHOT) Slog.i(TAG, "Screenshot: No image ready for " + appToken |
| 5678 | + ", " + appWin + " drawState=" + appWin.mWinAnimator.mDrawState); |
| 5679 | continue; |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5680 | } |
Craig Mautner | 312eac4 | 2012-11-13 10:56:22 -0800 | [diff] [blame] | 5681 | |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5682 | // Constrain frame to the screen size. |
| 5683 | frame.intersect(0, 0, dw, dh); |
| 5684 | |
| 5685 | if (frame.isEmpty() || maxLayer == 0) { |
| 5686 | if (DEBUG_SCREENSHOT) Slog.i(TAG, "Screenshot of " + appToken |
| 5687 | + ": returning null frame=" + frame.toShortString() + " maxLayer=" |
| 5688 | + maxLayer); |
| 5689 | return null; |
Jim Miller | 2aded18 | 2011-03-08 15:32:42 -0800 | [diff] [blame] | 5690 | } |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5691 | |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5692 | // The screenshot API does not apply the current screen rotation. |
| 5693 | rot = getDefaultDisplayContentLocked().getDisplay().getRotation(); |
| 5694 | int fw = frame.width(); |
| 5695 | int fh = frame.height(); |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5696 | |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5697 | // Constrain thumbnail to smaller of screen width or height. Assumes aspect |
| 5698 | // of thumbnail is the same as the screen (in landscape) or square. |
Craig Mautner | 76ea224 | 2013-05-15 11:40:05 -0700 | [diff] [blame] | 5699 | scale = Math.max(width / (float) fw, height / (float) fh); |
| 5700 | /* |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5701 | float targetWidthScale = width / (float) fw; |
| 5702 | float targetHeightScale = height / (float) fh; |
Craig Mautner | 76ea224 | 2013-05-15 11:40:05 -0700 | [diff] [blame] | 5703 | if (fw <= fh) { |
Michael Jurka | bfd24ac | 2011-11-13 13:50:38 -0800 | [diff] [blame] | 5704 | scale = targetWidthScale; |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5705 | // If aspect of thumbnail is the same as the screen (in landscape), |
| 5706 | // select the slightly larger value so we fill the entire bitmap |
| 5707 | if (targetHeightScale > scale && (int) (targetHeightScale * fw) == width) { |
| 5708 | scale = targetHeightScale; |
| 5709 | } |
| 5710 | } else { |
| 5711 | scale = targetHeightScale; |
| 5712 | // If aspect of thumbnail is the same as the screen (in landscape), |
| 5713 | // select the slightly larger value so we fill the entire bitmap |
| 5714 | if (targetWidthScale > scale && (int) (targetWidthScale * fh) == height) { |
| 5715 | scale = targetWidthScale; |
| 5716 | } |
Michael Jurka | bfd24ac | 2011-11-13 13:50:38 -0800 | [diff] [blame] | 5717 | } |
Craig Mautner | 76ea224 | 2013-05-15 11:40:05 -0700 | [diff] [blame] | 5718 | */ |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5719 | |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5720 | // The screen shot will contain the entire screen. |
| 5721 | dw = (int)(dw*scale); |
| 5722 | dh = (int)(dh*scale); |
| 5723 | if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) { |
| 5724 | int tmp = dw; |
| 5725 | dw = dh; |
| 5726 | dh = tmp; |
| 5727 | rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90; |
Dianne Hackborn | cfb9f2b | 2011-08-24 10:51:49 -0700 | [diff] [blame] | 5728 | } |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5729 | if (DEBUG_SCREENSHOT) { |
| 5730 | Slog.i(TAG, "Screenshot: " + dw + "x" + dh + " from " + minLayer + " to " |
| 5731 | + maxLayer + " appToken=" + appToken); |
| 5732 | for (int i = 0; i < windows.size(); i++) { |
| 5733 | WindowState win = windows.get(i); |
| 5734 | Slog.i(TAG, win + ": " + win.mLayer |
| 5735 | + " animLayer=" + win.mWinAnimator.mAnimLayer |
| 5736 | + " surfaceLayer=" + win.mWinAnimator.mSurfaceLayer); |
| 5737 | } |
| 5738 | } |
Dan Stoza | 16ec12a | 2014-02-14 15:06:55 -0800 | [diff] [blame] | 5739 | // TODO: Replace 'false' in the following line with a variable that indicates |
| 5740 | // whether the screenshot should use the identity transformation matrix |
| 5741 | // (e.g., enable it when taking a screenshot for recents, since we might be in |
| 5742 | // the middle of the rotation animation, but don't want a rotated recent image). |
| 5743 | rawss = SurfaceControl.screenshot(dw, dh, minLayer, maxLayer, false); |
Dianne Hackborn | cfb9f2b | 2011-08-24 10:51:49 -0700 | [diff] [blame] | 5744 | } |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5745 | } while (!screenshotReady && retryCount <= MAX_SCREENSHOT_RETRIES); |
Craig Mautner | 4238e3e | 2013-03-28 15:28:55 -0700 | [diff] [blame] | 5746 | if (retryCount > MAX_SCREENSHOT_RETRIES) Slog.i(TAG, "Screenshot max retries " + |
| 5747 | retryCount + " of " + appToken + " appWin=" + (appWin == null ? |
| 5748 | "null" : (appWin + " drawState=" + appWin.mWinAnimator.mDrawState))); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5749 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5750 | if (rawss == null) { |
Craig Mautner | 4238e3e | 2013-03-28 15:28:55 -0700 | [diff] [blame] | 5751 | Slog.w(TAG, "Screenshot failure taking screenshot for (" + dw + "x" + dh |
Dianne Hackborn | 88b03bd | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5752 | + ") to layer " + maxLayer); |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5753 | return null; |
| 5754 | } |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5755 | |
John Reck | 172e87c | 2013-10-02 16:55:16 -0700 | [diff] [blame] | 5756 | Bitmap bm = Bitmap.createBitmap(width, height, force565 ? Config.RGB_565 : rawss.getConfig()); |
Craig Mautner | 76ea224 | 2013-05-15 11:40:05 -0700 | [diff] [blame] | 5757 | frame.scale(scale); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5758 | Matrix matrix = new Matrix(); |
| 5759 | ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix); |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 5760 | // TODO: Test for RTL vs. LTR and use frame.right-width instead of -frame.left |
Craig Mautner | 76ea224 | 2013-05-15 11:40:05 -0700 | [diff] [blame] | 5761 | matrix.postTranslate(-FloatMath.ceil(frame.left), -FloatMath.ceil(frame.top)); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5762 | Canvas canvas = new Canvas(bm); |
Dianne Hackborn | ca46b87 | 2013-04-17 18:06:22 -0700 | [diff] [blame] | 5763 | canvas.drawColor(0xFF000000); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5764 | canvas.drawBitmap(rawss, matrix, null); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 5765 | canvas.setBitmap(null); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5766 | |
Craig Mautner | 4697bea | 2013-10-24 09:13:14 -0700 | [diff] [blame] | 5767 | if (DEBUG_SCREENSHOT) { |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5768 | // TEST IF IT's ALL BLACK |
| 5769 | int[] buffer = new int[bm.getWidth() * bm.getHeight()]; |
| 5770 | bm.getPixels(buffer, 0, bm.getWidth(), 0, 0, bm.getWidth(), bm.getHeight()); |
| 5771 | boolean allBlack = true; |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 5772 | final int firstColor = buffer[0]; |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5773 | for (int i = 0; i < buffer.length; i++) { |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 5774 | if (buffer[i] != firstColor) { |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5775 | allBlack = false; |
| 5776 | break; |
| 5777 | } |
| 5778 | } |
| 5779 | if (allBlack) { |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 5780 | Slog.i(TAG, "Screenshot " + appWin + " was monochrome(" + |
| 5781 | Integer.toHexString(firstColor) + ")! mSurfaceLayer=" + |
Craig Mautner | 4238e3e | 2013-03-28 15:28:55 -0700 | [diff] [blame] | 5782 | (appWin != null ? appWin.mWinAnimator.mSurfaceLayer : "null") + |
| 5783 | " minLayer=" + minLayer + " maxLayer=" + maxLayer); |
Craig Mautner | 24d88747 | 2013-03-20 15:40:36 -0700 | [diff] [blame] | 5784 | } |
| 5785 | } |
| 5786 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5787 | rawss.recycle(); |
| 5788 | return bm; |
| 5789 | } |
| 5790 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5791 | /** |
| 5792 | * Freeze rotation changes. (Enable "rotation lock".) |
| 5793 | * Persists across reboots. |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5794 | * @param rotation The desired rotation to freeze to, or -1 to use the |
| 5795 | * current rotation. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5796 | */ |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 5797 | @Override |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5798 | public void freezeRotation(int rotation) { |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5799 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5800 | "freezeRotation()")) { |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5801 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5802 | } |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5803 | if (rotation < -1 || rotation > Surface.ROTATION_270) { |
| 5804 | throw new IllegalArgumentException("Rotation argument must be -1 or a valid " |
| 5805 | + "rotation constant."); |
| 5806 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5807 | |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5808 | if (DEBUG_ORIENTATION) Slog.v(TAG, "freezeRotation: mRotation=" + mRotation); |
| 5809 | |
Daniel Sandler | 3de830b | 2013-02-20 15:23:52 -0500 | [diff] [blame] | 5810 | long origId = Binder.clearCallingIdentity(); |
| 5811 | try { |
| 5812 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, |
| 5813 | rotation == -1 ? mRotation : rotation); |
| 5814 | } finally { |
| 5815 | Binder.restoreCallingIdentity(origId); |
| 5816 | } |
| 5817 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5818 | updateRotationUnchecked(false, false); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5819 | } |
| 5820 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5821 | /** |
| 5822 | * Thaw rotation changes. (Disable "rotation lock".) |
| 5823 | * Persists across reboots. |
| 5824 | */ |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 5825 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5826 | public void thawRotation() { |
| 5827 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5828 | "thawRotation()")) { |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5829 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5830 | } |
| 5831 | |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5832 | if (DEBUG_ORIENTATION) Slog.v(TAG, "thawRotation: mRotation=" + mRotation); |
| 5833 | |
Daniel Sandler | 3de830b | 2013-02-20 15:23:52 -0500 | [diff] [blame] | 5834 | long origId = Binder.clearCallingIdentity(); |
| 5835 | try { |
| 5836 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, |
| 5837 | 777); // rot not used |
| 5838 | } finally { |
| 5839 | Binder.restoreCallingIdentity(origId); |
| 5840 | } |
| 5841 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5842 | updateRotationUnchecked(false, false); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5843 | } |
| 5844 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5845 | /** |
| 5846 | * Recalculate the current rotation. |
| 5847 | * |
| 5848 | * Called by the window manager policy whenever the state of the system changes |
| 5849 | * such that the current rotation might need to be updated, such as when the |
| 5850 | * device is docked or rotated into a new posture. |
| 5851 | */ |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 5852 | @Override |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5853 | public void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 5854 | updateRotationUnchecked(alwaysSendConfiguration, forceRelayout); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5855 | } |
| 5856 | |
| 5857 | /** |
| 5858 | * Temporarily pauses rotation changes until resumed. |
| 5859 | * |
| 5860 | * This can be used to prevent rotation changes from occurring while the user is |
| 5861 | * performing certain operations, such as drag and drop. |
| 5862 | * |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 5863 | * This call nests and must be matched by an equal number of calls to |
| 5864 | * {@link #resumeRotationLocked}. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5865 | */ |
| 5866 | void pauseRotationLocked() { |
| 5867 | mDeferredRotationPauseCount += 1; |
| 5868 | } |
| 5869 | |
| 5870 | /** |
| 5871 | * Resumes normal rotation changes after being paused. |
| 5872 | */ |
| 5873 | void resumeRotationLocked() { |
| 5874 | if (mDeferredRotationPauseCount > 0) { |
| 5875 | mDeferredRotationPauseCount -= 1; |
| 5876 | if (mDeferredRotationPauseCount == 0) { |
| 5877 | boolean changed = updateRotationUncheckedLocked(false); |
| 5878 | if (changed) { |
| 5879 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 5880 | } |
| 5881 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5882 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5883 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5884 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5885 | public void updateRotationUnchecked(boolean alwaysSendConfiguration, boolean forceRelayout) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5886 | if(DEBUG_ORIENTATION) Slog.v(TAG, "updateRotationUnchecked(" |
| 5887 | + "alwaysSendConfiguration=" + alwaysSendConfiguration + ")"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5888 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5889 | long origId = Binder.clearCallingIdentity(); |
| 5890 | boolean changed; |
| 5891 | synchronized(mWindowMap) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5892 | changed = updateRotationUncheckedLocked(false); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5893 | if (!changed || forceRelayout) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 5894 | getDefaultDisplayContentLocked().layoutNeeded = true; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5895 | performLayoutAndPlaceSurfacesLocked(); |
| 5896 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5897 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5898 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5899 | if (changed || alwaysSendConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5900 | sendNewConfiguration(); |
| 5901 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5903 | Binder.restoreCallingIdentity(origId); |
| 5904 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5905 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5906 | // TODO(multidisplay): Rotate any display? |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5907 | /** |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5908 | * Updates the current rotation. |
| 5909 | * |
| 5910 | * Returns true if the rotation has been changed. In this case YOU |
| 5911 | * MUST CALL sendNewConfiguration() TO UNFREEZE THE SCREEN. |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5912 | */ |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5913 | public boolean updateRotationUncheckedLocked(boolean inTransaction) { |
| 5914 | if (mDeferredRotationPauseCount > 0) { |
| 5915 | // Rotation updates have been paused temporarily. Defer the update until |
| 5916 | // updates have been resumed. |
| 5917 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation, rotation is paused."); |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 5918 | return false; |
| 5919 | } |
| 5920 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 5921 | ScreenRotationAnimation screenRotationAnimation = |
| 5922 | mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY); |
| 5923 | if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5924 | // Rotation updates cannot be performed while the previous rotation change |
| 5925 | // animation is still in progress. Skip this update. We will try updating |
| 5926 | // again after the animation is finished and the display is unfrozen. |
| 5927 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation, animation in progress."); |
| 5928 | return false; |
| 5929 | } |
| 5930 | |
| 5931 | if (!mDisplayEnabled) { |
| 5932 | // No point choosing a rotation if the display is not enabled. |
| 5933 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation, display is not enabled."); |
| 5934 | return false; |
| 5935 | } |
| 5936 | |
| 5937 | // TODO: Implement forced rotation changes. |
| 5938 | // Set mAltOrientation to indicate that the application is receiving |
| 5939 | // an orientation that has different metrics than it expected. |
| 5940 | // eg. Portrait instead of Landscape. |
| 5941 | |
| 5942 | int rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, mRotation); |
| 5943 | boolean altOrientation = !mPolicy.rotationHasCompatibleMetricsLw( |
| 5944 | mForcedAppOrientation, rotation); |
| 5945 | |
| 5946 | if (DEBUG_ORIENTATION) { |
| 5947 | Slog.v(TAG, "Application requested orientation " |
| 5948 | + mForcedAppOrientation + ", got rotation " + rotation |
| 5949 | + " which has " + (altOrientation ? "incompatible" : "compatible") |
| 5950 | + " metrics"); |
| 5951 | } |
| 5952 | |
| 5953 | if (mRotation == rotation && mAltOrientation == altOrientation) { |
| 5954 | // No change. |
| 5955 | return false; |
| 5956 | } |
| 5957 | |
| 5958 | if (DEBUG_ORIENTATION) { |
| 5959 | Slog.v(TAG, |
| 5960 | "Rotation changed to " + rotation + (altOrientation ? " (alt)" : "") |
| 5961 | + " from " + mRotation + (mAltOrientation ? " (alt)" : "") |
| 5962 | + ", forceApp=" + mForcedAppOrientation); |
| 5963 | } |
| 5964 | |
| 5965 | mRotation = rotation; |
| 5966 | mAltOrientation = altOrientation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5967 | mPolicy.setRotationLw(mRotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5968 | |
| 5969 | mWindowsFreezingScreen = true; |
| 5970 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 5971 | mH.sendEmptyMessageDelayed(H.WINDOW_FREEZE_TIMEOUT, WINDOW_FREEZE_TIMEOUT_DURATION); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5972 | mWaitingForConfig = true; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 5973 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
| 5974 | displayContent.layoutNeeded = true; |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 5975 | final int[] anim = new int[2]; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 5976 | if (displayContent.isDimming()) { |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 5977 | anim[0] = anim[1] = 0; |
| 5978 | } else { |
| 5979 | mPolicy.selectRotationAnimationLw(anim); |
| 5980 | } |
| 5981 | startFreezingDisplayLocked(inTransaction, anim[0], anim[1]); |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 5982 | // startFreezingDisplayLocked can reset the ScreenRotationAnimation. |
| 5983 | screenRotationAnimation = |
| 5984 | mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5985 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 5986 | // We need to update our screen size information to match the new |
| 5987 | // rotation. Note that this is redundant with the later call to |
| 5988 | // sendNewConfiguration() that must be called after this function |
| 5989 | // returns... however we need to do the screen size part of that |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 5990 | // before then so we have the correct size to use when initializing |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 5991 | // the rotation animation for the new rotation. |
| 5992 | computeScreenConfigurationLocked(null); |
| 5993 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5994 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 5995 | if (!inTransaction) { |
| 5996 | if (SHOW_TRANSACTIONS) { |
| 5997 | Slog.i(TAG, ">>> OPEN TRANSACTION setRotationUnchecked"); |
| 5998 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 5999 | SurfaceControl.openTransaction(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 6000 | } |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 6001 | try { |
| 6002 | // NOTE: We disable the rotation in the emulator because |
| 6003 | // it doesn't support hardware OpenGL emulation yet. |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 6004 | if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null |
| 6005 | && screenRotationAnimation.hasScreenshot()) { |
| 6006 | if (screenRotationAnimation.setRotationInTransaction( |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 6007 | rotation, mFxSession, |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6008 | MAX_ANIMATION_DURATION, mTransitionAnimationScale, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6009 | displayInfo.logicalWidth, displayInfo.logicalHeight)) { |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 6010 | scheduleAnimationLocked(); |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6011 | } |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 6012 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 6013 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 6014 | mDisplayManagerInternal.performTraversalInTransactionFromWindowManager(); |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 6015 | } finally { |
| 6016 | if (!inTransaction) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 6017 | SurfaceControl.closeTransaction(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 6018 | if (SHOW_LIGHT_TRANSACTIONS) { |
| 6019 | Slog.i(TAG, "<<< CLOSE TRANSACTION setRotationUnchecked"); |
| 6020 | } |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 6021 | } |
| 6022 | } |
| 6023 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6024 | final WindowList windows = displayContent.getWindowList(); |
| 6025 | for (int i = windows.size() - 1; i >= 0; i--) { |
| 6026 | WindowState w = windows.get(i); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 6027 | if (w.mHasSurface) { |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 6028 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Set mOrientationChanging of " + w); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6029 | w.mOrientationChanging = true; |
Craig Mautner | 3255a28 | 2012-04-16 15:42:47 -0700 | [diff] [blame] | 6030 | mInnerFields.mOrientationChangeComplete = false; |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6031 | } |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 6032 | w.mLastFreezeDuration = 0; |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6033 | } |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6034 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6035 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 6036 | try { |
Jim Miller | 7267ed1 | 2013-12-09 17:38:05 -0800 | [diff] [blame] | 6037 | mRotationWatchers.get(i).watcher.onRotationChanged(rotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6038 | } catch (RemoteException e) { |
| 6039 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6040 | } |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6041 | |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 6042 | //TODO (multidisplay): Magnification is supported only for the default display. |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 6043 | if (mAccessibilityController != null |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 6044 | && displayContent.getDisplayId() == Display.DEFAULT_DISPLAY) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 6045 | mAccessibilityController.onRotationChangedLocked(getDefaultDisplayContentLocked(), rotation); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 6046 | } |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6047 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6048 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6049 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6050 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 6051 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6052 | public int getRotation() { |
| 6053 | return mRotation; |
| 6054 | } |
| 6055 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 6056 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 6057 | public boolean isRotationFrozen() { |
| 6058 | return mPolicy.getUserRotationMode() == WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 6059 | } |
| 6060 | |
| 6061 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6062 | public int watchRotation(IRotationWatcher watcher) { |
| 6063 | final IBinder watcherBinder = watcher.asBinder(); |
| 6064 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 6065 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6066 | public void binderDied() { |
| 6067 | synchronized (mWindowMap) { |
| 6068 | for (int i=0; i<mRotationWatchers.size(); i++) { |
Jim Miller | 7267ed1 | 2013-12-09 17:38:05 -0800 | [diff] [blame] | 6069 | if (watcherBinder == mRotationWatchers.get(i).watcher.asBinder()) { |
| 6070 | RotationWatcher removed = mRotationWatchers.remove(i); |
| 6071 | IBinder binder = removed.watcher.asBinder(); |
| 6072 | if (binder != null) { |
| 6073 | binder.unlinkToDeath(this, 0); |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6074 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6075 | i--; |
| 6076 | } |
| 6077 | } |
| 6078 | } |
| 6079 | } |
| 6080 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6081 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6082 | synchronized (mWindowMap) { |
| 6083 | try { |
| 6084 | watcher.asBinder().linkToDeath(dr, 0); |
Jim Miller | 7267ed1 | 2013-12-09 17:38:05 -0800 | [diff] [blame] | 6085 | mRotationWatchers.add(new RotationWatcher(watcher, dr)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6086 | } catch (RemoteException e) { |
| 6087 | // Client died, no cleanup needed. |
| 6088 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6089 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6090 | return mRotation; |
| 6091 | } |
| 6092 | } |
| 6093 | |
Brian Colonna | b1b9a8a | 2013-03-29 11:52:42 -0400 | [diff] [blame] | 6094 | @Override |
| 6095 | public void removeRotationWatcher(IRotationWatcher watcher) { |
| 6096 | final IBinder watcherBinder = watcher.asBinder(); |
| 6097 | synchronized (mWindowMap) { |
| 6098 | for (int i=0; i<mRotationWatchers.size(); i++) { |
Jim Miller | 7267ed1 | 2013-12-09 17:38:05 -0800 | [diff] [blame] | 6099 | RotationWatcher rotationWatcher = mRotationWatchers.get(i); |
| 6100 | if (watcherBinder == rotationWatcher.watcher.asBinder()) { |
| 6101 | RotationWatcher removed = mRotationWatchers.remove(i); |
| 6102 | IBinder binder = removed.watcher.asBinder(); |
| 6103 | if (binder != null) { |
| 6104 | binder.unlinkToDeath(removed.deathRecipient, 0); |
| 6105 | } |
Brian Colonna | b1b9a8a | 2013-03-29 11:52:42 -0400 | [diff] [blame] | 6106 | i--; |
| 6107 | } |
| 6108 | } |
| 6109 | } |
| 6110 | } |
| 6111 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6112 | /** |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 6113 | * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact |
| 6114 | * theme attribute) on devices that feature a physical options menu key attempt to position |
| 6115 | * their menu panel window along the edge of the screen nearest the physical menu key. |
| 6116 | * This lowers the travel distance between invoking the menu panel and selecting |
| 6117 | * a menu option. |
| 6118 | * |
| 6119 | * This method helps control where that menu is placed. Its current implementation makes |
| 6120 | * assumptions about the menu key and its relationship to the screen based on whether |
| 6121 | * the device's natural orientation is portrait (width < height) or landscape. |
| 6122 | * |
| 6123 | * The menu key is assumed to be located along the bottom edge of natural-portrait |
| 6124 | * devices and along the right edge of natural-landscape devices. If these assumptions |
| 6125 | * do not hold for the target device, this method should be changed to reflect that. |
| 6126 | * |
| 6127 | * @return A {@link Gravity} value for placing the options menu window |
| 6128 | */ |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 6129 | @Override |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 6130 | public int getPreferredOptionsPanelGravity() { |
| 6131 | synchronized (mWindowMap) { |
| 6132 | final int rotation = getRotation(); |
| 6133 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6134 | // TODO(multidisplay): Assume that such devices physical keys are on the main screen. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 6135 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6136 | if (displayContent.mInitialDisplayWidth < displayContent.mInitialDisplayHeight) { |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 6137 | // On devices with a natural orientation of portrait |
| 6138 | switch (rotation) { |
| 6139 | default: |
| 6140 | case Surface.ROTATION_0: |
| 6141 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 6142 | case Surface.ROTATION_90: |
Adam Powell | 67ed6c7 | 2011-08-28 13:21:56 -0700 | [diff] [blame] | 6143 | return Gravity.RIGHT | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 6144 | case Surface.ROTATION_180: |
Adam Powell | 67ed6c7 | 2011-08-28 13:21:56 -0700 | [diff] [blame] | 6145 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 6146 | case Surface.ROTATION_270: |
Fabrice Di Meglio | aac0d4e | 2012-07-19 19:21:26 -0700 | [diff] [blame] | 6147 | return Gravity.START | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 6148 | } |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 6149 | } |
| 6150 | |
| 6151 | // On devices with a natural orientation of landscape |
| 6152 | switch (rotation) { |
| 6153 | default: |
| 6154 | case Surface.ROTATION_0: |
| 6155 | return Gravity.RIGHT | Gravity.BOTTOM; |
| 6156 | case Surface.ROTATION_90: |
| 6157 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 6158 | case Surface.ROTATION_180: |
| 6159 | return Gravity.START | Gravity.BOTTOM; |
| 6160 | case Surface.ROTATION_270: |
| 6161 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 6162 | } |
| 6163 | } |
| 6164 | } |
| 6165 | |
| 6166 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6167 | * Starts the view server on the specified port. |
| 6168 | * |
| 6169 | * @param port The port to listener to. |
| 6170 | * |
| 6171 | * @return True if the server was successfully started, false otherwise. |
| 6172 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 6173 | * @see com.android.server.wm.ViewServer |
| 6174 | * @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] | 6175 | */ |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 6176 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6177 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6178 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6179 | return false; |
| 6180 | } |
| 6181 | |
| 6182 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 6183 | return false; |
| 6184 | } |
| 6185 | |
| 6186 | if (port < 1024) { |
| 6187 | return false; |
| 6188 | } |
| 6189 | |
| 6190 | if (mViewServer != null) { |
| 6191 | if (!mViewServer.isRunning()) { |
| 6192 | try { |
| 6193 | return mViewServer.start(); |
| 6194 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6195 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6196 | } |
| 6197 | } |
| 6198 | return false; |
| 6199 | } |
| 6200 | |
| 6201 | try { |
| 6202 | mViewServer = new ViewServer(this, port); |
| 6203 | return mViewServer.start(); |
| 6204 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6205 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6206 | } |
| 6207 | return false; |
| 6208 | } |
| 6209 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6210 | private boolean isSystemSecure() { |
| 6211 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 6212 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 6213 | } |
| 6214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6215 | /** |
| 6216 | * Stops the view server if it exists. |
| 6217 | * |
| 6218 | * @return True if the server stopped, false if it wasn't started or |
| 6219 | * couldn't be stopped. |
| 6220 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 6221 | * @see com.android.server.wm.ViewServer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6222 | */ |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 6223 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6224 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6225 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6226 | return false; |
| 6227 | } |
| 6228 | |
| 6229 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 6230 | return false; |
| 6231 | } |
| 6232 | |
| 6233 | if (mViewServer != null) { |
| 6234 | return mViewServer.stop(); |
| 6235 | } |
| 6236 | return false; |
| 6237 | } |
| 6238 | |
| 6239 | /** |
| 6240 | * Indicates whether the view server is running. |
| 6241 | * |
| 6242 | * @return True if the server is running, false otherwise. |
| 6243 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 6244 | * @see com.android.server.wm.ViewServer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6245 | */ |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 6246 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6247 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6248 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6249 | return false; |
| 6250 | } |
| 6251 | |
| 6252 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 6253 | return false; |
| 6254 | } |
| 6255 | |
| 6256 | return mViewServer != null && mViewServer.isRunning(); |
| 6257 | } |
| 6258 | |
| 6259 | /** |
| 6260 | * Lists all availble windows in the system. The listing is written in the |
| 6261 | * specified Socket's output stream with the following syntax: |
| 6262 | * windowHashCodeInHexadecimal windowName |
| 6263 | * Each line of the ouput represents a different window. |
| 6264 | * |
| 6265 | * @param client The remote client to send the listing to. |
| 6266 | * @return False if an error occured, true otherwise. |
| 6267 | */ |
| 6268 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6269 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6270 | return false; |
| 6271 | } |
| 6272 | |
| 6273 | boolean result = true; |
| 6274 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6275 | WindowList windows = new WindowList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6276 | synchronized (mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6277 | //noinspection unchecked |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 6278 | final int numDisplays = mDisplayContents.size(); |
| 6279 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 6280 | final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx); |
| 6281 | windows.addAll(displayContent.getWindowList()); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6282 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6283 | } |
| 6284 | |
| 6285 | BufferedWriter out = null; |
| 6286 | |
| 6287 | // Any uncaught exception will crash the system process |
| 6288 | try { |
| 6289 | OutputStream clientStream = client.getOutputStream(); |
| 6290 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 6291 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6292 | final int count = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6293 | for (int i = 0; i < count; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6294 | final WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6295 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 6296 | out.write(' '); |
| 6297 | out.append(w.mAttrs.getTitle()); |
| 6298 | out.write('\n'); |
| 6299 | } |
| 6300 | |
| 6301 | out.write("DONE.\n"); |
| 6302 | out.flush(); |
| 6303 | } catch (Exception e) { |
| 6304 | result = false; |
| 6305 | } finally { |
| 6306 | if (out != null) { |
| 6307 | try { |
| 6308 | out.close(); |
| 6309 | } catch (IOException e) { |
| 6310 | result = false; |
| 6311 | } |
| 6312 | } |
| 6313 | } |
| 6314 | |
| 6315 | return result; |
| 6316 | } |
| 6317 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6318 | // TODO(multidisplay): Extend to multiple displays. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6319 | /** |
Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 6320 | * Returns the focused window in the following format: |
| 6321 | * windowHashCodeInHexadecimal windowName |
| 6322 | * |
| 6323 | * @param client The remote client to send the listing to. |
| 6324 | * @return False if an error occurred, true otherwise. |
| 6325 | */ |
| 6326 | boolean viewServerGetFocusedWindow(Socket client) { |
| 6327 | if (isSystemSecure()) { |
| 6328 | return false; |
| 6329 | } |
| 6330 | |
| 6331 | boolean result = true; |
| 6332 | |
| 6333 | WindowState focusedWindow = getFocusedWindow(); |
| 6334 | |
| 6335 | BufferedWriter out = null; |
| 6336 | |
| 6337 | // Any uncaught exception will crash the system process |
| 6338 | try { |
| 6339 | OutputStream clientStream = client.getOutputStream(); |
| 6340 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 6341 | |
| 6342 | if(focusedWindow != null) { |
| 6343 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 6344 | out.write(' '); |
| 6345 | out.append(focusedWindow.mAttrs.getTitle()); |
| 6346 | } |
| 6347 | out.write('\n'); |
| 6348 | out.flush(); |
| 6349 | } catch (Exception e) { |
| 6350 | result = false; |
| 6351 | } finally { |
| 6352 | if (out != null) { |
| 6353 | try { |
| 6354 | out.close(); |
| 6355 | } catch (IOException e) { |
| 6356 | result = false; |
| 6357 | } |
| 6358 | } |
| 6359 | } |
| 6360 | |
| 6361 | return result; |
| 6362 | } |
| 6363 | |
| 6364 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6365 | * Sends a command to a target window. The result of the command, if any, will be |
| 6366 | * written in the output stream of the specified socket. |
| 6367 | * |
| 6368 | * The parameters must follow this syntax: |
| 6369 | * windowHashcode extra |
| 6370 | * |
| 6371 | * Where XX is the length in characeters of the windowTitle. |
| 6372 | * |
| 6373 | * The first parameter is the target window. The window with the specified hashcode |
| 6374 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 6375 | * will be delivered to the target window and as parameters to the command itself. |
| 6376 | * |
| 6377 | * @param client The remote client to sent the result, if any, to. |
| 6378 | * @param command The command to execute. |
| 6379 | * @param parameters The command parameters. |
| 6380 | * |
| 6381 | * @return True if the command was successfully delivered, false otherwise. This does |
| 6382 | * not indicate whether the command itself was successful. |
| 6383 | */ |
| 6384 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6385 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6386 | return false; |
| 6387 | } |
| 6388 | |
| 6389 | boolean success = true; |
| 6390 | Parcel data = null; |
| 6391 | Parcel reply = null; |
| 6392 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 6393 | BufferedWriter out = null; |
| 6394 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6395 | // Any uncaught exception will crash the system process |
| 6396 | try { |
| 6397 | // Find the hashcode of the window |
| 6398 | int index = parameters.indexOf(' '); |
| 6399 | if (index == -1) { |
| 6400 | index = parameters.length(); |
| 6401 | } |
| 6402 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 6403 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6404 | |
| 6405 | // Extract the command's parameter after the window description |
| 6406 | if (index < parameters.length()) { |
| 6407 | parameters = parameters.substring(index + 1); |
| 6408 | } else { |
| 6409 | parameters = ""; |
| 6410 | } |
| 6411 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 6412 | final WindowState window = findWindow(hashCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6413 | if (window == null) { |
| 6414 | return false; |
| 6415 | } |
| 6416 | |
| 6417 | data = Parcel.obtain(); |
| 6418 | data.writeInterfaceToken("android.view.IWindow"); |
| 6419 | data.writeString(command); |
| 6420 | data.writeString(parameters); |
| 6421 | data.writeInt(1); |
| 6422 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 6423 | |
| 6424 | reply = Parcel.obtain(); |
| 6425 | |
| 6426 | final IBinder binder = window.mClient.asBinder(); |
| 6427 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 6428 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 6429 | |
| 6430 | reply.readException(); |
| 6431 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 6432 | if (!client.isOutputShutdown()) { |
| 6433 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 6434 | out.write("DONE\n"); |
| 6435 | out.flush(); |
| 6436 | } |
| 6437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6438 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6439 | 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] | 6440 | success = false; |
| 6441 | } finally { |
| 6442 | if (data != null) { |
| 6443 | data.recycle(); |
| 6444 | } |
| 6445 | if (reply != null) { |
| 6446 | reply.recycle(); |
| 6447 | } |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 6448 | if (out != null) { |
| 6449 | try { |
| 6450 | out.close(); |
| 6451 | } catch (IOException e) { |
| 6452 | |
| 6453 | } |
| 6454 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6455 | } |
| 6456 | |
| 6457 | return success; |
| 6458 | } |
| 6459 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 6460 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 6461 | synchronized(mWindowMap) { |
| 6462 | mWindowChangeListeners.add(listener); |
| 6463 | } |
| 6464 | } |
| 6465 | |
| 6466 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 6467 | synchronized(mWindowMap) { |
| 6468 | mWindowChangeListeners.remove(listener); |
| 6469 | } |
| 6470 | } |
| 6471 | |
| 6472 | private void notifyWindowsChanged() { |
| 6473 | WindowChangeListener[] windowChangeListeners; |
| 6474 | synchronized(mWindowMap) { |
| 6475 | if(mWindowChangeListeners.isEmpty()) { |
| 6476 | return; |
| 6477 | } |
| 6478 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 6479 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 6480 | } |
| 6481 | int N = windowChangeListeners.length; |
| 6482 | for(int i = 0; i < N; i++) { |
| 6483 | windowChangeListeners[i].windowsChanged(); |
| 6484 | } |
| 6485 | } |
| 6486 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 6487 | private void notifyFocusChanged() { |
| 6488 | WindowChangeListener[] windowChangeListeners; |
| 6489 | synchronized(mWindowMap) { |
| 6490 | if(mWindowChangeListeners.isEmpty()) { |
| 6491 | return; |
| 6492 | } |
| 6493 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 6494 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 6495 | } |
| 6496 | int N = windowChangeListeners.length; |
| 6497 | for(int i = 0; i < N; i++) { |
| 6498 | windowChangeListeners[i].focusChanged(); |
| 6499 | } |
| 6500 | } |
| 6501 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6502 | private WindowState findWindow(int hashCode) { |
| 6503 | if (hashCode == -1) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6504 | // TODO(multidisplay): Extend to multiple displays. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6505 | return getFocusedWindow(); |
| 6506 | } |
| 6507 | |
| 6508 | synchronized (mWindowMap) { |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 6509 | final int numDisplays = mDisplayContents.size(); |
| 6510 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 6511 | final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList(); |
| 6512 | final int numWindows = windows.size(); |
| 6513 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 6514 | final WindowState w = windows.get(winNdx); |
| 6515 | if (System.identityHashCode(w) == hashCode) { |
| 6516 | return w; |
| 6517 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6518 | } |
| 6519 | } |
| 6520 | } |
| 6521 | |
| 6522 | return null; |
| 6523 | } |
| 6524 | |
| 6525 | /* |
| 6526 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 6527 | * that to config-changed listeners if appropriate. |
| 6528 | */ |
| 6529 | void sendNewConfiguration() { |
| 6530 | try { |
| 6531 | mActivityManager.updateConfiguration(null); |
| 6532 | } catch (RemoteException e) { |
| 6533 | } |
| 6534 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6536 | public Configuration computeNewConfiguration() { |
| 6537 | synchronized (mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6538 | Configuration config = computeNewConfigurationLocked(); |
| 6539 | if (config == null && mWaitingForConfig) { |
| 6540 | // Nothing changed but we are waiting for something... stop that! |
| 6541 | mWaitingForConfig = false; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 6542 | mLastFinishedFreezeSource = "new-config"; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6543 | performLayoutAndPlaceSurfacesLocked(); |
| 6544 | } |
| 6545 | return config; |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6546 | } |
| 6547 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6548 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6549 | Configuration computeNewConfigurationLocked() { |
| 6550 | Configuration config = new Configuration(); |
Dianne Hackborn | 09e5b9d | 2011-10-04 16:32:01 -0700 | [diff] [blame] | 6551 | config.fontScale = 0; |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6552 | if (!computeScreenConfigurationLocked(config)) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6553 | return null; |
| 6554 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6555 | return config; |
| 6556 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6557 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6558 | private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation, int dw, int dh) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 6559 | // TODO: Multidisplay: for now only use with default display. |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 6560 | final int width = mPolicy.getConfigDisplayWidth(dw, dh, rotation); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6561 | if (width < displayInfo.smallestNominalAppWidth) { |
| 6562 | displayInfo.smallestNominalAppWidth = width; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 6563 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6564 | if (width > displayInfo.largestNominalAppWidth) { |
| 6565 | displayInfo.largestNominalAppWidth = width; |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 6566 | } |
| 6567 | final int height = mPolicy.getConfigDisplayHeight(dw, dh, rotation); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6568 | if (height < displayInfo.smallestNominalAppHeight) { |
| 6569 | displayInfo.smallestNominalAppHeight = height; |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 6570 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6571 | if (height > displayInfo.largestNominalAppHeight) { |
| 6572 | displayInfo.largestNominalAppHeight = height; |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 6573 | } |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 6574 | } |
| 6575 | |
Dianne Hackborn | 56b53b5 | 2011-11-10 11:19:57 -0800 | [diff] [blame] | 6576 | private int reduceConfigLayout(int curLayout, int rotation, float density, |
| 6577 | int dw, int dh) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 6578 | // TODO: Multidisplay: for now only use with default display. |
Dianne Hackborn | 56b53b5 | 2011-11-10 11:19:57 -0800 | [diff] [blame] | 6579 | // Get the app screen size at this rotation. |
| 6580 | int w = mPolicy.getNonDecorDisplayWidth(dw, dh, rotation); |
| 6581 | int h = mPolicy.getNonDecorDisplayHeight(dw, dh, rotation); |
| 6582 | |
| 6583 | // Compute the screen layout size class for this rotation. |
Dianne Hackborn | 56b53b5 | 2011-11-10 11:19:57 -0800 | [diff] [blame] | 6584 | int longSize = w; |
| 6585 | int shortSize = h; |
| 6586 | if (longSize < shortSize) { |
| 6587 | int tmp = longSize; |
| 6588 | longSize = shortSize; |
| 6589 | shortSize = tmp; |
| 6590 | } |
| 6591 | longSize = (int)(longSize/density); |
| 6592 | shortSize = (int)(shortSize/density); |
Dianne Hackborn | fe37f8f | 2012-09-30 12:24:33 -0700 | [diff] [blame] | 6593 | return Configuration.reduceScreenLayout(curLayout, longSize, shortSize); |
Dianne Hackborn | 56b53b5 | 2011-11-10 11:19:57 -0800 | [diff] [blame] | 6594 | } |
| 6595 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6596 | private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated, |
| 6597 | int dw, int dh, float density, Configuration outConfig) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 6598 | // TODO: Multidisplay: for now only use with default display. |
| 6599 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6600 | // We need to determine the smallest width that will occur under normal |
| 6601 | // operation. To this, start with the base screen size and compute the |
| 6602 | // width under the different possible rotations. We need to un-rotate |
| 6603 | // the current screen dimensions before doing this. |
| 6604 | int unrotDw, unrotDh; |
| 6605 | if (rotated) { |
| 6606 | unrotDw = dh; |
| 6607 | unrotDh = dw; |
| 6608 | } else { |
| 6609 | unrotDw = dw; |
| 6610 | unrotDh = dh; |
| 6611 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6612 | displayInfo.smallestNominalAppWidth = 1<<30; |
| 6613 | displayInfo.smallestNominalAppHeight = 1<<30; |
| 6614 | displayInfo.largestNominalAppWidth = 0; |
| 6615 | displayInfo.largestNominalAppHeight = 0; |
| 6616 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_0, unrotDw, unrotDh); |
| 6617 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_90, unrotDh, unrotDw); |
| 6618 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_180, unrotDw, unrotDh); |
| 6619 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_270, unrotDh, unrotDw); |
Dianne Hackborn | fe37f8f | 2012-09-30 12:24:33 -0700 | [diff] [blame] | 6620 | int sl = Configuration.resetScreenLayout(outConfig.screenLayout); |
Dianne Hackborn | 56b53b5 | 2011-11-10 11:19:57 -0800 | [diff] [blame] | 6621 | sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh); |
| 6622 | sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw); |
| 6623 | sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh); |
| 6624 | sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6625 | outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density); |
Dianne Hackborn | fe37f8f | 2012-09-30 12:24:33 -0700 | [diff] [blame] | 6626 | outConfig.screenLayout = sl; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6627 | } |
| 6628 | |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 6629 | private int reduceCompatConfigWidthSize(int curSize, int rotation, DisplayMetrics dm, |
| 6630 | int dw, int dh) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 6631 | // TODO: Multidisplay: for now only use with default display. |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 6632 | dm.noncompatWidthPixels = mPolicy.getNonDecorDisplayWidth(dw, dh, rotation); |
| 6633 | dm.noncompatHeightPixels = mPolicy.getNonDecorDisplayHeight(dw, dh, rotation); |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 6634 | float scale = CompatibilityInfo.computeCompatibleScaling(dm, null); |
Dianne Hackborn | 2b31d53 | 2011-06-23 11:58:50 -0700 | [diff] [blame] | 6635 | int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f); |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 6636 | if (curSize == 0 || size < curSize) { |
| 6637 | curSize = size; |
| 6638 | } |
| 6639 | return curSize; |
| 6640 | } |
| 6641 | |
| 6642 | private int computeCompatSmallestWidth(boolean rotated, DisplayMetrics dm, int dw, int dh) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 6643 | // TODO: Multidisplay: for now only use with default display. |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 6644 | mTmpDisplayMetrics.setTo(dm); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 6645 | final DisplayMetrics tmpDm = mTmpDisplayMetrics; |
| 6646 | final int unrotDw, unrotDh; |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 6647 | if (rotated) { |
| 6648 | unrotDw = dh; |
| 6649 | unrotDh = dw; |
| 6650 | } else { |
| 6651 | unrotDw = dw; |
| 6652 | unrotDh = dh; |
| 6653 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 6654 | int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, tmpDm, unrotDw, unrotDh); |
| 6655 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, tmpDm, unrotDh, unrotDw); |
| 6656 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, tmpDm, unrotDw, unrotDh); |
| 6657 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, tmpDm, unrotDh, unrotDw); |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 6658 | return sw; |
| 6659 | } |
| 6660 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6661 | boolean computeScreenConfigurationLocked(Configuration config) { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 6662 | if (!mDisplayReady) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6663 | return false; |
| 6664 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 6665 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6666 | // TODO(multidisplay): For now, apply Configuration to main screen only. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 6667 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6668 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 6669 | // Use the effective "visual" dimensions based on current rotation |
| 6670 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 6671 | || mRotation == Surface.ROTATION_270); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6672 | final int realdw = rotated ? |
| 6673 | displayContent.mBaseDisplayHeight : displayContent.mBaseDisplayWidth; |
| 6674 | final int realdh = rotated ? |
| 6675 | displayContent.mBaseDisplayWidth : displayContent.mBaseDisplayHeight; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6676 | int dw = realdw; |
| 6677 | int dh = realdh; |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6678 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6679 | if (mAltOrientation) { |
| 6680 | if (realdw > realdh) { |
| 6681 | // Turn landscape into portrait. |
| 6682 | int maxw = (int)(realdh/1.3f); |
| 6683 | if (maxw < realdw) { |
| 6684 | dw = maxw; |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6685 | } |
| 6686 | } else { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6687 | // Turn portrait into landscape. |
| 6688 | int maxh = (int)(realdw/1.3f); |
| 6689 | if (maxh < realdh) { |
| 6690 | dh = maxh; |
| 6691 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6692 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6693 | } |
| 6694 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6695 | if (config != null) { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 6696 | config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT : |
| 6697 | Configuration.ORIENTATION_LANDSCAPE; |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6698 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6699 | |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 6700 | // Update application display metrics. |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 6701 | final int appWidth = mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation); |
| 6702 | final int appHeight = mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6703 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 6704 | synchronized(displayContent.mDisplaySizeLock) { |
| 6705 | displayInfo.rotation = mRotation; |
| 6706 | displayInfo.logicalWidth = dw; |
| 6707 | displayInfo.logicalHeight = dh; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 6708 | displayInfo.logicalDensityDpi = displayContent.mBaseDisplayDensity; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6709 | displayInfo.appWidth = appWidth; |
| 6710 | displayInfo.appHeight = appHeight; |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 6711 | displayInfo.getLogicalMetrics(mRealDisplayMetrics, |
| 6712 | CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null); |
| 6713 | displayInfo.getAppMetrics(mDisplayMetrics); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 6714 | mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager( |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 6715 | displayContent.getDisplayId(), displayInfo); |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 6716 | } |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 6717 | if (false) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6718 | Slog.i(TAG, "Set app display size: " + appWidth + " x " + appHeight); |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 6719 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6720 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6721 | final DisplayMetrics dm = mDisplayMetrics; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6722 | mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(dm, |
| 6723 | mCompatDisplayMetrics); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6724 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6725 | if (config != null) { |
| 6726 | config.screenWidthDp = (int)(mPolicy.getConfigDisplayWidth(dw, dh, mRotation) |
| 6727 | / dm.density); |
| 6728 | config.screenHeightDp = (int)(mPolicy.getConfigDisplayHeight(dw, dh, mRotation) |
| 6729 | / dm.density); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6730 | computeSizeRangesAndScreenLayout(displayInfo, rotated, dw, dh, dm.density, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6731 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6732 | config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale); |
| 6733 | config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale); |
| 6734 | config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, dm, dw, dh); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 6735 | config.densityDpi = displayContent.mBaseDisplayDensity; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 6736 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6737 | // Update the configuration based on available input devices, lid switch, |
| 6738 | // and platform configuration. |
| 6739 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
| 6740 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
| 6741 | config.navigation = Configuration.NAVIGATION_NONAV; |
| 6742 | |
| 6743 | int keyboardPresence = 0; |
| 6744 | int navigationPresence = 0; |
Craig Mautner | 1d961d4 | 2012-05-27 12:02:11 -0700 | [diff] [blame] | 6745 | final InputDevice[] devices = mInputManager.getInputDevices(); |
| 6746 | final int len = devices.length; |
| 6747 | for (int i = 0; i < len; i++) { |
| 6748 | InputDevice device = devices[i]; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6749 | if (!device.isVirtual()) { |
| 6750 | final int sources = device.getSources(); |
| 6751 | final int presenceFlag = device.isExternal() ? |
| 6752 | WindowManagerPolicy.PRESENCE_EXTERNAL : |
| 6753 | WindowManagerPolicy.PRESENCE_INTERNAL; |
| 6754 | |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 6755 | if (mIsTouchDevice) { |
Jeff Brown | 7e4ff4b | 2012-05-30 14:32:16 -0700 | [diff] [blame] | 6756 | if ((sources & InputDevice.SOURCE_TOUCHSCREEN) == |
| 6757 | InputDevice.SOURCE_TOUCHSCREEN) { |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 6758 | config.touchscreen = Configuration.TOUCHSCREEN_FINGER; |
| 6759 | } |
| 6760 | } else { |
| 6761 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6762 | } |
| 6763 | |
Jeff Brown | 7e4ff4b | 2012-05-30 14:32:16 -0700 | [diff] [blame] | 6764 | if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) { |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6765 | config.navigation = Configuration.NAVIGATION_TRACKBALL; |
| 6766 | navigationPresence |= presenceFlag; |
Jeff Brown | 7e4ff4b | 2012-05-30 14:32:16 -0700 | [diff] [blame] | 6767 | } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6768 | && config.navigation == Configuration.NAVIGATION_NONAV) { |
| 6769 | config.navigation = Configuration.NAVIGATION_DPAD; |
| 6770 | navigationPresence |= presenceFlag; |
| 6771 | } |
| 6772 | |
| 6773 | if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { |
| 6774 | config.keyboard = Configuration.KEYBOARD_QWERTY; |
| 6775 | keyboardPresence |= presenceFlag; |
| 6776 | } |
| 6777 | } |
| 6778 | } |
| 6779 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6780 | // Determine whether a hard keyboard is available and enabled. |
| 6781 | boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; |
| 6782 | if (hardKeyboardAvailable != mHardKeyboardAvailable) { |
| 6783 | mHardKeyboardAvailable = hardKeyboardAvailable; |
| 6784 | mHardKeyboardEnabled = hardKeyboardAvailable; |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6785 | mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 6786 | mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 6787 | } |
| 6788 | if (!mHardKeyboardEnabled) { |
| 6789 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
| 6790 | } |
| 6791 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6792 | // Let the policy update hidden states. |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6793 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 6794 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 6795 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6796 | mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence); |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 6797 | } |
Jeff Brown | 597eec8 | 2011-01-31 17:12:25 -0800 | [diff] [blame] | 6798 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6799 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6800 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6801 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 6802 | public boolean isHardKeyboardAvailable() { |
| 6803 | synchronized (mWindowMap) { |
| 6804 | return mHardKeyboardAvailable; |
| 6805 | } |
| 6806 | } |
| 6807 | |
| 6808 | public boolean isHardKeyboardEnabled() { |
| 6809 | synchronized (mWindowMap) { |
| 6810 | return mHardKeyboardEnabled; |
| 6811 | } |
| 6812 | } |
| 6813 | |
| 6814 | public void setHardKeyboardEnabled(boolean enabled) { |
| 6815 | synchronized (mWindowMap) { |
| 6816 | if (mHardKeyboardEnabled != enabled) { |
| 6817 | mHardKeyboardEnabled = enabled; |
| 6818 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 6819 | } |
| 6820 | } |
| 6821 | } |
| 6822 | |
| 6823 | public void setOnHardKeyboardStatusChangeListener( |
| 6824 | OnHardKeyboardStatusChangeListener listener) { |
| 6825 | synchronized (mWindowMap) { |
| 6826 | mHardKeyboardStatusChangeListener = listener; |
| 6827 | } |
| 6828 | } |
| 6829 | |
| 6830 | void notifyHardKeyboardStatusChange() { |
| 6831 | final boolean available, enabled; |
| 6832 | final OnHardKeyboardStatusChangeListener listener; |
| 6833 | synchronized (mWindowMap) { |
| 6834 | listener = mHardKeyboardStatusChangeListener; |
| 6835 | available = mHardKeyboardAvailable; |
| 6836 | enabled = mHardKeyboardEnabled; |
| 6837 | } |
| 6838 | if (listener != null) { |
| 6839 | listener.onHardKeyboardStatusChange(available, enabled); |
| 6840 | } |
| 6841 | } |
| 6842 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6843 | // ------------------------------------------------------------- |
| 6844 | // Drag and drop |
| 6845 | // ------------------------------------------------------------- |
| 6846 | |
| 6847 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6848 | int flags, int width, int height, Surface outSurface) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6849 | if (DEBUG_DRAG) { |
| 6850 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6851 | + " flags=" + Integer.toHexString(flags) + " win=" + window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6852 | + " asbinder=" + window.asBinder()); |
| 6853 | } |
| 6854 | |
| 6855 | final int callerPid = Binder.getCallingPid(); |
| 6856 | final long origId = Binder.clearCallingIdentity(); |
| 6857 | IBinder token = null; |
| 6858 | |
| 6859 | try { |
| 6860 | synchronized (mWindowMap) { |
| 6861 | try { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6862 | if (mDragState == null) { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 6863 | // TODO(multi-display): support other displays |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 6864 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 6865 | final Display display = displayContent.getDisplay(); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 6866 | SurfaceControl surface = new SurfaceControl(session, "drag surface", |
| 6867 | width, height, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN); |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 6868 | surface.setLayerStack(display.getLayerStack()); |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 6869 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DRAG " |
| 6870 | + surface + ": CREATE"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6871 | outSurface.copyFrom(surface); |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 6872 | final IBinder winBinder = window.asBinder(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6873 | token = new Binder(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 6874 | mDragState = new DragState(this, token, surface, /*flags*/ 0, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6875 | token = mDragState.mToken = new Binder(); |
| 6876 | |
| 6877 | // 5 second timeout for this window to actually begin the drag |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 6878 | mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder); |
| 6879 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6880 | mH.sendMessageDelayed(msg, 5000); |
| 6881 | } else { |
| 6882 | Slog.w(TAG, "Drag already in progress"); |
| 6883 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6884 | } catch (OutOfResourcesException e) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6885 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 6886 | if (mDragState != null) { |
| 6887 | mDragState.reset(); |
| 6888 | mDragState = null; |
| 6889 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6890 | } |
| 6891 | } |
| 6892 | } finally { |
| 6893 | Binder.restoreCallingIdentity(origId); |
| 6894 | } |
| 6895 | |
| 6896 | return token; |
| 6897 | } |
| 6898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6899 | // ------------------------------------------------------------- |
| 6900 | // Input Events and Focus Management |
| 6901 | // ------------------------------------------------------------- |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 6902 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 6903 | final InputMonitor mInputMonitor = new InputMonitor(this); |
Jeff Brown | 08a746a | 2012-06-24 12:14:49 -0700 | [diff] [blame] | 6904 | private boolean mEventDispatchingEnabled; |
| 6905 | |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 6906 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6907 | public void pauseKeyDispatching(IBinder _token) { |
| 6908 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6909 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6910 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6911 | } |
| 6912 | |
| 6913 | synchronized (mWindowMap) { |
| 6914 | WindowToken token = mTokenMap.get(_token); |
| 6915 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6916 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6917 | } |
| 6918 | } |
| 6919 | } |
| 6920 | |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 6921 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6922 | public void resumeKeyDispatching(IBinder _token) { |
| 6923 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6924 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6925 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6926 | } |
| 6927 | |
| 6928 | synchronized (mWindowMap) { |
| 6929 | WindowToken token = mTokenMap.get(_token); |
| 6930 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6931 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6932 | } |
| 6933 | } |
| 6934 | } |
| 6935 | |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 6936 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6937 | public void setEventDispatching(boolean enabled) { |
| 6938 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
Craig Mautner | 3d7b7d5 | 2012-05-24 11:28:26 -0700 | [diff] [blame] | 6939 | "setEventDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6940 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6941 | } |
| 6942 | |
| 6943 | synchronized (mWindowMap) { |
Jeff Brown | 08a746a | 2012-06-24 12:14:49 -0700 | [diff] [blame] | 6944 | mEventDispatchingEnabled = enabled; |
| 6945 | if (mDisplayEnabled) { |
| 6946 | mInputMonitor.setEventDispatchingLw(enabled); |
| 6947 | } |
Craig Mautner | 3d7b7d5 | 2012-05-24 11:28:26 -0700 | [diff] [blame] | 6948 | sendScreenStatusToClientsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6949 | } |
| 6950 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6952 | private WindowState getFocusedWindow() { |
| 6953 | synchronized (mWindowMap) { |
| 6954 | return getFocusedWindowLocked(); |
| 6955 | } |
| 6956 | } |
| 6957 | |
| 6958 | private WindowState getFocusedWindowLocked() { |
| 6959 | return mCurrentFocus; |
| 6960 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6961 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6962 | public boolean detectSafeMode() { |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 6963 | if (!mInputMonitor.waitForInputDevicesReady( |
| 6964 | INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) { |
| 6965 | Slog.w(TAG, "Devices still not ready after waiting " |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 6966 | + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS |
| 6967 | + " milliseconds before attempting to detect safe mode."); |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 6968 | } |
| 6969 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 6970 | int menuState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, |
| 6971 | KeyEvent.KEYCODE_MENU); |
| 6972 | int sState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, KeyEvent.KEYCODE_S); |
| 6973 | int dpadState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, |
| 6974 | KeyEvent.KEYCODE_DPAD_CENTER); |
| 6975 | int trackballState = mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6976 | InputManagerService.BTN_MOUSE); |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 6977 | int volumeDownState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, |
| 6978 | KeyEvent.KEYCODE_VOLUME_DOWN); |
| 6979 | mSafeMode = menuState > 0 || sState > 0 || dpadState > 0 || trackballState > 0 |
| 6980 | || volumeDownState > 0; |
Dianne Hackborn | 19caadc | 2012-04-20 17:49:10 -0700 | [diff] [blame] | 6981 | try { |
| 6982 | if (SystemProperties.getInt(ShutdownThread.REBOOT_SAFEMODE_PROPERTY, 0) != 0) { |
| 6983 | mSafeMode = true; |
| 6984 | SystemProperties.set(ShutdownThread.REBOOT_SAFEMODE_PROPERTY, ""); |
| 6985 | } |
| 6986 | } catch (IllegalArgumentException e) { |
| 6987 | } |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 6988 | if (mSafeMode) { |
| 6989 | Log.i(TAG, "SAFE MODE ENABLED (menu=" + menuState + " s=" + sState |
| 6990 | + " dpad=" + dpadState + " trackball=" + trackballState + ")"); |
| 6991 | } else { |
| 6992 | Log.i(TAG, "SAFE MODE not enabled"); |
| 6993 | } |
| 6994 | mPolicy.setSafeMode(mSafeMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6995 | return mSafeMode; |
| 6996 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6997 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6998 | public void displayReady() { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 6999 | displayReady(Display.DEFAULT_DISPLAY); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 7000 | |
| 7001 | synchronized(mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 7002 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 7003 | readForcedDisplaySizeAndDensityLocked(displayContent); |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 7004 | mDisplayReady = true; |
Craig Mautner | 67a6042 | 2013-07-24 09:19:44 -0700 | [diff] [blame] | 7005 | } |
| 7006 | |
| 7007 | try { |
| 7008 | mActivityManager.updateConfiguration(null); |
| 7009 | } catch (RemoteException e) { |
| 7010 | } |
| 7011 | |
| 7012 | synchronized(mWindowMap) { |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 7013 | mIsTouchDevice = mContext.getPackageManager().hasSystemFeature( |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 7014 | PackageManager.FEATURE_TOUCHSCREEN); |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 7015 | configureDisplayPolicyLocked(getDefaultDisplayContentLocked()); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 7016 | } |
Dianne Hackborn | 5a052a4 | 2012-08-15 18:49:23 -0700 | [diff] [blame] | 7017 | |
| 7018 | try { |
| 7019 | mActivityManager.updateConfiguration(null); |
| 7020 | } catch (RemoteException e) { |
| 7021 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7022 | } |
| 7023 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 7024 | private void displayReady(int displayId) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 7025 | synchronized(mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 7026 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 7027 | if (displayContent != null) { |
| 7028 | mAnimator.addDisplayLocked(displayId); |
| 7029 | synchronized(displayContent.mDisplaySizeLock) { |
| 7030 | // Bootstrap the default logical display from the display manager. |
| 7031 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 7032 | DisplayInfo newDisplayInfo = mDisplayManagerInternal.getDisplayInfo(displayId); |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 7033 | if (newDisplayInfo != null) { |
| 7034 | displayInfo.copyFrom(newDisplayInfo); |
| 7035 | } |
| 7036 | displayContent.mInitialDisplayWidth = displayInfo.logicalWidth; |
| 7037 | displayContent.mInitialDisplayHeight = displayInfo.logicalHeight; |
| 7038 | displayContent.mInitialDisplayDensity = displayInfo.logicalDensityDpi; |
| 7039 | displayContent.mBaseDisplayWidth = displayContent.mInitialDisplayWidth; |
| 7040 | displayContent.mBaseDisplayHeight = displayContent.mInitialDisplayHeight; |
| 7041 | displayContent.mBaseDisplayDensity = displayContent.mInitialDisplayDensity; |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 7042 | displayContent.mBaseDisplayRect.set(0, 0, |
| 7043 | displayContent.mBaseDisplayWidth, displayContent.mBaseDisplayHeight); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 7044 | } |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7045 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 7046 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 7047 | } |
| 7048 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7049 | public void systemReady() { |
| 7050 | mPolicy.systemReady(); |
| 7051 | } |
| 7052 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7053 | // TODO(multidisplay): Call isScreenOn for each display. |
Craig Mautner | 3d7b7d5 | 2012-05-24 11:28:26 -0700 | [diff] [blame] | 7054 | private void sendScreenStatusToClientsLocked() { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7055 | final boolean on = mPowerManager.isScreenOn(); |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 7056 | final int numDisplays = mDisplayContents.size(); |
| 7057 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 7058 | final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList(); |
| 7059 | final int numWindows = windows.size(); |
| 7060 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 7061 | try { |
| 7062 | windows.get(winNdx).mClient.dispatchScreenState(on); |
| 7063 | } catch (RemoteException e) { |
| 7064 | // Ignored |
| 7065 | } |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 7066 | } |
| 7067 | } |
| 7068 | } |
| 7069 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7070 | // ------------------------------------------------------------- |
| 7071 | // Async Handler |
| 7072 | // ------------------------------------------------------------- |
| 7073 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 7074 | final class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7075 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 7076 | public static final int REPORT_LOSING_FOCUS = 3; |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 7077 | public static final int DO_TRAVERSAL = 4; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7078 | public static final int ADD_STARTING = 5; |
| 7079 | public static final int REMOVE_STARTING = 6; |
| 7080 | public static final int FINISHED_STARTING = 7; |
| 7081 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 7082 | public static final int REPORT_APPLICATION_TOKEN_DRAWN = 9; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7083 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
Craig Mautner | 259328c | 2012-08-21 19:30:58 -0700 | [diff] [blame] | 7084 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7085 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 7086 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 7087 | public static final int FORCE_GC = 15; |
| 7088 | public static final int ENABLE_SCREEN = 16; |
| 7089 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7090 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 7091 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7092 | public static final int DRAG_START_TIMEOUT = 20; |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 7093 | public static final int DRAG_END_TIMEOUT = 21; |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 7094 | public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 7095 | public static final int BOOT_TIMEOUT = 23; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 7096 | public static final int WAITING_FOR_DRAWN_TIMEOUT = 24; |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 7097 | public static final int SHOW_STRICT_MODE_VIOLATION = 25; |
| 7098 | public static final int DO_ANIMATION_CALLBACK = 26; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7099 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 7100 | public static final int DO_DISPLAY_ADDED = 27; |
| 7101 | public static final int DO_DISPLAY_REMOVED = 28; |
| 7102 | public static final int DO_DISPLAY_CHANGED = 29; |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 7103 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 7104 | public static final int CLIENT_FREEZE_TIMEOUT = 30; |
Craig Mautner | d3c9338 | 2013-04-24 14:23:39 -0700 | [diff] [blame] | 7105 | public static final int TAP_OUTSIDE_STACK = 31; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7106 | public static final int NOTIFY_ACTIVITY_DRAWN = 32; |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 7107 | |
Craig Mautner | 68cc241 | 2013-10-01 10:39:43 -0700 | [diff] [blame] | 7108 | public static final int REMOVE_STARTING_TIMEOUT = 33; |
| 7109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7110 | @Override |
| 7111 | public void handleMessage(Message msg) { |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 7112 | if (DEBUG_WINDOW_TRACE) { |
| 7113 | Slog.v(TAG, "handleMessage: entry what=" + msg.what); |
| 7114 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7115 | switch (msg.what) { |
| 7116 | case REPORT_FOCUS_CHANGE: { |
| 7117 | WindowState lastFocus; |
| 7118 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7120 | synchronized(mWindowMap) { |
| 7121 | lastFocus = mLastFocus; |
| 7122 | newFocus = mCurrentFocus; |
| 7123 | if (lastFocus == newFocus) { |
| 7124 | // Focus is not changing, so nothing to do. |
| 7125 | return; |
| 7126 | } |
| 7127 | mLastFocus = newFocus; |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 7128 | if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, "Focus moving from " + lastFocus + |
| 7129 | " to " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7130 | if (newFocus != null && lastFocus != null |
| 7131 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7132 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7133 | mLosingFocus.add(lastFocus); |
| 7134 | lastFocus = null; |
| 7135 | } |
| 7136 | } |
| 7137 | |
Craig Mautner | b1885b8 | 2013-09-16 22:50:50 -0700 | [diff] [blame] | 7138 | //System.out.println("Changing focus from " + lastFocus |
| 7139 | // + " to " + newFocus); |
| 7140 | if (newFocus != null) { |
| 7141 | if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, "Gaining focus: " + newFocus); |
| 7142 | newFocus.reportFocusChangedSerialized(true, mInTouchMode); |
| 7143 | notifyFocusChanged(); |
| 7144 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7145 | |
Craig Mautner | b1885b8 | 2013-09-16 22:50:50 -0700 | [diff] [blame] | 7146 | if (lastFocus != null) { |
| 7147 | if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, "Losing focus: " + lastFocus); |
| 7148 | lastFocus.reportFocusChangedSerialized(false, mInTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7149 | } |
| 7150 | } break; |
| 7151 | |
| 7152 | case REPORT_LOSING_FOCUS: { |
| 7153 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7155 | synchronized(mWindowMap) { |
| 7156 | losers = mLosingFocus; |
| 7157 | mLosingFocus = new ArrayList<WindowState>(); |
| 7158 | } |
| 7159 | |
| 7160 | final int N = losers.size(); |
| 7161 | for (int i=0; i<N; i++) { |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 7162 | if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, "Losing delayed focus: " + |
| 7163 | losers.get(i)); |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 7164 | losers.get(i).reportFocusChangedSerialized(false, mInTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7165 | } |
| 7166 | } break; |
| 7167 | |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 7168 | case DO_TRAVERSAL: { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7169 | synchronized(mWindowMap) { |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 7170 | mTraversalScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7171 | performLayoutAndPlaceSurfacesLocked(); |
| 7172 | } |
| 7173 | } break; |
| 7174 | |
| 7175 | case ADD_STARTING: { |
| 7176 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7177 | final StartingData sd = wtoken.startingData; |
| 7178 | |
| 7179 | if (sd == null) { |
| 7180 | // Animation has been canceled... do nothing. |
| 7181 | return; |
| 7182 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7183 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7184 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7185 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7186 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7187 | View view = null; |
| 7188 | try { |
| 7189 | view = mPolicy.addStartingWindow( |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 7190 | wtoken.token, sd.pkg, sd.theme, sd.compatInfo, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 7191 | sd.nonLocalizedLabel, sd.labelRes, sd.icon, sd.logo, sd.windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7192 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7193 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7194 | } |
| 7195 | |
| 7196 | if (view != null) { |
| 7197 | boolean abort = false; |
| 7198 | |
| 7199 | synchronized(mWindowMap) { |
| 7200 | if (wtoken.removed || wtoken.startingData == null) { |
| 7201 | // If the window was successfully added, then |
| 7202 | // we need to remove it. |
| 7203 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7204 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7205 | "Aborted starting " + wtoken |
| 7206 | + ": removed=" + wtoken.removed |
| 7207 | + " startingData=" + wtoken.startingData); |
| 7208 | wtoken.startingWindow = null; |
| 7209 | wtoken.startingData = null; |
| 7210 | abort = true; |
| 7211 | } |
| 7212 | } else { |
| 7213 | wtoken.startingView = view; |
| 7214 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7215 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7216 | "Added starting " + wtoken |
| 7217 | + ": startingWindow=" |
| 7218 | + wtoken.startingWindow + " startingView=" |
| 7219 | + wtoken.startingView); |
| 7220 | } |
| 7221 | |
| 7222 | if (abort) { |
| 7223 | try { |
| 7224 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 7225 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7226 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7227 | } |
| 7228 | } |
| 7229 | } |
| 7230 | } break; |
| 7231 | |
| 7232 | case REMOVE_STARTING: { |
| 7233 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7234 | IBinder token = null; |
| 7235 | View view = null; |
| 7236 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7237 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7238 | + wtoken + ": startingWindow=" |
| 7239 | + wtoken.startingWindow + " startingView=" |
| 7240 | + wtoken.startingView); |
| 7241 | if (wtoken.startingWindow != null) { |
| 7242 | view = wtoken.startingView; |
| 7243 | token = wtoken.token; |
| 7244 | wtoken.startingData = null; |
| 7245 | wtoken.startingView = null; |
| 7246 | wtoken.startingWindow = null; |
Craig Mautner | 38b2478 | 2012-07-02 16:21:28 -0700 | [diff] [blame] | 7247 | wtoken.startingDisplayed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7248 | } |
| 7249 | } |
| 7250 | if (view != null) { |
| 7251 | try { |
| 7252 | mPolicy.removeStartingWindow(token, view); |
| 7253 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7254 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7255 | } |
| 7256 | } |
| 7257 | } break; |
| 7258 | |
| 7259 | case FINISHED_STARTING: { |
| 7260 | IBinder token = null; |
| 7261 | View view = null; |
| 7262 | while (true) { |
| 7263 | synchronized (mWindowMap) { |
| 7264 | final int N = mFinishedStarting.size(); |
| 7265 | if (N <= 0) { |
| 7266 | break; |
| 7267 | } |
| 7268 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 7269 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7270 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7271 | "Finished starting " + wtoken |
| 7272 | + ": startingWindow=" + wtoken.startingWindow |
| 7273 | + " startingView=" + wtoken.startingView); |
| 7274 | |
| 7275 | if (wtoken.startingWindow == null) { |
| 7276 | continue; |
| 7277 | } |
| 7278 | |
| 7279 | view = wtoken.startingView; |
| 7280 | token = wtoken.token; |
| 7281 | wtoken.startingData = null; |
| 7282 | wtoken.startingView = null; |
| 7283 | wtoken.startingWindow = null; |
Craig Mautner | 38b2478 | 2012-07-02 16:21:28 -0700 | [diff] [blame] | 7284 | wtoken.startingDisplayed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7285 | } |
| 7286 | |
| 7287 | try { |
| 7288 | mPolicy.removeStartingWindow(token, view); |
| 7289 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7290 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7291 | } |
| 7292 | } |
| 7293 | } break; |
| 7294 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 7295 | case REPORT_APPLICATION_TOKEN_DRAWN: { |
| 7296 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7297 | |
| 7298 | try { |
| 7299 | if (DEBUG_VISIBILITY) Slog.v( |
| 7300 | TAG, "Reporting drawn in " + wtoken); |
| 7301 | wtoken.appToken.windowsDrawn(); |
| 7302 | } catch (RemoteException ex) { |
| 7303 | } |
| 7304 | } break; |
| 7305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7306 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 7307 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7308 | |
| 7309 | boolean nowVisible = msg.arg1 != 0; |
| 7310 | boolean nowGone = msg.arg2 != 0; |
| 7311 | |
| 7312 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7313 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7314 | TAG, "Reporting visible in " + wtoken |
| 7315 | + " visible=" + nowVisible |
| 7316 | + " gone=" + nowGone); |
| 7317 | if (nowVisible) { |
| 7318 | wtoken.appToken.windowsVisible(); |
| 7319 | } else { |
| 7320 | wtoken.appToken.windowsGone(); |
| 7321 | } |
| 7322 | } catch (RemoteException ex) { |
| 7323 | } |
| 7324 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7326 | case WINDOW_FREEZE_TIMEOUT: { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7327 | // TODO(multidisplay): Can non-default displays rotate? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7328 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7329 | Slog.w(TAG, "Window freeze timeout expired."); |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 7330 | final WindowList windows = getDefaultWindowListLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7331 | int i = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7332 | while (i > 0) { |
| 7333 | i--; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7334 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7335 | if (w.mOrientationChanging) { |
| 7336 | w.mOrientationChanging = false; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 7337 | w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
| 7338 | - mDisplayFreezeTime); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7339 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7340 | } |
| 7341 | } |
| 7342 | performLayoutAndPlaceSurfacesLocked(); |
| 7343 | } |
| 7344 | break; |
| 7345 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7347 | case APP_TRANSITION_TIMEOUT: { |
| 7348 | synchronized (mWindowMap) { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 7349 | if (mAppTransition.isTransitionSet()) { |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 7350 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** APP TRANSITION TIMEOUT"); |
| 7351 | mAppTransition.setTimeout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7352 | performLayoutAndPlaceSurfacesLocked(); |
| 7353 | } |
| 7354 | } |
| 7355 | break; |
| 7356 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7357 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7358 | case PERSIST_ANIMATION_SCALE: { |
Jeff Sharkey | 6e2bee7 | 2012-10-01 13:39:08 -0700 | [diff] [blame] | 7359 | Settings.Global.putFloat(mContext.getContentResolver(), |
| 7360 | Settings.Global.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 7361 | Settings.Global.putFloat(mContext.getContentResolver(), |
| 7362 | Settings.Global.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 7363 | Settings.Global.putFloat(mContext.getContentResolver(), |
| 7364 | Settings.Global.ANIMATOR_DURATION_SCALE, mAnimatorDurationScale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7365 | break; |
| 7366 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7368 | case FORCE_GC: { |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 7369 | synchronized (mWindowMap) { |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 7370 | // Since we're holding both mWindowMap and mAnimator we don't need to |
| 7371 | // hold mAnimator.mLayoutToAnim. |
| 7372 | if (mAnimator.mAnimating || mAnimationScheduled) { |
| 7373 | // If we are animating, don't do the gc now but |
| 7374 | // delay a bit so we don't interrupt the animation. |
| 7375 | sendEmptyMessageDelayed(H.FORCE_GC, 2000); |
| 7376 | return; |
| 7377 | } |
| 7378 | // If we are currently rotating the display, it will |
| 7379 | // schedule a new message when done. |
| 7380 | if (mDisplayFrozen) { |
| 7381 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7382 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7383 | } |
| 7384 | Runtime.getRuntime().gc(); |
| 7385 | break; |
| 7386 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7387 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7388 | case ENABLE_SCREEN: { |
| 7389 | performEnableScreen(); |
| 7390 | break; |
| 7391 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7392 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7393 | case APP_FREEZE_TIMEOUT: { |
| 7394 | synchronized (mWindowMap) { |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 7395 | Slog.w(TAG, "App freeze timeout expired."); |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 7396 | final int numStacks = mStackIdToStack.size(); |
| 7397 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 7398 | final TaskStack stack = mStackIdToStack.valueAt(stackNdx); |
| 7399 | final ArrayList<Task> tasks = stack.getTasks(); |
| 7400 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 7401 | AppTokenList tokens = tasks.get(taskNdx).mAppTokens; |
| 7402 | for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) { |
| 7403 | AppWindowToken tok = tokens.get(tokenNdx); |
| 7404 | if (tok.mAppAnimator.freezingScreen) { |
| 7405 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| 7406 | unsetAppFreezingScreenLocked(tok, true, true); |
| 7407 | } |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 7408 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7409 | } |
| 7410 | } |
| 7411 | } |
| 7412 | break; |
| 7413 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7414 | |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 7415 | case CLIENT_FREEZE_TIMEOUT: { |
| 7416 | synchronized (mWindowMap) { |
| 7417 | if (mClientFreezingScreen) { |
| 7418 | mClientFreezingScreen = false; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 7419 | mLastFinishedFreezeSource = "client-timeout"; |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 7420 | stopFreezingDisplayLocked(); |
| 7421 | } |
| 7422 | } |
| 7423 | break; |
| 7424 | } |
| 7425 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7426 | case SEND_NEW_CONFIGURATION: { |
| 7427 | removeMessages(SEND_NEW_CONFIGURATION); |
| 7428 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 7429 | break; |
| 7430 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7431 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 7432 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 7433 | if (mWindowsChanged) { |
| 7434 | synchronized (mWindowMap) { |
| 7435 | mWindowsChanged = false; |
| 7436 | } |
| 7437 | notifyWindowsChanged(); |
| 7438 | } |
| 7439 | break; |
| 7440 | } |
| 7441 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7442 | case DRAG_START_TIMEOUT: { |
| 7443 | IBinder win = (IBinder)msg.obj; |
| 7444 | if (DEBUG_DRAG) { |
| 7445 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 7446 | } |
| 7447 | synchronized (mWindowMap) { |
| 7448 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 7449 | if (mDragState != null) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 7450 | mDragState.unregister(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 7451 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7452 | mDragState.reset(); |
| 7453 | mDragState = null; |
| 7454 | } |
| 7455 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 7456 | break; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7457 | } |
| 7458 | |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 7459 | case DRAG_END_TIMEOUT: { |
| 7460 | IBinder win = (IBinder)msg.obj; |
| 7461 | if (DEBUG_DRAG) { |
| 7462 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 7463 | } |
| 7464 | synchronized (mWindowMap) { |
| 7465 | // !!! TODO: ANR the drag-receiving app |
Christopher Tate | d9be36c | 2011-08-16 16:09:33 -0700 | [diff] [blame] | 7466 | if (mDragState != null) { |
| 7467 | mDragState.mDragResult = false; |
| 7468 | mDragState.endDragLw(); |
| 7469 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 7470 | } |
| 7471 | break; |
| 7472 | } |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 7473 | |
| 7474 | case REPORT_HARD_KEYBOARD_STATUS_CHANGE: { |
| 7475 | notifyHardKeyboardStatusChange(); |
| 7476 | break; |
| 7477 | } |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 7478 | |
| 7479 | case BOOT_TIMEOUT: { |
| 7480 | performBootTimeout(); |
| 7481 | break; |
| 7482 | } |
| 7483 | |
| 7484 | case WAITING_FOR_DRAWN_TIMEOUT: { |
| 7485 | Pair<WindowState, IRemoteCallback> pair; |
| 7486 | synchronized (mWindowMap) { |
| 7487 | pair = (Pair<WindowState, IRemoteCallback>)msg.obj; |
| 7488 | Slog.w(TAG, "Timeout waiting for drawn: " + pair.first); |
| 7489 | if (!mWaitingForDrawn.remove(pair)) { |
| 7490 | return; |
| 7491 | } |
| 7492 | } |
| 7493 | try { |
| 7494 | pair.second.sendResult(null); |
| 7495 | } catch (RemoteException e) { |
| 7496 | } |
| 7497 | break; |
| 7498 | } |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 7499 | |
Craig Mautner | 0447a81 | 2012-05-22 16:01:31 -0700 | [diff] [blame] | 7500 | case SHOW_STRICT_MODE_VIOLATION: { |
Chris Craik | 3198ef3 | 2012-10-10 14:52:30 -0700 | [diff] [blame] | 7501 | showStrictModeViolation(msg.arg1, msg.arg2); |
Craig Mautner | 0447a81 | 2012-05-22 16:01:31 -0700 | [diff] [blame] | 7502 | break; |
| 7503 | } |
| 7504 | |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 7505 | case DO_ANIMATION_CALLBACK: { |
| 7506 | try { |
| 7507 | ((IRemoteCallback)msg.obj).sendResult(null); |
| 7508 | } catch (RemoteException e) { |
| 7509 | } |
| 7510 | break; |
| 7511 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 7512 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 7513 | case DO_DISPLAY_ADDED: |
Craig Mautner | ad25fa3 | 2014-01-12 21:19:06 -0800 | [diff] [blame] | 7514 | handleDisplayAdded(msg.arg1); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 7515 | break; |
| 7516 | |
| 7517 | case DO_DISPLAY_REMOVED: |
| 7518 | synchronized (mWindowMap) { |
| 7519 | handleDisplayRemovedLocked(msg.arg1); |
| 7520 | } |
| 7521 | break; |
| 7522 | |
| 7523 | case DO_DISPLAY_CHANGED: |
| 7524 | synchronized (mWindowMap) { |
| 7525 | handleDisplayChangedLocked(msg.arg1); |
| 7526 | } |
| 7527 | break; |
Craig Mautner | d3c9338 | 2013-04-24 14:23:39 -0700 | [diff] [blame] | 7528 | |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 7529 | case TAP_OUTSIDE_STACK: { |
| 7530 | int stackId; |
Craig Mautner | d3c9338 | 2013-04-24 14:23:39 -0700 | [diff] [blame] | 7531 | synchronized (mWindowMap) { |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 7532 | stackId = ((DisplayContent)msg.obj).stackIdFromPoint(msg.arg1, msg.arg2); |
| 7533 | } |
| 7534 | if (stackId >= 0) { |
| 7535 | try { |
| 7536 | mActivityManager.setFocusedStack(stackId); |
| 7537 | } catch (RemoteException e) { |
Craig Mautner | d3c9338 | 2013-04-24 14:23:39 -0700 | [diff] [blame] | 7538 | } |
| 7539 | } |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 7540 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 7541 | break; |
| 7542 | case NOTIFY_ACTIVITY_DRAWN: |
| 7543 | try { |
| 7544 | mActivityManager.notifyActivityDrawn((IBinder) msg.obj); |
| 7545 | } catch (RemoteException e) { |
| 7546 | } |
| 7547 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7548 | } |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 7549 | if (DEBUG_WINDOW_TRACE) { |
| 7550 | Slog.v(TAG, "handleMessage: exit"); |
| 7551 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7552 | } |
| 7553 | } |
| 7554 | |
| 7555 | // ------------------------------------------------------------- |
| 7556 | // IWindowManager API |
| 7557 | // ------------------------------------------------------------- |
| 7558 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 7559 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7560 | public IWindowSession openSession(IInputMethodClient client, |
| 7561 | IInputContext inputContext) { |
| 7562 | if (client == null) throw new IllegalArgumentException("null client"); |
| 7563 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 7564 | Session session = new Session(this, client, inputContext); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7565 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7566 | } |
| 7567 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 7568 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7569 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 7570 | synchronized (mWindowMap) { |
| 7571 | // The focus for the client is the window immediately below |
| 7572 | // where we would place the input method window. |
| 7573 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7574 | if (idx > 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7575 | // TODO(multidisplay): IMEs are only supported on the default display. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 7576 | WindowState imFocus = getDefaultWindowListLocked().get(idx-1); |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 7577 | if (DEBUG_INPUT_METHOD) { |
| 7578 | Slog.i(TAG, "Desired input method target: " + imFocus); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7579 | Slog.i(TAG, "Current focus: " + mCurrentFocus); |
| 7580 | Slog.i(TAG, "Last focus: " + mLastFocus); |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 7581 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7582 | if (imFocus != null) { |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 7583 | // This may be a starting window, in which case we still want |
| 7584 | // to count it as okay. |
| 7585 | if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING |
| 7586 | && imFocus.mAppToken != null) { |
| 7587 | // The client has definitely started, so it really should |
| 7588 | // have a window in this app token. Let's look for it. |
| 7589 | for (int i=0; i<imFocus.mAppToken.windows.size(); i++) { |
| 7590 | WindowState w = imFocus.mAppToken.windows.get(i); |
| 7591 | if (w != imFocus) { |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 7592 | Log.i(TAG, "Switching to real app window: " + w); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 7593 | imFocus = w; |
| 7594 | break; |
| 7595 | } |
| 7596 | } |
| 7597 | } |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 7598 | if (DEBUG_INPUT_METHOD) { |
| 7599 | Slog.i(TAG, "IM target client: " + imFocus.mSession.mClient); |
| 7600 | if (imFocus.mSession.mClient != null) { |
| 7601 | Slog.i(TAG, "IM target client binder: " |
| 7602 | + imFocus.mSession.mClient.asBinder()); |
| 7603 | Slog.i(TAG, "Requesting client binder: " + client.asBinder()); |
| 7604 | } |
| 7605 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7606 | if (imFocus.mSession.mClient != null && |
| 7607 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 7608 | return true; |
| 7609 | } |
| 7610 | } |
| 7611 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7612 | |
| 7613 | // Okay, how about this... what is the current focus? |
| 7614 | // It seems in some cases we may not have moved the IM |
| 7615 | // target window, such as when it was in a pop-up window, |
| 7616 | // so let's also look at the current focus. (An example: |
| 7617 | // go to Gmail, start searching so the keyboard goes up, |
| 7618 | // press home. Sometimes the IME won't go down.) |
| 7619 | // Would be nice to fix this more correctly, but it's |
| 7620 | // way at the end of a release, and this should be good enough. |
| 7621 | if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null |
| 7622 | && mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 7623 | return true; |
| 7624 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7625 | } |
| 7626 | return false; |
| 7627 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7628 | |
Dianne Hackborn | 672cf45 | 2013-03-26 15:24:24 -0700 | [diff] [blame] | 7629 | @Override |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7630 | public void getInitialDisplaySize(int displayId, Point size) { |
Craig Mautner | 5810681 | 2012-12-28 12:27:40 -0800 | [diff] [blame] | 7631 | synchronized (mWindowMap) { |
| 7632 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 7633 | if (displayContent != null && displayContent.hasAccess(Binder.getCallingUid())) { |
Craig Mautner | 5810681 | 2012-12-28 12:27:40 -0800 | [diff] [blame] | 7634 | synchronized(displayContent.mDisplaySizeLock) { |
| 7635 | size.x = displayContent.mInitialDisplayWidth; |
| 7636 | size.y = displayContent.mInitialDisplayHeight; |
| 7637 | } |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 7638 | } |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 7639 | } |
| 7640 | } |
| 7641 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 7642 | @Override |
Dianne Hackborn | 672cf45 | 2013-03-26 15:24:24 -0700 | [diff] [blame] | 7643 | public void getBaseDisplaySize(int displayId, Point size) { |
| 7644 | synchronized (mWindowMap) { |
| 7645 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 7646 | if (displayContent != null && displayContent.hasAccess(Binder.getCallingUid())) { |
Dianne Hackborn | 672cf45 | 2013-03-26 15:24:24 -0700 | [diff] [blame] | 7647 | synchronized(displayContent.mDisplaySizeLock) { |
| 7648 | size.x = displayContent.mBaseDisplayWidth; |
| 7649 | size.y = displayContent.mBaseDisplayHeight; |
| 7650 | } |
| 7651 | } |
| 7652 | } |
| 7653 | } |
| 7654 | |
| 7655 | @Override |
Jeff Brown | 43aa159 | 2012-09-10 17:36:31 -0700 | [diff] [blame] | 7656 | public void setForcedDisplaySize(int displayId, int width, int height) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 7657 | if (mContext.checkCallingOrSelfPermission( |
| 7658 | android.Manifest.permission.WRITE_SECURE_SETTINGS) != |
| 7659 | PackageManager.PERMISSION_GRANTED) { |
| 7660 | throw new SecurityException("Must hold permission " + |
| 7661 | android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 7662 | } |
| 7663 | if (displayId != Display.DEFAULT_DISPLAY) { |
| 7664 | throw new IllegalArgumentException("Can only set the default display"); |
| 7665 | } |
Dianne Hackborn | 0cca3db | 2013-10-23 10:23:39 -0700 | [diff] [blame] | 7666 | final long ident = Binder.clearCallingIdentity(); |
| 7667 | try { |
| 7668 | synchronized(mWindowMap) { |
| 7669 | // Set some sort of reasonable bounds on the size of the display that we |
| 7670 | // will try to emulate. |
| 7671 | final int MIN_WIDTH = 200; |
| 7672 | final int MIN_HEIGHT = 200; |
| 7673 | final int MAX_SCALE = 2; |
| 7674 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
| 7675 | if (displayContent != null) { |
| 7676 | width = Math.min(Math.max(width, MIN_WIDTH), |
| 7677 | displayContent.mInitialDisplayWidth * MAX_SCALE); |
| 7678 | height = Math.min(Math.max(height, MIN_HEIGHT), |
| 7679 | displayContent.mInitialDisplayHeight * MAX_SCALE); |
| 7680 | setForcedDisplaySizeLocked(displayContent, width, height); |
| 7681 | Settings.Global.putString(mContext.getContentResolver(), |
| 7682 | Settings.Global.DISPLAY_SIZE_FORCED, width + "," + height); |
| 7683 | } |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 7684 | } |
Dianne Hackborn | 0cca3db | 2013-10-23 10:23:39 -0700 | [diff] [blame] | 7685 | } finally { |
| 7686 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7687 | } |
| 7688 | } |
| 7689 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7690 | private void readForcedDisplaySizeAndDensityLocked(final DisplayContent displayContent) { |
Colin Cross | ef96fd9 | 2013-07-18 17:09:56 -0700 | [diff] [blame] | 7691 | String sizeStr = Settings.Global.getString(mContext.getContentResolver(), |
Jeff Brown | 43aa159 | 2012-09-10 17:36:31 -0700 | [diff] [blame] | 7692 | Settings.Global.DISPLAY_SIZE_FORCED); |
Dianne Hackborn | 635a6d5 | 2013-07-29 17:15:38 -0700 | [diff] [blame] | 7693 | if (sizeStr == null || sizeStr.length() == 0) { |
Colin Cross | ef96fd9 | 2013-07-18 17:09:56 -0700 | [diff] [blame] | 7694 | sizeStr = SystemProperties.get(SIZE_OVERRIDE, null); |
| 7695 | } |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7696 | if (sizeStr != null && sizeStr.length() > 0) { |
| 7697 | final int pos = sizeStr.indexOf(','); |
| 7698 | if (pos > 0 && sizeStr.lastIndexOf(',') == pos) { |
| 7699 | int width, height; |
| 7700 | try { |
| 7701 | width = Integer.parseInt(sizeStr.substring(0, pos)); |
| 7702 | height = Integer.parseInt(sizeStr.substring(pos+1)); |
| 7703 | synchronized(displayContent.mDisplaySizeLock) { |
| 7704 | if (displayContent.mBaseDisplayWidth != width |
| 7705 | || displayContent.mBaseDisplayHeight != height) { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7706 | Slog.i(TAG, "FORCED DISPLAY SIZE: " + width + "x" + height); |
| 7707 | displayContent.mBaseDisplayWidth = width; |
| 7708 | displayContent.mBaseDisplayHeight = height; |
| 7709 | } |
| 7710 | } |
| 7711 | } catch (NumberFormatException ex) { |
| 7712 | } |
| 7713 | } |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 7714 | } |
Colin Cross | ef96fd9 | 2013-07-18 17:09:56 -0700 | [diff] [blame] | 7715 | String densityStr = Settings.Global.getString(mContext.getContentResolver(), |
Jeff Brown | 43aa159 | 2012-09-10 17:36:31 -0700 | [diff] [blame] | 7716 | Settings.Global.DISPLAY_DENSITY_FORCED); |
Dianne Hackborn | 635a6d5 | 2013-07-29 17:15:38 -0700 | [diff] [blame] | 7717 | if (densityStr == null || densityStr.length() == 0) { |
Colin Cross | ef96fd9 | 2013-07-18 17:09:56 -0700 | [diff] [blame] | 7718 | densityStr = SystemProperties.get(DENSITY_OVERRIDE, null); |
| 7719 | } |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7720 | if (densityStr != null && densityStr.length() > 0) { |
| 7721 | int density; |
| 7722 | try { |
| 7723 | density = Integer.parseInt(densityStr); |
| 7724 | synchronized(displayContent.mDisplaySizeLock) { |
| 7725 | if (displayContent.mBaseDisplayDensity != density) { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7726 | Slog.i(TAG, "FORCED DISPLAY DENSITY: " + density); |
| 7727 | displayContent.mBaseDisplayDensity = density; |
| 7728 | } |
| 7729 | } |
| 7730 | } catch (NumberFormatException ex) { |
| 7731 | } |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 7732 | } |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 7733 | } |
| 7734 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 7735 | // displayContent must not be null |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7736 | private void setForcedDisplaySizeLocked(DisplayContent displayContent, int width, int height) { |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 7737 | Slog.i(TAG, "Using new display size: " + width + "x" + height); |
| 7738 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7739 | synchronized(displayContent.mDisplaySizeLock) { |
| 7740 | displayContent.mBaseDisplayWidth = width; |
| 7741 | displayContent.mBaseDisplayHeight = height; |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 7742 | } |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7743 | reconfigureDisplayLocked(displayContent); |
| 7744 | } |
| 7745 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 7746 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7747 | public void clearForcedDisplaySize(int displayId) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 7748 | if (mContext.checkCallingOrSelfPermission( |
| 7749 | android.Manifest.permission.WRITE_SECURE_SETTINGS) != |
| 7750 | PackageManager.PERMISSION_GRANTED) { |
| 7751 | throw new SecurityException("Must hold permission " + |
| 7752 | android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 7753 | } |
| 7754 | if (displayId != Display.DEFAULT_DISPLAY) { |
| 7755 | throw new IllegalArgumentException("Can only set the default display"); |
| 7756 | } |
Dianne Hackborn | 0cca3db | 2013-10-23 10:23:39 -0700 | [diff] [blame] | 7757 | final long ident = Binder.clearCallingIdentity(); |
| 7758 | try { |
| 7759 | synchronized(mWindowMap) { |
| 7760 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
| 7761 | if (displayContent != null) { |
| 7762 | setForcedDisplaySizeLocked(displayContent, displayContent.mInitialDisplayWidth, |
| 7763 | displayContent.mInitialDisplayHeight); |
| 7764 | Settings.Global.putString(mContext.getContentResolver(), |
| 7765 | Settings.Global.DISPLAY_SIZE_FORCED, ""); |
| 7766 | } |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 7767 | } |
Dianne Hackborn | 0cca3db | 2013-10-23 10:23:39 -0700 | [diff] [blame] | 7768 | } finally { |
| 7769 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7770 | } |
| 7771 | } |
| 7772 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 7773 | @Override |
Dianne Hackborn | 672cf45 | 2013-03-26 15:24:24 -0700 | [diff] [blame] | 7774 | public int getInitialDisplayDensity(int displayId) { |
| 7775 | synchronized (mWindowMap) { |
| 7776 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 7777 | if (displayContent != null && displayContent.hasAccess(Binder.getCallingUid())) { |
Dianne Hackborn | 672cf45 | 2013-03-26 15:24:24 -0700 | [diff] [blame] | 7778 | synchronized(displayContent.mDisplaySizeLock) { |
| 7779 | return displayContent.mInitialDisplayDensity; |
| 7780 | } |
| 7781 | } |
| 7782 | } |
| 7783 | return -1; |
| 7784 | } |
| 7785 | |
| 7786 | @Override |
| 7787 | public int getBaseDisplayDensity(int displayId) { |
| 7788 | synchronized (mWindowMap) { |
| 7789 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 7790 | if (displayContent != null && displayContent.hasAccess(Binder.getCallingUid())) { |
Dianne Hackborn | 672cf45 | 2013-03-26 15:24:24 -0700 | [diff] [blame] | 7791 | synchronized(displayContent.mDisplaySizeLock) { |
| 7792 | return displayContent.mBaseDisplayDensity; |
| 7793 | } |
| 7794 | } |
| 7795 | } |
| 7796 | return -1; |
| 7797 | } |
| 7798 | |
| 7799 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7800 | public void setForcedDisplayDensity(int displayId, int density) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 7801 | if (mContext.checkCallingOrSelfPermission( |
| 7802 | android.Manifest.permission.WRITE_SECURE_SETTINGS) != |
| 7803 | PackageManager.PERMISSION_GRANTED) { |
| 7804 | throw new SecurityException("Must hold permission " + |
| 7805 | android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 7806 | } |
| 7807 | if (displayId != Display.DEFAULT_DISPLAY) { |
| 7808 | throw new IllegalArgumentException("Can only set the default display"); |
| 7809 | } |
Dianne Hackborn | 0cca3db | 2013-10-23 10:23:39 -0700 | [diff] [blame] | 7810 | final long ident = Binder.clearCallingIdentity(); |
| 7811 | try { |
| 7812 | synchronized(mWindowMap) { |
| 7813 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
| 7814 | if (displayContent != null) { |
| 7815 | setForcedDisplayDensityLocked(displayContent, density); |
| 7816 | Settings.Global.putString(mContext.getContentResolver(), |
| 7817 | Settings.Global.DISPLAY_DENSITY_FORCED, Integer.toString(density)); |
| 7818 | } |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 7819 | } |
Dianne Hackborn | 0cca3db | 2013-10-23 10:23:39 -0700 | [diff] [blame] | 7820 | } finally { |
| 7821 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7822 | } |
| 7823 | } |
| 7824 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 7825 | // displayContent must not be null |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7826 | private void setForcedDisplayDensityLocked(DisplayContent displayContent, int density) { |
| 7827 | Slog.i(TAG, "Using new display density: " + density); |
| 7828 | |
| 7829 | synchronized(displayContent.mDisplaySizeLock) { |
| 7830 | displayContent.mBaseDisplayDensity = density; |
| 7831 | } |
| 7832 | reconfigureDisplayLocked(displayContent); |
| 7833 | } |
| 7834 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 7835 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7836 | public void clearForcedDisplayDensity(int displayId) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 7837 | if (mContext.checkCallingOrSelfPermission( |
| 7838 | android.Manifest.permission.WRITE_SECURE_SETTINGS) != |
| 7839 | PackageManager.PERMISSION_GRANTED) { |
| 7840 | throw new SecurityException("Must hold permission " + |
| 7841 | android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 7842 | } |
| 7843 | if (displayId != Display.DEFAULT_DISPLAY) { |
| 7844 | throw new IllegalArgumentException("Can only set the default display"); |
| 7845 | } |
Dianne Hackborn | 0cca3db | 2013-10-23 10:23:39 -0700 | [diff] [blame] | 7846 | final long ident = Binder.clearCallingIdentity(); |
| 7847 | try { |
| 7848 | synchronized(mWindowMap) { |
| 7849 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
| 7850 | if (displayContent != null) { |
| 7851 | setForcedDisplayDensityLocked(displayContent, |
| 7852 | displayContent.mInitialDisplayDensity); |
| 7853 | Settings.Global.putString(mContext.getContentResolver(), |
| 7854 | Settings.Global.DISPLAY_DENSITY_FORCED, ""); |
| 7855 | } |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 7856 | } |
Dianne Hackborn | 0cca3db | 2013-10-23 10:23:39 -0700 | [diff] [blame] | 7857 | } finally { |
| 7858 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7859 | } |
| 7860 | } |
| 7861 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 7862 | // displayContent must not be null |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7863 | private void reconfigureDisplayLocked(DisplayContent displayContent) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 7864 | // TODO: Multidisplay: for now only use with default display. |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 7865 | configureDisplayPolicyLocked(displayContent); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 7866 | displayContent.layoutNeeded = true; |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7867 | |
| 7868 | boolean configChanged = updateOrientationFromAppTokensLocked(false); |
| 7869 | mTempConfiguration.setToDefaults(); |
| 7870 | mTempConfiguration.fontScale = mCurConfiguration.fontScale; |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 7871 | if (computeScreenConfigurationLocked(mTempConfiguration)) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7872 | if (mCurConfiguration.diff(mTempConfiguration) != 0) { |
| 7873 | configChanged = true; |
| 7874 | } |
| 7875 | } |
| 7876 | |
| 7877 | if (configChanged) { |
| 7878 | mWaitingForConfig = true; |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 7879 | startFreezingDisplayLocked(false, 0, 0); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7880 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 7881 | } |
| 7882 | |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7883 | performLayoutAndPlaceSurfacesLocked(); |
| 7884 | } |
| 7885 | |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 7886 | private void configureDisplayPolicyLocked(DisplayContent displayContent) { |
| 7887 | mPolicy.setInitialDisplaySize(displayContent.getDisplay(), |
| 7888 | displayContent.mBaseDisplayWidth, |
| 7889 | displayContent.mBaseDisplayHeight, |
| 7890 | displayContent.mBaseDisplayDensity); |
| 7891 | |
| 7892 | DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 7893 | mPolicy.setDisplayOverscan(displayContent.getDisplay(), |
| 7894 | displayInfo.overscanLeft, displayInfo.overscanTop, |
| 7895 | displayInfo.overscanRight, displayInfo.overscanBottom); |
| 7896 | } |
| 7897 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 7898 | @Override |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 7899 | public void setOverscan(int displayId, int left, int top, int right, int bottom) { |
| 7900 | if (mContext.checkCallingOrSelfPermission( |
| 7901 | android.Manifest.permission.WRITE_SECURE_SETTINGS) != |
| 7902 | PackageManager.PERMISSION_GRANTED) { |
| 7903 | throw new SecurityException("Must hold permission " + |
| 7904 | android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 7905 | } |
Dianne Hackborn | 0cca3db | 2013-10-23 10:23:39 -0700 | [diff] [blame] | 7906 | final long ident = Binder.clearCallingIdentity(); |
| 7907 | try { |
| 7908 | synchronized(mWindowMap) { |
| 7909 | DisplayContent displayContent = getDisplayContentLocked(displayId); |
| 7910 | if (displayContent != null) { |
| 7911 | setOverscanLocked(displayContent, left, top, right, bottom); |
| 7912 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 7913 | } |
Dianne Hackborn | 0cca3db | 2013-10-23 10:23:39 -0700 | [diff] [blame] | 7914 | } finally { |
| 7915 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 7916 | } |
| 7917 | } |
| 7918 | |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 7919 | private void setOverscanLocked(DisplayContent displayContent, |
| 7920 | int left, int top, int right, int bottom) { |
| 7921 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 7922 | synchronized (displayContent.mDisplaySizeLock) { |
| 7923 | displayInfo.overscanLeft = left; |
| 7924 | displayInfo.overscanTop = top; |
| 7925 | displayInfo.overscanRight = right; |
| 7926 | displayInfo.overscanBottom = bottom; |
| 7927 | } |
| 7928 | |
| 7929 | mDisplaySettings.setOverscanLocked(displayInfo.name, left, top, right, bottom); |
| 7930 | mDisplaySettings.writeSettingsLocked(); |
| 7931 | |
| 7932 | reconfigureDisplayLocked(displayContent); |
| 7933 | } |
| 7934 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7935 | // ------------------------------------------------------------- |
| 7936 | // Internals |
| 7937 | // ------------------------------------------------------------- |
| 7938 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7939 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 7940 | boolean throwOnError) { |
| 7941 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7942 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7943 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7944 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 7945 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7946 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7947 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7948 | TAG, "Looking up client " + client + ": " + win); |
| 7949 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7950 | RuntimeException ex = new IllegalArgumentException( |
| 7951 | "Requested window " + client + " does not exist"); |
| 7952 | if (throwOnError) { |
| 7953 | throw ex; |
| 7954 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7955 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7956 | return null; |
| 7957 | } |
| 7958 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7959 | RuntimeException ex = new IllegalArgumentException( |
| 7960 | "Requested window " + client + " is in session " + |
| 7961 | win.mSession + ", not " + session); |
| 7962 | if (throwOnError) { |
| 7963 | throw ex; |
| 7964 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7965 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7966 | return null; |
| 7967 | } |
| 7968 | |
| 7969 | return win; |
| 7970 | } |
| 7971 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7972 | final void rebuildAppWindowListLocked() { |
Craig Mautner | 85689b9 | 2013-10-02 14:52:13 -0700 | [diff] [blame] | 7973 | rebuildAppWindowListLocked(getDefaultDisplayContentLocked()); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7974 | } |
| 7975 | |
| 7976 | private void rebuildAppWindowListLocked(final DisplayContent displayContent) { |
| 7977 | final WindowList windows = displayContent.getWindowList(); |
| 7978 | int NW = windows.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7979 | int i; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 7980 | int lastBelow = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7981 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7982 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7983 | if (mRebuildTmp.length < NW) { |
| 7984 | mRebuildTmp = new WindowState[NW+10]; |
| 7985 | } |
| 7986 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7987 | // First remove all existing app windows. |
| 7988 | i=0; |
| 7989 | while (i < NW) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7990 | WindowState w = windows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7991 | if (w.mAppToken != null) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7992 | WindowState win = windows.remove(i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7993 | win.mRebuilding = true; |
| 7994 | mRebuildTmp[numRemoved] = win; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 7995 | mWindowsChanged = true; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 7996 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7997 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7998 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7999 | continue; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8000 | } else if (lastBelow == i-1) { |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 8001 | if (w.mAttrs.type == TYPE_WALLPAPER || w.mAttrs.type == TYPE_UNIVERSE_BACKGROUND) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8002 | lastBelow = i; |
| 8003 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8004 | } |
| 8005 | i++; |
| 8006 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8007 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8008 | // Keep whatever windows were below the app windows still below, |
| 8009 | // by skipping them. |
| 8010 | lastBelow++; |
| 8011 | i = lastBelow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8012 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8013 | // First add all of the exiting app tokens... these are no longer |
| 8014 | // in the main app list, but still have windows shown. We put them |
| 8015 | // in the back because now that the animation is over we no longer |
| 8016 | // will care about them. |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 8017 | final ArrayList<TaskStack> stacks = displayContent.getStacks(); |
| 8018 | final int numStacks = stacks.size(); |
| 8019 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 8020 | AppTokenList exitingAppTokens = stacks.get(stackNdx).mExitingAppTokens; |
| 8021 | int NT = exitingAppTokens.size(); |
| 8022 | for (int j = 0; j < NT; j++) { |
| 8023 | i = reAddAppWindowsLocked(displayContent, i, exitingAppTokens.get(j)); |
| 8024 | } |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8025 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8026 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8027 | // And add in the still active app tokens in Z order. |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 8028 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 8029 | final ArrayList<Task> tasks = stacks.get(stackNdx).getTasks(); |
| 8030 | final int numTasks = tasks.size(); |
| 8031 | for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { |
| 8032 | final AppTokenList tokens = tasks.get(taskNdx).mAppTokens; |
| 8033 | final int numTokens = tokens.size(); |
| 8034 | for (int tokenNdx = 0; tokenNdx < numTokens; ++tokenNdx) { |
| 8035 | final AppWindowToken wtoken = tokens.get(tokenNdx); |
Craig Mautner | ac90c19 | 2014-02-12 12:37:17 -0800 | [diff] [blame] | 8036 | if (wtoken.mDeferRemoval) { |
| 8037 | continue; |
| 8038 | } |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 8039 | i = reAddAppWindowsLocked(displayContent, i, wtoken); |
| 8040 | } |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 8041 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8042 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8043 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8044 | i -= lastBelow; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8045 | if (i != numRemoved) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 8046 | Slog.w(TAG, "On display=" + displayContent.getDisplayId() + " Rebuild removed " + |
| 8047 | numRemoved + " windows but added " + i, |
Craig Mautner | 9e4f28c | 2013-04-03 10:53:23 -0700 | [diff] [blame] | 8048 | new RuntimeException("here").fillInStackTrace()); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8049 | for (i=0; i<numRemoved; i++) { |
| 8050 | WindowState ws = mRebuildTmp[i]; |
| 8051 | if (ws.mRebuilding) { |
| 8052 | StringWriter sw = new StringWriter(); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 8053 | PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 8054 | ws.dump(pw, "", true); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8055 | pw.flush(); |
| 8056 | Slog.w(TAG, "This window was lost: " + ws); |
| 8057 | Slog.w(TAG, sw.toString()); |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 8058 | ws.mWinAnimator.destroySurfaceLocked(); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8059 | } |
| 8060 | } |
| 8061 | Slog.w(TAG, "Current app token list:"); |
Craig Mautner | 496bdbb | 2013-02-14 09:32:55 -0800 | [diff] [blame] | 8062 | dumpAppTokensLocked(); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8063 | Slog.w(TAG, "Final window list:"); |
| 8064 | dumpWindowsLocked(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8065 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8066 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8067 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8068 | private final void assignLayersLocked(WindowList windows) { |
| 8069 | int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8070 | int curBaseLayer = 0; |
| 8071 | int curLayer = 0; |
| 8072 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8073 | |
Craig Mautner | 018be3d | 2013-08-27 13:25:17 -0700 | [diff] [blame] | 8074 | if (DEBUG_LAYERS) Slog.v(TAG, "Assigning layers based on windows=" + windows, |
| 8075 | new RuntimeException("here").fillInStackTrace()); |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 8076 | |
Svetoslav Ganov | 55468c6 | 2012-10-15 15:09:02 -0700 | [diff] [blame] | 8077 | boolean anyLayerChanged = false; |
| 8078 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8079 | for (i=0; i<N; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8080 | final WindowState w = windows.get(i); |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8081 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 8082 | boolean layerChanged = false; |
| 8083 | int oldLayer = w.mLayer; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8084 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8085 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8086 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8087 | w.mLayer = curLayer; |
| 8088 | } else { |
| 8089 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8090 | w.mLayer = curLayer; |
| 8091 | } |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8092 | if (w.mLayer != oldLayer) { |
| 8093 | layerChanged = true; |
Svetoslav Ganov | 55468c6 | 2012-10-15 15:09:02 -0700 | [diff] [blame] | 8094 | anyLayerChanged = true; |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8095 | } |
Craig Mautner | f766646 | 2013-04-28 08:58:21 -0700 | [diff] [blame] | 8096 | final AppWindowToken wtoken = w.mAppToken; |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8097 | oldLayer = winAnimator.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8098 | if (w.mTargetAppToken != null) { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8099 | winAnimator.mAnimLayer = |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8100 | w.mLayer + w.mTargetAppToken.mAppAnimator.animLayerAdjustment; |
Craig Mautner | f766646 | 2013-04-28 08:58:21 -0700 | [diff] [blame] | 8101 | } else if (wtoken != null) { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8102 | winAnimator.mAnimLayer = |
Craig Mautner | f766646 | 2013-04-28 08:58:21 -0700 | [diff] [blame] | 8103 | w.mLayer + wtoken.mAppAnimator.animLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8104 | } else { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8105 | winAnimator.mAnimLayer = w.mLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8106 | } |
| 8107 | if (w.mIsImWindow) { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8108 | winAnimator.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8109 | } else if (w.mIsWallpaper) { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8110 | winAnimator.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| 8111 | } |
| 8112 | if (winAnimator.mAnimLayer != oldLayer) { |
| 8113 | layerChanged = true; |
Svetoslav Ganov | 55468c6 | 2012-10-15 15:09:02 -0700 | [diff] [blame] | 8114 | anyLayerChanged = true; |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8115 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 8116 | if (layerChanged && w.getStack().isDimming(winAnimator)) { |
| 8117 | // Force an animation pass just to update the mDimLayer layer. |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 8118 | scheduleAnimationLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8119 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8120 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 8121 | + "mBase=" + w.mBaseLayer |
| 8122 | + " mLayer=" + w.mLayer |
Craig Mautner | f766646 | 2013-04-28 08:58:21 -0700 | [diff] [blame] | 8123 | + (wtoken == null ? |
| 8124 | "" : " mAppLayer=" + wtoken.mAppAnimator.animLayerAdjustment) |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 8125 | + " =mAnimLayer=" + winAnimator.mAnimLayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8126 | //System.out.println( |
| 8127 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8128 | } |
Svetoslav Ganov | 55468c6 | 2012-10-15 15:09:02 -0700 | [diff] [blame] | 8129 | |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 8130 | //TODO (multidisplay): Magnification is supported only for the default display. |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 8131 | if (mAccessibilityController != null && anyLayerChanged |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 8132 | && windows.get(windows.size() - 1).getDisplayId() == Display.DEFAULT_DISPLAY) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 8133 | mAccessibilityController.onWindowLayersChangedLocked(); |
Svetoslav Ganov | 55468c6 | 2012-10-15 15:09:02 -0700 | [diff] [blame] | 8134 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8135 | } |
| 8136 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8137 | private final void performLayoutAndPlaceSurfacesLocked() { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 8138 | int loopCount = 6; |
Craig Mautner | a13a41d | 2012-10-16 12:53:13 -0700 | [diff] [blame] | 8139 | do { |
| 8140 | mTraversalScheduled = false; |
| 8141 | performLayoutAndPlaceSurfacesLockedLoop(); |
| 8142 | mH.removeMessages(H.DO_TRAVERSAL); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 8143 | loopCount--; |
| 8144 | } while (mTraversalScheduled && loopCount > 0); |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 8145 | mInnerFields.mWallpaperActionPending = false; |
Craig Mautner | a13a41d | 2012-10-16 12:53:13 -0700 | [diff] [blame] | 8146 | } |
| 8147 | |
| 8148 | private boolean mInLayout = false; |
| 8149 | private final void performLayoutAndPlaceSurfacesLockedLoop() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8150 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8151 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8152 | throw new RuntimeException("Recursive call!"); |
| 8153 | } |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8154 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout. Callers=" |
| 8155 | + Debug.getCallers(3)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8156 | return; |
| 8157 | } |
| 8158 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8159 | if (mWaitingForConfig) { |
| 8160 | // Our configuration has changed (most likely rotation), but we |
| 8161 | // don't yet have the complete configuration to report to |
| 8162 | // applications. Don't do any window layout until we have it. |
| 8163 | return; |
| 8164 | } |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 8165 | |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 8166 | if (!mDisplayReady) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8167 | // Not yet initialized, nothing to do. |
| 8168 | return; |
| 8169 | } |
| 8170 | |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 8171 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmLayout"); |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 8172 | mInLayout = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8173 | boolean recoveringMemory = false; |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 8174 | |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 8175 | try { |
| 8176 | if (mForceRemoves != null) { |
| 8177 | recoveringMemory = true; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8178 | // 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] | 8179 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8180 | WindowState ws = mForceRemoves.get(i); |
| 8181 | Slog.i(TAG, "Force removing: " + ws); |
| 8182 | removeWindowInnerLocked(ws.mSession, ws); |
| 8183 | } |
| 8184 | mForceRemoves = null; |
| 8185 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 8186 | Object tmp = new Object(); |
| 8187 | synchronized (tmp) { |
| 8188 | try { |
| 8189 | tmp.wait(250); |
| 8190 | } catch (InterruptedException e) { |
| 8191 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8192 | } |
| 8193 | } |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 8194 | } catch (RuntimeException e) { |
Dianne Hackborn | 8962028 | 2011-09-11 12:47:45 -0700 | [diff] [blame] | 8195 | 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] | 8196 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8197 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8198 | try { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8199 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 8200 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8201 | mInLayout = false; |
| 8202 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 8203 | if (needsLayout()) { |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 8204 | if (++mLayoutRepeatCount < 6) { |
| 8205 | requestTraversalLocked(); |
| 8206 | } else { |
| 8207 | Slog.e(TAG, "Performed 6 layouts in a row. Skipping"); |
| 8208 | mLayoutRepeatCount = 0; |
| 8209 | } |
| 8210 | } else { |
| 8211 | mLayoutRepeatCount = 0; |
| 8212 | } |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 8213 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8214 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8215 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
You Kim | cb6291c | 2012-12-04 23:22:28 +0900 | [diff] [blame] | 8216 | mH.sendEmptyMessage(H.REPORT_WINDOWS_CHANGE); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8217 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8218 | } catch (RuntimeException e) { |
| 8219 | mInLayout = false; |
Dianne Hackborn | 8962028 | 2011-09-11 12:47:45 -0700 | [diff] [blame] | 8220 | 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] | 8221 | } |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 8222 | |
| 8223 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8224 | } |
| 8225 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8226 | private final void performLayoutLockedInner(final DisplayContent displayContent, |
| 8227 | boolean initial, boolean updateInputWindows) { |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 8228 | if (!displayContent.layoutNeeded) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8229 | return; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8230 | } |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 8231 | displayContent.layoutNeeded = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8232 | WindowList windows = displayContent.getWindowList(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 8233 | boolean isDefaultDisplay = displayContent.isDefaultDisplay; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8234 | |
| 8235 | DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 8236 | final int dw = displayInfo.logicalWidth; |
| 8237 | final int dh = displayInfo.logicalHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8238 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 8239 | final int NFW = mFakeWindows.size(); |
| 8240 | for (int i=0; i<NFW; i++) { |
| 8241 | mFakeWindows.get(i).layout(dw, dh); |
| 8242 | } |
| 8243 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8244 | final int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8245 | int i; |
| 8246 | |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8247 | if (DEBUG_LAYOUT) { |
| 8248 | Slog.v(TAG, "-------------------------------------"); |
| 8249 | Slog.v(TAG, "performLayout: needed=" |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 8250 | + displayContent.layoutNeeded + " dw=" + dw + " dh=" + dh); |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8251 | } |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8252 | |
| 8253 | WindowStateAnimator universeBackground = null; |
| 8254 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 8255 | mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mRotation); |
| 8256 | if (isDefaultDisplay) { |
| 8257 | // Not needed on non-default displays. |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 8258 | mSystemDecorLayer = mPolicy.getSystemDecorLayerLw(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 8259 | mScreenRect.set(0, 0, dw, dh); |
| 8260 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8261 | |
John Spurlock | 4e92a7c | 2013-09-24 17:09:05 -0400 | [diff] [blame] | 8262 | mPolicy.getContentRectLw(mTmpContentRect); |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 8263 | displayContent.resize(mTmpContentRect); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 8264 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8265 | int seq = mLayoutSeq+1; |
| 8266 | if (seq < 0) seq = 0; |
| 8267 | mLayoutSeq = seq; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 8268 | |
| 8269 | boolean behindDream = false; |
| 8270 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8271 | // First perform layout of any root windows (not attached |
| 8272 | // to another window). |
| 8273 | int topAttached = -1; |
| 8274 | for (i = N-1; i >= 0; i--) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8275 | final WindowState win = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8276 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8277 | // Don't do layout of a window if it is not visible, or |
| 8278 | // soon won't be visible, to avoid wasting time and funky |
| 8279 | // changes while a window is animating away. |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 8280 | final boolean gone = (behindDream && mPolicy.canBeForceHidden(win, win.mAttrs)) |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 8281 | || win.isGoneForLayoutLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8282 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8283 | if (DEBUG_LAYOUT && !win.mLayoutAttached) { |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8284 | Slog.v(TAG, "1ST PASS " + win |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8285 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 8286 | + " mLayoutAttached=" + win.mLayoutAttached |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 8287 | + " screen changed=" + win.isConfigChanged()); |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8288 | final AppWindowToken atoken = win.mAppToken; |
| 8289 | if (gone) Slog.v(TAG, " GONE: mViewVisibility=" |
| 8290 | + win.mViewVisibility + " mRelayoutCalled=" |
| 8291 | + win.mRelayoutCalled + " hidden=" |
| 8292 | + win.mRootToken.hidden + " hiddenRequested=" |
| 8293 | + (atoken != null && atoken.hiddenRequested) |
| 8294 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 8295 | else Slog.v(TAG, " VIS: mViewVisibility=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8296 | + win.mViewVisibility + " mRelayoutCalled=" |
| 8297 | + win.mRelayoutCalled + " hidden=" |
| 8298 | + win.mRootToken.hidden + " hiddenRequested=" |
| 8299 | + (atoken != null && atoken.hiddenRequested) |
| 8300 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 8301 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 8302 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8303 | // If this view is GONE, then skip it -- keep the current |
| 8304 | // frame, and let the caller know so they can ignore it |
| 8305 | // if they want. (We do the normal layout for INVISIBLE |
| 8306 | // windows, since that means "perform layout as normal, |
| 8307 | // just don't display"). |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8308 | if (!gone || !win.mHaveFrame || win.mLayoutNeeded |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 8309 | || ((win.isConfigChanged() || win.setInsetsChanged()) && |
| 8310 | (win.mAttrs.type == TYPE_KEYGUARD || |
| 8311 | win.mAppToken != null && win.mAppToken.layoutConfigChanges)) |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8312 | || win.mAttrs.type == TYPE_UNIVERSE_BACKGROUND) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8313 | if (!win.mLayoutAttached) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 8314 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 8315 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 8316 | win.mContentChanged = false; |
| 8317 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 8318 | if (win.mAttrs.type == TYPE_DREAM) { |
| 8319 | // Don't layout windows behind a dream, so that if it |
| 8320 | // does stuff like hide the status bar we won't get a |
| 8321 | // bad transition when it goes away. |
| 8322 | behindDream = true; |
| 8323 | } |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 8324 | win.mLayoutNeeded = false; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 8325 | win.prelayout(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8326 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 8327 | win.mLayoutSeq = seq; |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8328 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8329 | + win.mFrame + " mContainingFrame=" |
| 8330 | + win.mContainingFrame + " mDisplayFrame=" |
| 8331 | + win.mDisplayFrame); |
| 8332 | } else { |
| 8333 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8334 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8335 | } |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8336 | if (win.mViewVisibility == View.VISIBLE |
| 8337 | && win.mAttrs.type == TYPE_UNIVERSE_BACKGROUND |
| 8338 | && universeBackground == null) { |
| 8339 | universeBackground = win.mWinAnimator; |
| 8340 | } |
| 8341 | } |
| 8342 | |
| 8343 | if (mAnimator.mUniverseBackground != universeBackground) { |
| 8344 | mFocusMayChange = true; |
| 8345 | mAnimator.mUniverseBackground = universeBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8346 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8347 | |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 8348 | boolean attachedBehindDream = false; |
| 8349 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8350 | // Now perform layout of attached windows, which usually |
| 8351 | // depend on the position of the window they are attached to. |
| 8352 | // XXX does not deal with windows that are attached to windows |
| 8353 | // that are themselves attached. |
| 8354 | for (i = topAttached; i >= 0; i--) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8355 | final WindowState win = windows.get(i); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8356 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8357 | if (win.mLayoutAttached) { |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8358 | if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + win |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8359 | + " mHaveFrame=" + win.mHaveFrame |
| 8360 | + " mViewVisibility=" + win.mViewVisibility |
| 8361 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8362 | // If this view is GONE, then skip it -- keep the current |
| 8363 | // frame, and let the caller know so they can ignore it |
| 8364 | // if they want. (We do the normal layout for INVISIBLE |
| 8365 | // windows, since that means "perform layout as normal, |
| 8366 | // just don't display"). |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 8367 | if (attachedBehindDream && mPolicy.canBeForceHidden(win, win.mAttrs)) { |
| 8368 | continue; |
| 8369 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8370 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 8371 | || !win.mHaveFrame || win.mLayoutNeeded) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 8372 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 8373 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 8374 | win.mContentChanged = false; |
| 8375 | } |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 8376 | win.mLayoutNeeded = false; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 8377 | win.prelayout(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8378 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 8379 | win.mLayoutSeq = seq; |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8380 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8381 | + win.mFrame + " mContainingFrame=" |
| 8382 | + win.mContainingFrame + " mDisplayFrame=" |
| 8383 | + win.mDisplayFrame); |
| 8384 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 8385 | } else if (win.mAttrs.type == TYPE_DREAM) { |
| 8386 | // Don't layout windows behind a dream, so that if it |
| 8387 | // does stuff like hide the status bar we won't get a |
| 8388 | // bad transition when it goes away. |
| 8389 | attachedBehindDream = behindDream; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8390 | } |
| 8391 | } |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 8392 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8393 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8394 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 8395 | if (updateInputWindows) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 8396 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8397 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8398 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8399 | mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8400 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8401 | |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 8402 | void makeWindowFreezingScreenIfNeededLocked(WindowState w) { |
| 8403 | // If the screen is currently frozen or off, then keep |
| 8404 | // it frozen/off until this window draws at its new |
| 8405 | // orientation. |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 8406 | if (!okToDisplay()) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 8407 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Changing surface while display frozen: " + w); |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 8408 | w.mOrientationChanging = true; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 8409 | w.mLastFreezeDuration = 0; |
Craig Mautner | 3255a28 | 2012-04-16 15:42:47 -0700 | [diff] [blame] | 8410 | mInnerFields.mOrientationChangeComplete = false; |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 8411 | if (!mWindowsFreezingScreen) { |
| 8412 | mWindowsFreezingScreen = true; |
| 8413 | // XXX should probably keep timeout from |
| 8414 | // when we first froze the display. |
| 8415 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 8416 | mH.sendEmptyMessageDelayed(H.WINDOW_FREEZE_TIMEOUT, |
You Kim | cb6291c | 2012-12-04 23:22:28 +0900 | [diff] [blame] | 8417 | WINDOW_FREEZE_TIMEOUT_DURATION); |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 8418 | } |
| 8419 | } |
| 8420 | } |
| 8421 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8422 | /** |
| 8423 | * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method. |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 8424 | * @param windows List of windows on default display. |
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 | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8427 | public int handleAppTransitionReadyLocked(WindowList windows) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8428 | int changes = 0; |
| 8429 | int i; |
| 8430 | int NN = mOpeningApps.size(); |
| 8431 | boolean goodToGo = true; |
| 8432 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8433 | "Checking " + NN + " opening apps (frozen=" |
| 8434 | + mDisplayFrozen + " timeout=" |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 8435 | + mAppTransition.isTimeout() + ")..."); |
| 8436 | if (!mDisplayFrozen && !mAppTransition.isTimeout()) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8437 | // If the display isn't frozen, wait to do anything until |
| 8438 | // all of the apps are ready. Otherwise just go because |
| 8439 | // we'll unfreeze the display when everyone is ready. |
| 8440 | for (i=0; i<NN && goodToGo; i++) { |
| 8441 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 8442 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Craig Mautner | 1d961d4 | 2012-05-27 12:02:11 -0700 | [diff] [blame] | 8443 | "Check opening app=" + wtoken + ": allDrawn=" |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8444 | + wtoken.allDrawn + " startingDisplayed=" |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 8445 | + wtoken.startingDisplayed + " startingMoved=" |
| 8446 | + wtoken.startingMoved); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8447 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 8448 | && !wtoken.startingMoved) { |
| 8449 | goodToGo = false; |
| 8450 | } |
| 8451 | } |
| 8452 | } |
| 8453 | if (goodToGo) { |
| 8454 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO"); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 8455 | int transit = mAppTransition.getAppTransition(); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8456 | if (mSkipAppTransitionAnimation) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 8457 | transit = AppTransition.TRANSIT_UNSET; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8458 | } |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 8459 | mAppTransition.goodToGo(); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8460 | mStartingIconInTransition = false; |
| 8461 | mSkipAppTransitionAnimation = false; |
| 8462 | |
| 8463 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 8464 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8465 | rebuildAppWindowListLocked(); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8466 | |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 8467 | // 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] | 8468 | WindowState oldWallpaper = |
| 8469 | mWallpaperTarget != null && mWallpaperTarget.mWinAnimator.isAnimating() |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 8470 | && !mWallpaperTarget.mWinAnimator.isDummyAnimation() |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 8471 | ? null : mWallpaperTarget; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8472 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8473 | mInnerFields.mWallpaperMayChange = false; |
| 8474 | |
| 8475 | // The top-most window will supply the layout params, |
| 8476 | // and we will determine it below. |
| 8477 | LayoutParams animLp = null; |
| 8478 | int bestAnimLayer = -1; |
| 8479 | boolean fullscreenAnim = false; |
| 8480 | |
| 8481 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8482 | "New wallpaper target=" + mWallpaperTarget |
Daniel Sandler | ab886f5 | 2012-06-04 14:36:25 -0400 | [diff] [blame] | 8483 | + ", oldWallpaper=" + oldWallpaper |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8484 | + ", lower target=" + mLowerWallpaperTarget |
| 8485 | + ", upper target=" + mUpperWallpaperTarget); |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 8486 | |
| 8487 | boolean openingAppHasWallpaper = false; |
| 8488 | boolean closingAppHasWallpaper = false; |
| 8489 | final AppWindowToken lowerWallpaperAppToken; |
| 8490 | final AppWindowToken upperWallpaperAppToken; |
| 8491 | if (mLowerWallpaperTarget == null) { |
| 8492 | lowerWallpaperAppToken = upperWallpaperAppToken = null; |
| 8493 | } else { |
| 8494 | lowerWallpaperAppToken = mLowerWallpaperTarget.mAppToken; |
| 8495 | upperWallpaperAppToken = mUpperWallpaperTarget.mAppToken; |
| 8496 | } |
| 8497 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8498 | // Do a first pass through the tokens for two |
| 8499 | // things: |
| 8500 | // (1) Determine if both the closing and opening |
| 8501 | // app token sets are wallpaper targets, in which |
| 8502 | // case special animations are needed |
| 8503 | // (since the wallpaper needs to stay static |
| 8504 | // behind them). |
| 8505 | // (2) Find the layout params of the top-most |
| 8506 | // application window in the tokens, which is |
| 8507 | // what will control the animation theme. |
| 8508 | final int NC = mClosingApps.size(); |
| 8509 | NN = NC + mOpeningApps.size(); |
| 8510 | for (i=0; i<NN; i++) { |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 8511 | final AppWindowToken wtoken; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8512 | if (i < NC) { |
| 8513 | wtoken = mClosingApps.get(i); |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 8514 | if (wtoken == lowerWallpaperAppToken || wtoken == upperWallpaperAppToken) { |
| 8515 | closingAppHasWallpaper = true; |
| 8516 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8517 | } else { |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 8518 | wtoken = mOpeningApps.get(i - NC); |
| 8519 | if (wtoken == lowerWallpaperAppToken || wtoken == upperWallpaperAppToken) { |
| 8520 | openingAppHasWallpaper = true; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8521 | } |
| 8522 | } |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 8523 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8524 | if (wtoken.appFullscreen) { |
| 8525 | WindowState ws = wtoken.findMainWindow(); |
| 8526 | if (ws != null) { |
| 8527 | animLp = ws.mAttrs; |
| 8528 | bestAnimLayer = ws.mLayer; |
| 8529 | fullscreenAnim = true; |
| 8530 | } |
| 8531 | } else if (!fullscreenAnim) { |
| 8532 | WindowState ws = wtoken.findMainWindow(); |
| 8533 | if (ws != null) { |
| 8534 | if (ws.mLayer > bestAnimLayer) { |
| 8535 | animLp = ws.mAttrs; |
| 8536 | bestAnimLayer = ws.mLayer; |
| 8537 | } |
| 8538 | } |
| 8539 | } |
| 8540 | } |
| 8541 | |
Craig Mautner | 798adef | 2013-10-22 14:29:01 -0700 | [diff] [blame] | 8542 | mAnimateWallpaperWithTarget = false; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 8543 | if (closingAppHasWallpaper && openingAppHasWallpaper) { |
| 8544 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Wallpaper animation!"); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8545 | switch (transit) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 8546 | case AppTransition.TRANSIT_ACTIVITY_OPEN: |
| 8547 | case AppTransition.TRANSIT_TASK_OPEN: |
| 8548 | case AppTransition.TRANSIT_TASK_TO_FRONT: |
| 8549 | transit = AppTransition.TRANSIT_WALLPAPER_INTRA_OPEN; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8550 | break; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 8551 | case AppTransition.TRANSIT_ACTIVITY_CLOSE: |
| 8552 | case AppTransition.TRANSIT_TASK_CLOSE: |
| 8553 | case AppTransition.TRANSIT_TASK_TO_BACK: |
| 8554 | transit = AppTransition.TRANSIT_WALLPAPER_INTRA_CLOSE; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8555 | break; |
| 8556 | } |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 8557 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "New transit: " + transit); |
Adam Lesinski | 76afd1f | 2013-10-23 10:45:28 -0700 | [diff] [blame] | 8558 | } else if ((oldWallpaper != null) && !mOpeningApps.isEmpty() |
| 8559 | && !mOpeningApps.contains(oldWallpaper.mAppToken)) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8560 | // We are transitioning from an activity with |
| 8561 | // a wallpaper to one without. |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 8562 | transit = AppTransition.TRANSIT_WALLPAPER_CLOSE; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8563 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8564 | "New transit away from wallpaper: " + transit); |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 8565 | } else if (mWallpaperTarget != null && mWallpaperTarget.isVisibleLw()) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8566 | // We are transitioning from an activity without |
| 8567 | // a wallpaper to now showing the wallpaper |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 8568 | transit = AppTransition.TRANSIT_WALLPAPER_OPEN; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8569 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8570 | "New transit into wallpaper: " + transit); |
Craig Mautner | 798adef | 2013-10-22 14:29:01 -0700 | [diff] [blame] | 8571 | } else { |
| 8572 | mAnimateWallpaperWithTarget = true; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8573 | } |
| 8574 | |
| 8575 | // If all closing windows are obscured, then there is |
| 8576 | // no need to do an animation. This is the case, for |
| 8577 | // example, when this transition is being done behind |
| 8578 | // the lock screen. |
| 8579 | if (!mPolicy.allowAppAnimationsLw()) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 8580 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8581 | "Animations disallowed by keyguard or dream."); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8582 | animLp = null; |
| 8583 | } |
| 8584 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8585 | AppWindowToken topOpeningApp = null; |
| 8586 | int topOpeningLayer = 0; |
| 8587 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8588 | NN = mOpeningApps.size(); |
| 8589 | for (i=0; i<NN; i++) { |
| 8590 | AppWindowToken wtoken = mOpeningApps.get(i); |
Craig Mautner | bea12bd | 2012-08-20 10:18:34 -0700 | [diff] [blame] | 8591 | final AppWindowAnimator appAnimator = wtoken.mAppAnimator; |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 8592 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now opening app" + wtoken); |
Craig Mautner | bea12bd | 2012-08-20 10:18:34 -0700 | [diff] [blame] | 8593 | appAnimator.clearThumbnail(); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8594 | wtoken.inPendingTransaction = false; |
Craig Mautner | bea12bd | 2012-08-20 10:18:34 -0700 | [diff] [blame] | 8595 | appAnimator.animation = null; |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 8596 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8597 | wtoken.updateReportedVisibilityLocked(); |
| 8598 | wtoken.waitingToShow = false; |
Craig Mautner | bea12bd | 2012-08-20 10:18:34 -0700 | [diff] [blame] | 8599 | |
| 8600 | appAnimator.mAllAppWinAnimators.clear(); |
| 8601 | final int N = wtoken.allAppWindows.size(); |
| 8602 | for (int j = 0; j < N; j++) { |
| 8603 | appAnimator.mAllAppWinAnimators.add(wtoken.allAppWindows.get(j).mWinAnimator); |
| 8604 | } |
| 8605 | mAnimator.mAnimating |= appAnimator.showAllWindowsLocked(); |
| 8606 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8607 | if (animLp != null) { |
| 8608 | int layer = -1; |
| 8609 | for (int j=0; j<wtoken.windows.size(); j++) { |
| 8610 | WindowState win = wtoken.windows.get(j); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 8611 | if (win.mWinAnimator.mAnimLayer > layer) { |
| 8612 | layer = win.mWinAnimator.mAnimLayer; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8613 | } |
| 8614 | } |
| 8615 | if (topOpeningApp == null || layer > topOpeningLayer) { |
| 8616 | topOpeningApp = wtoken; |
| 8617 | topOpeningLayer = layer; |
| 8618 | } |
| 8619 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8620 | } |
| 8621 | NN = mClosingApps.size(); |
| 8622 | for (i=0; i<NN; i++) { |
| 8623 | AppWindowToken wtoken = mClosingApps.get(i); |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 8624 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now closing app " + wtoken); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8625 | wtoken.mAppAnimator.clearThumbnail(); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8626 | wtoken.inPendingTransaction = false; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8627 | wtoken.mAppAnimator.animation = null; |
Adam Lesinski | 76afd1f | 2013-10-23 10:45:28 -0700 | [diff] [blame] | 8628 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8629 | wtoken.updateReportedVisibilityLocked(); |
| 8630 | wtoken.waitingToHide = false; |
| 8631 | // Force the allDrawn flag, because we want to start |
| 8632 | // this guy's animations regardless of whether it's |
| 8633 | // gotten drawn. |
| 8634 | wtoken.allDrawn = true; |
Craig Mautner | 7636dfb | 2012-11-16 15:24:11 -0800 | [diff] [blame] | 8635 | wtoken.deferClearAllDrawn = false; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8636 | } |
| 8637 | |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 8638 | boolean useAlternateThumbnailAnimation = |
| 8639 | SystemProperties.getBoolean("persist.anim.use_alt_thumbnail", false); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 8640 | AppWindowAnimator appAnimator = |
| 8641 | topOpeningApp == null ? null : topOpeningApp.mAppAnimator; |
| 8642 | Bitmap nextAppTransitionThumbnail = mAppTransition.getNextAppTransitionThumbnail(); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 8643 | if (!useAlternateThumbnailAnimation && nextAppTransitionThumbnail != null |
| 8644 | && appAnimator != null && appAnimator.animation != null) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8645 | // This thumbnail animation is very special, we need to have |
| 8646 | // an extra surface with the thumbnail included with the animation. |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 8647 | Rect dirty = new Rect(0, 0, nextAppTransitionThumbnail.getWidth(), |
| 8648 | nextAppTransitionThumbnail.getHeight()); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8649 | try { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 8650 | // TODO(multi-display): support other displays |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 8651 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 8652 | final Display display = displayContent.getDisplay(); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 8653 | SurfaceControl surfaceControl = new SurfaceControl(mFxSession, |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 8654 | "thumbnail anim", |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 8655 | dirty.width(), dirty.height(), |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 8656 | PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 8657 | surfaceControl.setLayerStack(display.getLayerStack()); |
| 8658 | appAnimator.thumbnail = surfaceControl; |
| 8659 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " THUMBNAIL " + surfaceControl + ": CREATE"); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8660 | Surface drawSurface = new Surface(); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 8661 | drawSurface.copyFrom(surfaceControl); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8662 | Canvas c = drawSurface.lockCanvas(dirty); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 8663 | c.drawBitmap(nextAppTransitionThumbnail, 0, 0, null); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8664 | drawSurface.unlockCanvasAndPost(c); |
| 8665 | drawSurface.release(); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 8666 | appAnimator.thumbnailLayer = topOpeningLayer; |
| 8667 | DisplayInfo displayInfo = getDefaultDisplayInfoLocked(); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 8668 | Animation anim = mAppTransition.createThumbnailScaleAnimationLocked( |
| 8669 | displayInfo.appWidth, displayInfo.appHeight, transit); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 8670 | appAnimator.thumbnailAnimation = anim; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8671 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8672 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 8673 | Point p = new Point(); |
| 8674 | mAppTransition.getStartingPoint(p); |
| 8675 | appAnimator.thumbnailX = p.x; |
| 8676 | appAnimator.thumbnailY = p.y; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8677 | } catch (OutOfResourcesException e) { |
| 8678 | Slog.e(TAG, "Can't allocate thumbnail/Canvas surface w=" + dirty.width() |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 8679 | + " h=" + dirty.height(), e); |
| 8680 | appAnimator.clearThumbnail(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8681 | } |
| 8682 | } |
| 8683 | |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 8684 | mAppTransition.postAnimationCallback(); |
| 8685 | mAppTransition.clear(); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8686 | |
| 8687 | mOpeningApps.clear(); |
| 8688 | mClosingApps.clear(); |
| 8689 | |
| 8690 | // This has changed the visibility of windows, so perform |
| 8691 | // a new layout to get them all up-to-date. |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 8692 | changes |= WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8693 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 8694 | getDefaultDisplayContentLocked().layoutNeeded = true; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8695 | |
| 8696 | // TODO(multidisplay): IMEs are only supported on the default display. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 8697 | if (windows == getDefaultWindowListLocked() |
| 8698 | && !moveInputMethodWindowsIfNeededLocked(true)) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8699 | assignLayersLocked(windows); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8700 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8701 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, false /*updateInputWindows*/); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8702 | mFocusMayChange = false; |
| 8703 | } |
| 8704 | |
| 8705 | return changes; |
| 8706 | } |
| 8707 | |
| 8708 | /** |
| 8709 | * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method. |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8710 | * @return bitmap indicating if another pass through layout must be made. |
| 8711 | */ |
Craig Mautner | 2f995a7 | 2012-02-21 09:53:21 -0800 | [diff] [blame] | 8712 | private int handleAnimatingStoppedAndTransitionLocked() { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8713 | int changes = 0; |
| 8714 | |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 8715 | mAppTransition.setIdle(); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8716 | // Restore window app tokens to the ActivityManager views |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 8717 | ArrayList<TaskStack> stacks = getDefaultDisplayContentLocked().getStacks(); |
| 8718 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 8719 | final ArrayList<Task> tasks = stacks.get(stackNdx).getTasks(); |
| 8720 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 8721 | final AppTokenList tokens = tasks.get(taskNdx).mAppTokens; |
| 8722 | for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) { |
| 8723 | tokens.get(tokenNdx).sendingToBottom = false; |
| 8724 | } |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 8725 | } |
Craig Mautner | 3f99fde | 2012-06-19 14:10:01 -0700 | [diff] [blame] | 8726 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8727 | rebuildAppWindowListLocked(); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8728 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8729 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 8730 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 8731 | "Wallpaper layer changed: assigning layers + relayout"); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8732 | moveInputMethodWindowsIfNeededLocked(true); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8733 | mInnerFields.mWallpaperMayChange = true; |
| 8734 | // Since the window list has been rebuilt, focus might |
| 8735 | // have to be recomputed since the actual order of windows |
| 8736 | // might have changed again. |
| 8737 | mFocusMayChange = true; |
| 8738 | |
| 8739 | return changes; |
| 8740 | } |
| 8741 | |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8742 | private void updateResizingWindows(final WindowState w) { |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 8743 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
Craig Mautner | ade0a9a | 2012-10-06 13:55:07 -0700 | [diff] [blame] | 8744 | if (w.mHasSurface && w.mLayoutSeq == mLayoutSeq) { |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 8745 | w.setInsetsChanged(); |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 8746 | boolean configChanged = w.isConfigChanged(); |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8747 | if (DEBUG_CONFIGURATION && configChanged) { |
| 8748 | Slog.v(TAG, "Win " + w + " config changed: " |
| 8749 | + mCurConfiguration); |
| 8750 | } |
| 8751 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| 8752 | + ": configChanged=" + configChanged |
| 8753 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| 8754 | w.mLastFrame.set(w.mFrame); |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 8755 | if (w.mContentInsetsChanged |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8756 | || w.mVisibleInsetsChanged |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 8757 | || winAnimator.mSurfaceResized |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8758 | || configChanged) { |
| 8759 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 8760 | Slog.v(TAG, "Resize reasons for w=" + w + ": " |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8761 | + " contentInsetsChanged=" + w.mContentInsetsChanged |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 8762 | + " " + w.mContentInsets.toShortString() |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8763 | + " visibleInsetsChanged=" + w.mVisibleInsetsChanged |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 8764 | + " " + w.mVisibleInsets.toShortString() |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8765 | + " surfaceResized=" + winAnimator.mSurfaceResized |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8766 | + " configChanged=" + configChanged); |
| 8767 | } |
| 8768 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 8769 | w.mLastOverscanInsets.set(w.mOverscanInsets); |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8770 | w.mLastContentInsets.set(w.mContentInsets); |
| 8771 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| 8772 | makeWindowFreezingScreenIfNeededLocked(w); |
| 8773 | // If the orientation is changing, then we need to |
| 8774 | // hold off on unfreezing the display until this |
| 8775 | // window has been redrawn; to do that, we need |
| 8776 | // to go through the process of getting informed |
| 8777 | // by the application when it has finished drawing. |
| 8778 | if (w.mOrientationChanging) { |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8779 | if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION) Slog.v(TAG, |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 8780 | "Orientation start waiting for draw mDrawState=DRAW_PENDING in " |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 8781 | + w + ", surface " + winAnimator.mSurfaceControl); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 8782 | winAnimator.mDrawState = WindowStateAnimator.DRAW_PENDING; |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8783 | if (w.mAppToken != null) { |
| 8784 | w.mAppToken.allDrawn = false; |
Craig Mautner | 7636dfb | 2012-11-16 15:24:11 -0800 | [diff] [blame] | 8785 | w.mAppToken.deferClearAllDrawn = false; |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8786 | } |
| 8787 | } |
| 8788 | if (!mResizingWindows.contains(w)) { |
| 8789 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8790 | "Resizing window " + w + " to " + winAnimator.mSurfaceW |
| 8791 | + "x" + winAnimator.mSurfaceH); |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8792 | mResizingWindows.add(w); |
| 8793 | } |
| 8794 | } else if (w.mOrientationChanging) { |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 8795 | if (w.isDrawnLw()) { |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8796 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| 8797 | "Orientation not waiting for draw in " |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 8798 | + w + ", surface " + winAnimator.mSurfaceControl); |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8799 | w.mOrientationChanging = false; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 8800 | w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
| 8801 | - mDisplayFreezeTime); |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8802 | } |
| 8803 | } |
| 8804 | } |
| 8805 | } |
| 8806 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8807 | /** |
| 8808 | * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method. |
| 8809 | * |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8810 | * @param w WindowState this method is applied to. |
| 8811 | * @param currentTime The time which animations use for calculating transitions. |
| 8812 | * @param innerDw Width of app window. |
| 8813 | * @param innerDh Height of app window. |
| 8814 | */ |
| 8815 | private void handleNotObscuredLocked(final WindowState w, final long currentTime, |
| 8816 | final int innerDw, final int innerDh) { |
| 8817 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8818 | final int attrFlags = attrs.flags; |
| 8819 | final boolean canBeSeen = w.isDisplayedLw(); |
Jeff Brown | 4fd7917 | 2013-11-07 17:58:15 -0800 | [diff] [blame] | 8820 | final boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 8821 | |
| 8822 | if (opaqueDrawn && w.isFullscreen(innerDw, innerDh)) { |
| 8823 | // This window completely covers everything behind it, |
| 8824 | // so we want to leave all of them as undimmed (for |
| 8825 | // performance reasons). |
| 8826 | mInnerFields.mObscured = true; |
| 8827 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8828 | |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 8829 | if (w.mHasSurface) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8830 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 8831 | mInnerFields.mHoldScreen = w.mSession; |
| 8832 | } |
| 8833 | if (!mInnerFields.mSyswin && w.mAttrs.screenBrightness >= 0 |
| 8834 | && mInnerFields.mScreenBrightness < 0) { |
| 8835 | mInnerFields.mScreenBrightness = w.mAttrs.screenBrightness; |
| 8836 | } |
| 8837 | if (!mInnerFields.mSyswin && w.mAttrs.buttonBrightness >= 0 |
| 8838 | && mInnerFields.mButtonBrightness < 0) { |
| 8839 | mInnerFields.mButtonBrightness = w.mAttrs.buttonBrightness; |
| 8840 | } |
Jeff Brown | 1e3b98d | 2012-09-30 18:58:59 -0700 | [diff] [blame] | 8841 | if (!mInnerFields.mSyswin && w.mAttrs.userActivityTimeout >= 0 |
| 8842 | && mInnerFields.mUserActivityTimeout < 0) { |
| 8843 | mInnerFields.mUserActivityTimeout = w.mAttrs.userActivityTimeout; |
| 8844 | } |
| 8845 | |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 8846 | final int type = attrs.type; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8847 | if (canBeSeen |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 8848 | && (type == TYPE_SYSTEM_DIALOG |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 8849 | || type == TYPE_RECENTS_OVERLAY |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 8850 | || type == TYPE_KEYGUARD |
| 8851 | || type == TYPE_SYSTEM_ERROR)) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8852 | mInnerFields.mSyswin = true; |
| 8853 | } |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 8854 | |
| 8855 | if (canBeSeen) { |
Jeff Brown | 4fd7917 | 2013-11-07 17:58:15 -0800 | [diff] [blame] | 8856 | // This function assumes that the contents of the default display are |
| 8857 | // processed first before secondary displays. |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 8858 | final DisplayContent displayContent = w.getDisplayContent(); |
| 8859 | if (displayContent != null && displayContent.isDefaultDisplay) { |
Jeff Brown | 4fd7917 | 2013-11-07 17:58:15 -0800 | [diff] [blame] | 8860 | // While a dream or keyguard is showing, obscure ordinary application |
| 8861 | // content on secondary displays (by forcibly enabling mirroring unless |
| 8862 | // there is other content we want to show) but still allow opaque |
| 8863 | // keyguard dialogs to be shown. |
| 8864 | if (type == TYPE_DREAM || type == TYPE_KEYGUARD) { |
| 8865 | mInnerFields.mObscureApplicationContentOnSecondaryDisplays = true; |
| 8866 | } |
| 8867 | mInnerFields.mDisplayHasContent = true; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 8868 | } else if (displayContent != null && |
| 8869 | (!mInnerFields.mObscureApplicationContentOnSecondaryDisplays |
| 8870 | || (mInnerFields.mObscured && type == TYPE_KEYGUARD_DIALOG))) { |
Jeff Brown | 4fd7917 | 2013-11-07 17:58:15 -0800 | [diff] [blame] | 8871 | // Allow full screen keyguard presentation dialogs to be seen. |
| 8872 | mInnerFields.mDisplayHasContent = true; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 8873 | } |
| 8874 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8875 | } |
Craig Mautner | 312eac4 | 2012-11-13 10:56:22 -0800 | [diff] [blame] | 8876 | } |
| 8877 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 8878 | private void handleFlagDimBehind(WindowState w) { |
Craig Mautner | 312eac4 | 2012-11-13 10:56:22 -0800 | [diff] [blame] | 8879 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8880 | if ((attrs.flags & FLAG_DIM_BEHIND) != 0 |
| 8881 | && w.isDisplayedLw() |
Craig Mautner | 236a35b | 2012-06-08 09:54:59 -0700 | [diff] [blame] | 8882 | && !w.mExiting) { |
Craig Mautner | 312eac4 | 2012-11-13 10:56:22 -0800 | [diff] [blame] | 8883 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 8884 | final TaskStack stack = w.getStack(); |
| 8885 | stack.setDimmingTag(); |
| 8886 | if (!stack.isDimming(winAnimator)) { |
Craig Mautner | 312eac4 | 2012-11-13 10:56:22 -0800 | [diff] [blame] | 8887 | if (localLOGV) Slog.v(TAG, "Win " + w + " start dimming."); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 8888 | stack.startDimmingIfNeeded(winAnimator); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8889 | } |
| 8890 | } |
| 8891 | } |
| 8892 | |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 8893 | private void updateAllDrawnLocked(DisplayContent displayContent) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 8894 | // See if any windows have been drawn, so they (and others |
| 8895 | // associated with them) can now be shown. |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 8896 | ArrayList<TaskStack> stacks = displayContent.getStacks(); |
| 8897 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 8898 | final ArrayList<Task> tasks = stacks.get(stackNdx).getTasks(); |
| 8899 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 8900 | final AppTokenList tokens = tasks.get(taskNdx).mAppTokens; |
| 8901 | for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) { |
| 8902 | final AppWindowToken wtoken = tokens.get(tokenNdx); |
| 8903 | if (!wtoken.allDrawn) { |
| 8904 | int numInteresting = wtoken.numInterestingWindows; |
| 8905 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 8906 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 8907 | "allDrawn: " + wtoken |
| 8908 | + " interesting=" + numInteresting |
| 8909 | + " drawn=" + wtoken.numDrawnWindows); |
| 8910 | wtoken.allDrawn = true; |
| 8911 | mH.obtainMessage(H.NOTIFY_ACTIVITY_DRAWN, wtoken.token).sendToTarget(); |
| 8912 | } |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 8913 | } |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 8914 | } |
| 8915 | } |
| 8916 | } |
| 8917 | } |
| 8918 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 8919 | // "Something has changed! Let's make it correct now." |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8920 | private final void performLayoutAndPlaceSurfacesLockedInner(boolean recoveringMemory) { |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 8921 | if (DEBUG_WINDOW_TRACE) { |
Craig Mautner | 3255a28 | 2012-04-16 15:42:47 -0700 | [diff] [blame] | 8922 | Slog.v(TAG, "performLayoutAndPlaceSurfacesLockedInner: entry. Called by " |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 8923 | + Debug.getCallers(3)); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 8924 | } |
Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 8925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8926 | final long currentTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 8927 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8928 | int i; |
| 8929 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8930 | if (mFocusMayChange) { |
| 8931 | mFocusMayChange = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8932 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 8933 | false /*updateInputWindows*/); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8934 | } |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8936 | // Initialize state of exiting tokens. |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 8937 | final int numDisplays = mDisplayContents.size(); |
| 8938 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 8939 | final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx); |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 8940 | for (i=displayContent.mExitingTokens.size()-1; i>=0; i--) { |
| 8941 | displayContent.mExitingTokens.get(i).hasVisible = false; |
| 8942 | } |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 8943 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8944 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 8945 | for (int stackNdx = mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) { |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 8946 | // Initialize state of exiting applications. |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 8947 | final AppTokenList exitingAppTokens = |
| 8948 | mStackIdToStack.valueAt(stackNdx).mExitingAppTokens; |
| 8949 | for (int tokenNdx = exitingAppTokens.size() - 1; tokenNdx >= 0; --tokenNdx) { |
| 8950 | exitingAppTokens.get(tokenNdx).hasVisible = false; |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 8951 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8952 | } |
| 8953 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8954 | mInnerFields.mHoldScreen = null; |
| 8955 | mInnerFields.mScreenBrightness = -1; |
| 8956 | mInnerFields.mButtonBrightness = -1; |
Jeff Brown | 1e3b98d | 2012-09-30 18:58:59 -0700 | [diff] [blame] | 8957 | mInnerFields.mUserActivityTimeout = -1; |
Jeff Brown | 4fd7917 | 2013-11-07 17:58:15 -0800 | [diff] [blame] | 8958 | mInnerFields.mObscureApplicationContentOnSecondaryDisplays = false; |
Jeff Brown | 1e3b98d | 2012-09-30 18:58:59 -0700 | [diff] [blame] | 8959 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 8960 | mTransactionSequence++; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8961 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 8962 | final DisplayContent defaultDisplay = getDefaultDisplayContentLocked(); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8963 | final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo(); |
| 8964 | final int defaultDw = defaultInfo.logicalWidth; |
| 8965 | final int defaultDh = defaultInfo.logicalHeight; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8966 | |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 8967 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 8968 | ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 8969 | SurfaceControl.openTransaction(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8970 | try { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8971 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 8972 | if (mWatermark != null) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8973 | mWatermark.positionSurface(defaultDw, defaultDh); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 8974 | } |
| 8975 | if (mStrictModeFlash != null) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8976 | mStrictModeFlash.positionSurface(defaultDw, defaultDh); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 8977 | } |
| 8978 | |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 8979 | boolean focusDisplayed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8980 | |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 8981 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 8982 | final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx); |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 8983 | boolean updateAllDrawn = false; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8984 | WindowList windows = displayContent.getWindowList(); |
| 8985 | DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 8986 | final int displayId = displayContent.getDisplayId(); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8987 | final int dw = displayInfo.logicalWidth; |
| 8988 | final int dh = displayInfo.logicalHeight; |
| 8989 | final int innerDw = displayInfo.appWidth; |
| 8990 | final int innerDh = displayInfo.appHeight; |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 8991 | final boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8992 | |
Jeff Brown | 4fd7917 | 2013-11-07 17:58:15 -0800 | [diff] [blame] | 8993 | // Reset for each display. |
| 8994 | mInnerFields.mDisplayHasContent = false; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 8995 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8996 | int repeats = 0; |
| 8997 | do { |
| 8998 | repeats++; |
| 8999 | if (repeats > 6) { |
| 9000 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9001 | displayContent.layoutNeeded = false; |
| 9002 | break; |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 9003 | } |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 9004 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9005 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("On entry to LockedInner", |
| 9006 | displayContent.pendingLayoutChanges); |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 9007 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 9008 | if ((displayContent.pendingLayoutChanges & |
| 9009 | WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0 && |
| 9010 | (adjustWallpaperWindowsLocked() & |
| 9011 | ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9012 | assignLayersLocked(windows); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9013 | displayContent.layoutNeeded = true; |
| 9014 | } |
| 9015 | |
| 9016 | if (isDefaultDisplay && (displayContent.pendingLayoutChanges |
| 9017 | & WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9018 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 9019 | if (updateOrientationFromAppTokensLocked(true)) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9020 | displayContent.layoutNeeded = true; |
| 9021 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 9022 | } |
| 9023 | } |
| 9024 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9025 | if ((displayContent.pendingLayoutChanges |
| 9026 | & WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9027 | displayContent.layoutNeeded = true; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 9028 | } |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9029 | |
| 9030 | // FIRST LOOP: Perform a layout, if needed. |
| 9031 | if (repeats < 4) { |
| 9032 | performLayoutLockedInner(displayContent, repeats == 1, |
| 9033 | false /*updateInputWindows*/); |
| 9034 | } else { |
| 9035 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9036 | } |
| 9037 | |
| 9038 | // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think |
| 9039 | // it is animating. |
| 9040 | displayContent.pendingLayoutChanges = 0; |
| 9041 | |
| 9042 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("loop number " |
| 9043 | + mLayoutRepeatCount, displayContent.pendingLayoutChanges); |
| 9044 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 9045 | if (isDefaultDisplay) { |
| 9046 | mPolicy.beginPostLayoutPolicyLw(dw, dh); |
| 9047 | for (i = windows.size() - 1; i >= 0; i--) { |
| 9048 | WindowState w = windows.get(i); |
| 9049 | if (w.mHasSurface) { |
| 9050 | mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs); |
| 9051 | } |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 9052 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 9053 | displayContent.pendingLayoutChanges |= mPolicy.finishPostLayoutPolicyLw(); |
| 9054 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats( |
| 9055 | "after finishPostLayoutPolicyLw", displayContent.pendingLayoutChanges); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9056 | } |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9057 | } while (displayContent.pendingLayoutChanges != 0); |
| 9058 | |
| 9059 | mInnerFields.mObscured = false; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9060 | mInnerFields.mSyswin = false; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 9061 | displayContent.resetDimming(); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9062 | |
| 9063 | // Only used if default window |
| 9064 | final boolean someoneLosingFocus = !mLosingFocus.isEmpty(); |
| 9065 | |
| 9066 | final int N = windows.size(); |
| 9067 | for (i=N-1; i>=0; i--) { |
| 9068 | WindowState w = windows.get(i); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 9069 | final TaskStack stack = w.getStack(); |
| 9070 | if (stack == null) { |
| 9071 | continue; |
| 9072 | } |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9073 | |
| 9074 | final boolean obscuredChanged = w.mObscured != mInnerFields.mObscured; |
| 9075 | |
| 9076 | // Update effect. |
| 9077 | w.mObscured = mInnerFields.mObscured; |
| 9078 | if (!mInnerFields.mObscured) { |
| 9079 | handleNotObscuredLocked(w, currentTime, innerDw, innerDh); |
| 9080 | } |
| 9081 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 9082 | if (!stack.testDimmingTag()) { |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 9083 | handleFlagDimBehind(w); |
Craig Mautner | 312eac4 | 2012-11-13 10:56:22 -0800 | [diff] [blame] | 9084 | } |
| 9085 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9086 | if (isDefaultDisplay && obscuredChanged && (mWallpaperTarget == w) |
| 9087 | && w.isVisibleLw()) { |
| 9088 | // This is the wallpaper target and its obscured state |
| 9089 | // changed... make sure the current wallaper's visibility |
| 9090 | // has been updated accordingly. |
| 9091 | updateWallpaperVisibilityLocked(); |
| 9092 | } |
| 9093 | |
| 9094 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 9095 | |
| 9096 | // If the window has moved due to its containing |
| 9097 | // content frame changing, then we'd like to animate |
| 9098 | // it. |
| 9099 | if (w.mHasSurface && w.shouldAnimateMove()) { |
| 9100 | // Frame has moved, containing content frame |
| 9101 | // has also moved, and we're not currently animating... |
| 9102 | // let's do something. |
| 9103 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 9104 | com.android.internal.R.anim.window_move_from_decor); |
| 9105 | winAnimator.setAnimation(a); |
| 9106 | winAnimator.mAnimDw = w.mLastFrame.left - w.mFrame.left; |
| 9107 | winAnimator.mAnimDh = w.mLastFrame.top - w.mFrame.top; |
| 9108 | try { |
| 9109 | w.mClient.moved(w.mFrame.left, w.mFrame.top); |
| 9110 | } catch (RemoteException e) { |
| 9111 | } |
| 9112 | } |
| 9113 | |
| 9114 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
| 9115 | w.mContentChanged = false; |
| 9116 | |
| 9117 | // Moved from updateWindowsAndWallpaperLocked(). |
| 9118 | if (w.mHasSurface) { |
| 9119 | // Take care of the window being ready to display. |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 9120 | final boolean committed = |
| 9121 | winAnimator.commitFinishDrawingLocked(currentTime); |
| 9122 | if (isDefaultDisplay && committed) { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 9123 | if (w.mAttrs.type == TYPE_DREAM) { |
| 9124 | // HACK: When a dream is shown, it may at that |
| 9125 | // point hide the lock screen. So we need to |
| 9126 | // redo the layout to let the phone window manager |
| 9127 | // make this happen. |
| 9128 | displayContent.pendingLayoutChanges |= |
| 9129 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | 11462cc | 2013-05-13 15:56:18 -0700 | [diff] [blame] | 9130 | if (DEBUG_LAYOUT_REPEATS) { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 9131 | debugLayoutRepeats( |
| 9132 | "dream and commitFinishDrawingLocked true", |
| 9133 | displayContent.pendingLayoutChanges); |
| 9134 | } |
| 9135 | } |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 9136 | if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 9137 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9138 | "First draw done in potential wallpaper target " + w); |
| 9139 | mInnerFields.mWallpaperMayChange = true; |
| 9140 | displayContent.pendingLayoutChanges |= |
| 9141 | WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Craig Mautner | 11462cc | 2013-05-13 15:56:18 -0700 | [diff] [blame] | 9142 | if (DEBUG_LAYOUT_REPEATS) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9143 | debugLayoutRepeats( |
| 9144 | "wallpaper and commitFinishDrawingLocked true", |
| 9145 | displayContent.pendingLayoutChanges); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 9146 | } |
| 9147 | } |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9148 | } |
| 9149 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9150 | winAnimator.setSurfaceBoundariesLocked(recoveringMemory); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9151 | |
| 9152 | final AppWindowToken atoken = w.mAppToken; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 9153 | if (DEBUG_STARTING_WINDOW && atoken != null |
| 9154 | && w == atoken.startingWindow) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9155 | Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" |
| 9156 | + w.isOnScreen() + " allDrawn=" + atoken.allDrawn |
| 9157 | + " freezingScreen=" + atoken.mAppAnimator.freezingScreen); |
| 9158 | } |
| 9159 | if (atoken != null |
| 9160 | && (!atoken.allDrawn || atoken.mAppAnimator.freezingScreen)) { |
| 9161 | if (atoken.lastTransactionSequence != mTransactionSequence) { |
| 9162 | atoken.lastTransactionSequence = mTransactionSequence; |
| 9163 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9164 | atoken.startingDisplayed = false; |
| 9165 | } |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 9166 | if ((w.isOnScreen() || winAnimator.mAttrType == TYPE_BASE_APPLICATION) |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9167 | && !w.mExiting && !w.mDestroying) { |
Craig Mautner | 11462cc | 2013-05-13 15:56:18 -0700 | [diff] [blame] | 9168 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9169 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw() |
| 9170 | + ", isAnimating=" + winAnimator.isAnimating()); |
| 9171 | if (!w.isDrawnLw()) { |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 9172 | Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceControl |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9173 | + " pv=" + w.mPolicyVisibility |
| 9174 | + " mDrawState=" + winAnimator.mDrawState |
| 9175 | + " ah=" + w.mAttachedHidden |
| 9176 | + " th=" + atoken.hiddenRequested |
| 9177 | + " a=" + winAnimator.mAnimating); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 9178 | } |
| 9179 | } |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9180 | if (w != atoken.startingWindow) { |
| 9181 | if (!atoken.mAppAnimator.freezingScreen || !w.mAppFreezing) { |
| 9182 | atoken.numInterestingWindows++; |
| 9183 | if (w.isDrawnLw()) { |
| 9184 | atoken.numDrawnWindows++; |
Craig Mautner | 11462cc | 2013-05-13 15:56:18 -0700 | [diff] [blame] | 9185 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9186 | "tokenMayBeDrawn: " + atoken |
| 9187 | + " freezingScreen=" + atoken.mAppAnimator.freezingScreen |
| 9188 | + " mAppFreezing=" + w.mAppFreezing); |
| 9189 | updateAllDrawn = true; |
| 9190 | } |
| 9191 | } |
| 9192 | } else if (w.isDrawnLw()) { |
| 9193 | atoken.startingDisplayed = true; |
| 9194 | } |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 9195 | } |
| 9196 | } |
| 9197 | } |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 9198 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9199 | if (isDefaultDisplay && someoneLosingFocus && (w == mCurrentFocus) |
| 9200 | && w.isDisplayedLw()) { |
| 9201 | focusDisplayed = true; |
| 9202 | } |
Craig Mautner | 51bb12b | 2012-04-27 14:39:53 -0700 | [diff] [blame] | 9203 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9204 | updateResizingWindows(w); |
| 9205 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9206 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 9207 | mDisplayManagerInternal.setDisplayHasContent(displayId, |
Jeff Brown | 4fd7917 | 2013-11-07 17:58:15 -0800 | [diff] [blame] | 9208 | mInnerFields.mDisplayHasContent, |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 9209 | true /* inTraversal, must call performTraversalInTrans... below */); |
| 9210 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 9211 | getDisplayContentLocked(displayId).stopDimmingIfNeeded(); |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 9212 | |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 9213 | if (updateAllDrawn) { |
| 9214 | updateAllDrawnLocked(displayContent); |
| 9215 | } |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 9216 | } |
| 9217 | |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 9218 | if (focusDisplayed) { |
| 9219 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 9220 | } |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 9221 | |
| 9222 | // Give the display manager a chance to adjust properties |
| 9223 | // like display rotation if it needs to. |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 9224 | mDisplayManagerInternal.performTraversalInTransactionFromWindowManager(); |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame] | 9225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9226 | } catch (RuntimeException e) { |
Dianne Hackborn | 8962028 | 2011-09-11 12:47:45 -0700 | [diff] [blame] | 9227 | Log.wtf(TAG, "Unhandled exception in Window Manager", e); |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 9228 | } finally { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 9229 | SurfaceControl.closeTransaction(); |
Chet Haase | d5d11af | 2012-10-31 08:57:17 -0700 | [diff] [blame] | 9230 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 9231 | "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9232 | } |
| 9233 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9234 | final WindowList defaultWindows = defaultDisplay.getWindowList(); |
| 9235 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9236 | // If we are ready to perform an app transition, check through |
| 9237 | // all of the app tokens to be shown and see if they are ready |
| 9238 | // to go. |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 9239 | if (mAppTransition.isReady()) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9240 | defaultDisplay.pendingLayoutChanges |= handleAppTransitionReadyLocked(defaultWindows); |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 9241 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after handleAppTransitionReadyLocked", |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 9242 | defaultDisplay.pendingLayoutChanges); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9243 | } |
| 9244 | |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 9245 | if (!mAnimator.mAnimating && mAppTransition.isRunning()) { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9246 | // We have finished the animation of an app transition. To do |
| 9247 | // this, we have delayed a lot of operations like showing and |
| 9248 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9249 | // reflects the correct Z-order, but the window list may now |
| 9250 | // be out of sync with it. So here we will just rebuild the |
| 9251 | // entire app window list. Fun! |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9252 | defaultDisplay.pendingLayoutChanges |= handleAnimatingStoppedAndTransitionLocked(); |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 9253 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after handleAnimStopAndXitionLock", |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9254 | defaultDisplay.pendingLayoutChanges); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9255 | } |
| 9256 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9257 | if (mInnerFields.mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0 |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 9258 | && !mAppTransition.isReady()) { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9259 | // At this point, there was a window with a wallpaper that |
| 9260 | // was force hiding other windows behind it, but now it |
| 9261 | // is going away. This may be simple -- just animate |
| 9262 | // away the wallpaper and its window -- or it may be |
| 9263 | // hard -- the wallpaper now needs to be shown behind |
| 9264 | // something that was hidden. |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 9265 | defaultDisplay.pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 9266 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after animateAwayWallpaperLocked", |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9267 | defaultDisplay.pendingLayoutChanges); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9268 | } |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 9269 | mInnerFields.mWallpaperForceHidingChanged = false; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9270 | |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 9271 | if (mInnerFields.mWallpaperMayChange) { |
Craig Mautner | 11462cc | 2013-05-13 15:56:18 -0700 | [diff] [blame] | 9272 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change! Adjusting"); |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 9273 | defaultDisplay.pendingLayoutChanges |= |
| 9274 | WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
| 9275 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("WallpaperMayChange", |
| 9276 | defaultDisplay.pendingLayoutChanges); |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 9277 | } |
| 9278 | |
| 9279 | if (mFocusMayChange) { |
| 9280 | mFocusMayChange = false; |
| 9281 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 9282 | false /*updateInputWindows*/)) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9283 | defaultDisplay.pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 9284 | } |
| 9285 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9286 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 9287 | if (needsLayout()) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9288 | defaultDisplay.pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
| 9289 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("mLayoutNeeded", |
| 9290 | defaultDisplay.pendingLayoutChanges); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9291 | } |
| 9292 | |
Craig Mautner | ade0a9a | 2012-10-06 13:55:07 -0700 | [diff] [blame] | 9293 | for (i = mResizingWindows.size() - 1; i >= 0; i--) { |
| 9294 | WindowState win = mResizingWindows.get(i); |
| 9295 | if (win.mAppFreezing) { |
| 9296 | // Don't remove this window until rotation has completed. |
| 9297 | continue; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 9298 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 9299 | win.reportResized(); |
Craig Mautner | ade0a9a | 2012-10-06 13:55:07 -0700 | [diff] [blame] | 9300 | mResizingWindows.remove(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9301 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9302 | |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 9303 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| 9304 | "With display frozen, orientationChangeComplete=" |
| 9305 | + mInnerFields.mOrientationChangeComplete); |
| 9306 | if (mInnerFields.mOrientationChangeComplete) { |
| 9307 | if (mWindowsFreezingScreen) { |
| 9308 | mWindowsFreezingScreen = false; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 9309 | mLastFinishedFreezeSource = mInnerFields.mLastWindowFreezeSource; |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 9310 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9311 | } |
| 9312 | stopFreezingDisplayLocked(); |
| 9313 | } |
| 9314 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9315 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9316 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9317 | i = mDestroySurface.size(); |
| 9318 | if (i > 0) { |
| 9319 | do { |
| 9320 | i--; |
| 9321 | WindowState win = mDestroySurface.get(i); |
| 9322 | win.mDestroying = false; |
| 9323 | if (mInputMethodWindow == win) { |
| 9324 | mInputMethodWindow = null; |
| 9325 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9326 | if (win == mWallpaperTarget) { |
| 9327 | wallpaperDestroyed = true; |
| 9328 | } |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 9329 | win.mWinAnimator.destroySurfaceLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9330 | } while (i > 0); |
| 9331 | mDestroySurface.clear(); |
| 9332 | } |
| 9333 | |
| 9334 | // Time to remove any exiting tokens? |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 9335 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 9336 | final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx); |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 9337 | ArrayList<WindowToken> exitingTokens = displayContent.mExitingTokens; |
| 9338 | for (i = exitingTokens.size() - 1; i >= 0; i--) { |
| 9339 | WindowToken token = exitingTokens.get(i); |
| 9340 | if (!token.hasVisible) { |
| 9341 | exitingTokens.remove(i); |
| 9342 | if (token.windowType == TYPE_WALLPAPER) { |
| 9343 | mWallpaperTokens.remove(token); |
| 9344 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 9345 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9346 | } |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 9347 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9348 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 9349 | // Time to remove any exiting applications? |
| 9350 | for (int stackNdx = mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) { |
| 9351 | // Initialize state of exiting applications. |
| 9352 | final AppTokenList exitingAppTokens = |
| 9353 | mStackIdToStack.valueAt(stackNdx).mExitingAppTokens; |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 9354 | for (i = exitingAppTokens.size() - 1; i >= 0; i--) { |
| 9355 | AppWindowToken token = exitingAppTokens.get(i); |
Craig Mautner | 81481fc | 2014-03-18 14:26:36 -0700 | [diff] [blame] | 9356 | if (!token.hasVisible && !mClosingApps.contains(token) && !token.mDeferRemoval) { |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 9357 | // Make sure there is no animation running on this token, |
| 9358 | // so any windows associated with it will be removed as |
| 9359 | // soon as their animations are complete |
| 9360 | token.mAppAnimator.clearAnimation(); |
| 9361 | token.mAppAnimator.animating = false; |
| 9362 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 9363 | "performLayout: App token exiting now removed" + token); |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 9364 | removeAppFromTaskLocked(token); |
Craig Mautner | b1fd65c | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 9365 | exitingAppTokens.remove(i); |
| 9366 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9367 | } |
| 9368 | } |
| 9369 | |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 9370 | if (!mAnimator.mAnimating && mRelayoutWhileAnimating.size() > 0) { |
| 9371 | for (int j=mRelayoutWhileAnimating.size()-1; j>=0; j--) { |
| 9372 | try { |
| 9373 | mRelayoutWhileAnimating.get(j).mClient.doneAnimating(); |
| 9374 | } catch (RemoteException e) { |
| 9375 | } |
| 9376 | } |
| 9377 | mRelayoutWhileAnimating.clear(); |
| 9378 | } |
| 9379 | |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 9380 | if (wallpaperDestroyed) { |
| 9381 | defaultDisplay.pendingLayoutChanges |= |
| 9382 | WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
| 9383 | defaultDisplay.layoutNeeded = true; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9384 | } |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9385 | |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 9386 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 9387 | final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9388 | if (displayContent.pendingLayoutChanges != 0) { |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 9389 | displayContent.layoutNeeded = true; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9390 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9391 | } |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 9392 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9393 | // Finally update all input windows now that the window changes have stabilized. |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 9394 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 9395 | |
Craig Mautner | 259328c | 2012-08-21 19:30:58 -0700 | [diff] [blame] | 9396 | setHoldScreenLocked(mInnerFields.mHoldScreen); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 9397 | if (!mDisplayFrozen) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 9398 | if (mInnerFields.mScreenBrightness < 0 || mInnerFields.mScreenBrightness > 1.0f) { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 9399 | mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(-1); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 9400 | } else { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 9401 | mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager( |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 9402 | toBrightnessOverride(mInnerFields.mScreenBrightness)); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 9403 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 9404 | if (mInnerFields.mButtonBrightness < 0 || mInnerFields.mButtonBrightness > 1.0f) { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 9405 | mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(-1); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 9406 | } else { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 9407 | mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager( |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 9408 | toBrightnessOverride(mInnerFields.mButtonBrightness)); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 9409 | } |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 9410 | mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager( |
Jeff Brown | 1e3b98d | 2012-09-30 18:58:59 -0700 | [diff] [blame] | 9411 | mInnerFields.mUserActivityTimeout); |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9412 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9413 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9414 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9415 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 9416 | mPowerManager.wakeUp(SystemClock.uptimeMillis()); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9417 | mTurnOnScreen = false; |
| 9418 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 9419 | |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 9420 | if (mInnerFields.mUpdateRotation) { |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9421 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 9422 | if (updateRotationUncheckedLocked(false)) { |
Dianne Hackborn | 3e4f9d0 | 2011-02-04 14:05:55 -0800 | [diff] [blame] | 9423 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 9424 | } else { |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 9425 | mInnerFields.mUpdateRotation = false; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9426 | } |
| 9427 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 9428 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 9429 | if (mInnerFields.mOrientationChangeComplete && !defaultDisplay.layoutNeeded |
| 9430 | && !mInnerFields.mUpdateRotation) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 9431 | checkDrawnWindowsLocked(); |
| 9432 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 9433 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9434 | final int N = mPendingRemove.size(); |
| 9435 | if (N > 0) { |
| 9436 | if (mPendingRemoveTmp.length < N) { |
| 9437 | mPendingRemoveTmp = new WindowState[N+10]; |
| 9438 | } |
| 9439 | mPendingRemove.toArray(mPendingRemoveTmp); |
| 9440 | mPendingRemove.clear(); |
| 9441 | DisplayContentList displayList = new DisplayContentList(); |
| 9442 | for (i = 0; i < N; i++) { |
| 9443 | WindowState w = mPendingRemoveTmp[i]; |
| 9444 | removeWindowInnerLocked(w.mSession, w); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 9445 | final DisplayContent displayContent = w.getDisplayContent(); |
| 9446 | if (displayContent != null && !displayList.contains(displayContent)) { |
| 9447 | displayList.add(displayContent); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9448 | } |
| 9449 | } |
| 9450 | |
| 9451 | for (DisplayContent displayContent : displayList) { |
| 9452 | assignLayersLocked(displayContent.getWindowList()); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 9453 | displayContent.layoutNeeded = true; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9454 | } |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9455 | } |
| 9456 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 9457 | // Remove all deferred displays stacks, tasks, and activities. |
| 9458 | for (int displayNdx = mDisplayContents.size() - 1; displayNdx >= 0; --displayNdx) { |
| 9459 | mDisplayContents.valueAt(displayNdx).checkForDeferredActions(); |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 9460 | } |
| 9461 | |
Craig Mautner | f766646 | 2013-04-28 08:58:21 -0700 | [diff] [blame] | 9462 | setFocusedStackFrame(); |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 9463 | |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 9464 | // Check to see if we are now in a state where the screen should |
| 9465 | // be enabled, because the window obscured flags have changed. |
| 9466 | enableScreenIfNeededLocked(); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9467 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 9468 | scheduleAnimationLocked(); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9469 | |
| 9470 | if (DEBUG_WINDOW_TRACE) { |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 9471 | Slog.e(TAG, "performLayoutAndPlaceSurfacesLockedInner exit: animating=" |
| 9472 | + mAnimator.mAnimating); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9473 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9474 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 9475 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 9476 | private int toBrightnessOverride(float value) { |
| 9477 | return (int)(value * PowerManager.BRIGHTNESS_ON); |
| 9478 | } |
| 9479 | |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 9480 | void checkDrawnWindowsLocked() { |
| 9481 | if (mWaitingForDrawn.size() > 0) { |
| 9482 | for (int j=mWaitingForDrawn.size()-1; j>=0; j--) { |
| 9483 | Pair<WindowState, IRemoteCallback> pair = mWaitingForDrawn.get(j); |
| 9484 | WindowState win = pair.first; |
| 9485 | //Slog.i(TAG, "Waiting for drawn " + win + ": removed=" |
| 9486 | // + win.mRemoved + " visible=" + win.isVisibleLw() |
| 9487 | // + " shown=" + win.mSurfaceShown); |
Craig Mautner | 4e8a19c | 2013-10-08 17:26:08 -0700 | [diff] [blame] | 9488 | if (win.mRemoved) { |
| 9489 | // Window has been removed; no draw will now happen, so stop waiting. |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 9490 | Slog.w(TAG, "Aborted waiting for drawn: " + pair.first); |
| 9491 | try { |
| 9492 | pair.second.sendResult(null); |
| 9493 | } catch (RemoteException e) { |
| 9494 | } |
| 9495 | mWaitingForDrawn.remove(pair); |
| 9496 | mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT, pair); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9497 | } else if (win.mWinAnimator.mSurfaceShown) { |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 9498 | // Window is now drawn (and shown). |
| 9499 | try { |
| 9500 | pair.second.sendResult(null); |
| 9501 | } catch (RemoteException e) { |
| 9502 | } |
| 9503 | mWaitingForDrawn.remove(pair); |
| 9504 | mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT, pair); |
| 9505 | } |
| 9506 | } |
| 9507 | } |
| 9508 | } |
| 9509 | |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 9510 | @Override |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 9511 | public boolean waitForWindowDrawn(IBinder token, IRemoteCallback callback) { |
| 9512 | if (token != null && callback != null) { |
| 9513 | synchronized (mWindowMap) { |
| 9514 | WindowState win = windowForClientLocked(null, token, true); |
| 9515 | if (win != null) { |
| 9516 | Pair<WindowState, IRemoteCallback> pair = |
| 9517 | new Pair<WindowState, IRemoteCallback>(win, callback); |
| 9518 | Message m = mH.obtainMessage(H.WAITING_FOR_DRAWN_TIMEOUT, pair); |
| 9519 | mH.sendMessageDelayed(m, 2000); |
| 9520 | mWaitingForDrawn.add(pair); |
| 9521 | checkDrawnWindowsLocked(); |
| 9522 | return true; |
| 9523 | } |
Craig Mautner | 4e8a19c | 2013-10-08 17:26:08 -0700 | [diff] [blame] | 9524 | Slog.i(TAG, "waitForWindowDrawn: win null"); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 9525 | } |
| 9526 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 9527 | return false; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 9528 | } |
| 9529 | |
Craig Mautner | 259328c | 2012-08-21 19:30:58 -0700 | [diff] [blame] | 9530 | void setHoldScreenLocked(final Session newHoldScreen) { |
| 9531 | final boolean hold = newHoldScreen != null; |
| 9532 | |
| 9533 | if (hold && mHoldingScreenOn != newHoldScreen) { |
| 9534 | mHoldingScreenWakeLock.setWorkSource(new WorkSource(newHoldScreen.mUid)); |
| 9535 | } |
| 9536 | mHoldingScreenOn = newHoldScreen; |
| 9537 | |
| 9538 | final boolean state = mHoldingScreenWakeLock.isHeld(); |
| 9539 | if (hold != state) { |
| 9540 | if (hold) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9541 | mHoldingScreenWakeLock.acquire(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 9542 | mPolicy.keepScreenOnStartedLw(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9543 | } else { |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 9544 | mPolicy.keepScreenOnStoppedLw(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9545 | mHoldingScreenWakeLock.release(); |
| 9546 | } |
| 9547 | } |
| 9548 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9549 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 9550 | void requestTraversal() { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 9551 | synchronized (mWindowMap) { |
| 9552 | requestTraversalLocked(); |
| 9553 | } |
| 9554 | } |
| 9555 | |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 9556 | void requestTraversalLocked() { |
| 9557 | if (!mTraversalScheduled) { |
| 9558 | mTraversalScheduled = true; |
| 9559 | mH.sendEmptyMessage(H.DO_TRAVERSAL); |
| 9560 | } |
| 9561 | } |
| 9562 | |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 9563 | /** Note that Locked in this case is on mLayoutToAnim */ |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 9564 | void scheduleAnimationLocked() { |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 9565 | if (!mAnimationScheduled) { |
| 9566 | mAnimationScheduled = true; |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 9567 | mChoreographer.postCallback( |
| 9568 | Choreographer.CALLBACK_ANIMATION, mAnimator.mAnimationRunnable, null); |
| 9569 | } |
| 9570 | } |
| 9571 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 9572 | private boolean needsLayout() { |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 9573 | final int numDisplays = mDisplayContents.size(); |
| 9574 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 9575 | final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx); |
| 9576 | if (displayContent.layoutNeeded) { |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 9577 | return true; |
| 9578 | } |
| 9579 | } |
| 9580 | return false; |
| 9581 | } |
| 9582 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 9583 | boolean copyAnimToLayoutParamsLocked() { |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 9584 | boolean doRequest = false; |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 9585 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 9586 | final int bulkUpdateParams = mAnimator.mBulkUpdateParams; |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 9587 | if ((bulkUpdateParams & LayoutFields.SET_UPDATE_ROTATION) != 0) { |
| 9588 | mInnerFields.mUpdateRotation = true; |
| 9589 | doRequest = true; |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 9590 | } |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 9591 | if ((bulkUpdateParams & LayoutFields.SET_WALLPAPER_MAY_CHANGE) != 0) { |
| 9592 | mInnerFields.mWallpaperMayChange = true; |
| 9593 | doRequest = true; |
| 9594 | } |
| 9595 | if ((bulkUpdateParams & LayoutFields.SET_FORCE_HIDING_CHANGED) != 0) { |
| 9596 | mInnerFields.mWallpaperForceHidingChanged = true; |
| 9597 | doRequest = true; |
| 9598 | } |
| 9599 | if ((bulkUpdateParams & LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE) == 0) { |
| 9600 | mInnerFields.mOrientationChangeComplete = false; |
| 9601 | } else { |
| 9602 | mInnerFields.mOrientationChangeComplete = true; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 9603 | mInnerFields.mLastWindowFreezeSource = mAnimator.mLastWindowFreezeSource; |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 9604 | if (mWindowsFreezingScreen) { |
| 9605 | doRequest = true; |
| 9606 | } |
| 9607 | } |
| 9608 | if ((bulkUpdateParams & LayoutFields.SET_TURN_ON_SCREEN) != 0) { |
| 9609 | mTurnOnScreen = true; |
| 9610 | } |
| 9611 | if ((bulkUpdateParams & LayoutFields.SET_WALLPAPER_ACTION_PENDING) != 0) { |
| 9612 | mInnerFields.mWallpaperActionPending = true; |
| 9613 | } |
| 9614 | |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 9615 | return doRequest; |
| 9616 | } |
| 9617 | |
Craig Mautner | 6201c2a | 2013-08-09 18:48:48 -0700 | [diff] [blame] | 9618 | /** If a window that has an animation specifying a colored background and the current wallpaper |
| 9619 | * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 9620 | * suddenly disappear. */ |
| 9621 | int adjustAnimationBackground(WindowStateAnimator winAnimator) { |
Craig Mautner | 6201c2a | 2013-08-09 18:48:48 -0700 | [diff] [blame] | 9622 | WindowList windows = winAnimator.mWin.getWindowList(); |
| 9623 | for (int i = windows.size() - 1; i >= 0; --i) { |
| 9624 | WindowState testWin = windows.get(i); |
| 9625 | if (testWin.mIsWallpaper && testWin.isVisibleNow()) { |
| 9626 | return testWin.mWinAnimator.mAnimLayer; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 9627 | } |
| 9628 | } |
| 9629 | return winAnimator.mAnimLayer; |
| 9630 | } |
| 9631 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9632 | boolean reclaimSomeSurfaceMemoryLocked(WindowStateAnimator winAnimator, String operation, |
| 9633 | boolean secure) { |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 9634 | final SurfaceControl surface = winAnimator.mSurfaceControl; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 9635 | boolean leakedSurface = false; |
| 9636 | boolean killedApps = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9637 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9638 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(), |
| 9639 | winAnimator.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9640 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9641 | if (mForceRemoves == null) { |
| 9642 | mForceRemoves = new ArrayList<WindowState>(); |
| 9643 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9644 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9645 | long callingIdentity = Binder.clearCallingIdentity(); |
| 9646 | try { |
| 9647 | // There was some problem... first, do a sanity check of the |
| 9648 | // window list to make sure we haven't left any dangling surfaces |
| 9649 | // around. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9650 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9651 | Slog.i(TAG, "Out of memory for surface! Looking for leaks..."); |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 9652 | final int numDisplays = mDisplayContents.size(); |
| 9653 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 9654 | final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList(); |
| 9655 | final int numWindows = windows.size(); |
| 9656 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 9657 | final WindowState ws = windows.get(winNdx); |
| 9658 | WindowStateAnimator wsa = ws.mWinAnimator; |
| 9659 | if (wsa.mSurfaceControl != null) { |
| 9660 | if (!mSessions.contains(wsa.mSession)) { |
| 9661 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| 9662 | + ws + " surface=" + wsa.mSurfaceControl |
| 9663 | + " token=" + ws.mToken |
| 9664 | + " pid=" + ws.mSession.mPid |
| 9665 | + " uid=" + ws.mSession.mUid); |
| 9666 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
| 9667 | wsa.mSurfaceControl.destroy(); |
| 9668 | wsa.mSurfaceShown = false; |
| 9669 | wsa.mSurfaceControl = null; |
| 9670 | ws.mHasSurface = false; |
| 9671 | mForceRemoves.add(ws); |
| 9672 | leakedSurface = true; |
| 9673 | } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) { |
| 9674 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
| 9675 | + ws + " surface=" + wsa.mSurfaceControl |
| 9676 | + " token=" + ws.mAppToken); |
| 9677 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
| 9678 | wsa.mSurfaceControl.destroy(); |
| 9679 | wsa.mSurfaceShown = false; |
| 9680 | wsa.mSurfaceControl = null; |
| 9681 | ws.mHasSurface = false; |
| 9682 | leakedSurface = true; |
| 9683 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9684 | } |
| 9685 | } |
| 9686 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9687 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9688 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9689 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9690 | SparseIntArray pidCandidates = new SparseIntArray(); |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 9691 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 9692 | final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList(); |
| 9693 | final int numWindows = windows.size(); |
| 9694 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 9695 | final WindowState ws = windows.get(winNdx); |
| 9696 | if (mForceRemoves.contains(ws)) { |
| 9697 | continue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9698 | } |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 9699 | WindowStateAnimator wsa = ws.mWinAnimator; |
| 9700 | if (wsa.mSurfaceControl != null) { |
| 9701 | pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid); |
| 9702 | } |
| 9703 | } |
| 9704 | if (pidCandidates.size() > 0) { |
| 9705 | int[] pids = new int[pidCandidates.size()]; |
| 9706 | for (int i=0; i<pids.length; i++) { |
| 9707 | pids[i] = pidCandidates.keyAt(i); |
| 9708 | } |
| 9709 | try { |
| 9710 | if (mActivityManager.killPids(pids, "Free memory", secure)) { |
| 9711 | killedApps = true; |
| 9712 | } |
| 9713 | } catch (RemoteException e) { |
| 9714 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9715 | } |
| 9716 | } |
| 9717 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9718 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9719 | if (leakedSurface || killedApps) { |
| 9720 | // We managed to reclaim some memory, so get rid of the trouble |
| 9721 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9722 | 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] | 9723 | if (surface != null) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9724 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin, |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 9725 | "RECOVER DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9726 | surface.destroy(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9727 | winAnimator.mSurfaceShown = false; |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 9728 | winAnimator.mSurfaceControl = null; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 9729 | winAnimator.mWin.mHasSurface = false; |
Craig Mautner | 68cc241 | 2013-10-01 10:39:43 -0700 | [diff] [blame] | 9730 | scheduleRemoveStartingWindow(winAnimator.mWin.mAppToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9731 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9733 | try { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9734 | winAnimator.mWin.mClient.dispatchGetNewSurface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9735 | } catch (RemoteException e) { |
| 9736 | } |
| 9737 | } |
| 9738 | } finally { |
| 9739 | Binder.restoreCallingIdentity(callingIdentity); |
| 9740 | } |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 9741 | |
| 9742 | return leakedSurface || killedApps; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9743 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9744 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9745 | private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9746 | WindowState newFocus = computeFocusedWindowLocked(); |
| 9747 | if (mCurrentFocus != newFocus) { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 9748 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmUpdateFocus"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9749 | // This check makes sure that we don't already have the focus |
| 9750 | // change message pending. |
| 9751 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 9752 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Satoshi Kataoka | 02679f6 | 2013-05-20 16:13:44 +0900 | [diff] [blame] | 9753 | // TODO(multidisplay): Focused windows on default display only. |
| 9754 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
| 9755 | final boolean imWindowChanged = moveInputMethodWindowsIfNeededLocked( |
| 9756 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS |
| 9757 | && mode != UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 9758 | if (imWindowChanged) { |
| 9759 | displayContent.layoutNeeded = true; |
| 9760 | newFocus = computeFocusedWindowLocked(); |
| 9761 | } |
| 9762 | |
Craig Mautner | a7f2bd4 | 2013-10-15 16:13:50 -0700 | [diff] [blame] | 9763 | if (DEBUG_FOCUS_LIGHT || localLOGV) Slog.v(TAG, "Changing focus from " + |
Craig Mautner | b3370ce | 2013-09-19 12:02:09 -0700 | [diff] [blame] | 9764 | mCurrentFocus + " to " + newFocus + " Callers=" + Debug.getCallers(4)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9765 | final WindowState oldFocus = mCurrentFocus; |
| 9766 | mCurrentFocus = newFocus; |
| 9767 | mLosingFocus.remove(newFocus); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 9768 | |
| 9769 | if (mAccessibilityController != null) { |
| 9770 | mAccessibilityController.onWindowFocusChangedLocked(); |
| 9771 | } |
| 9772 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9773 | int focusChanged = mPolicy.focusChangedLw(oldFocus, newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9774 | |
Satoshi Kataoka | 12afe14 | 2013-05-21 06:19:27 +0900 | [diff] [blame] | 9775 | if (imWindowChanged && oldFocus != mInputMethodWindow) { |
Satoshi Kataoka | 02679f6 | 2013-05-20 16:13:44 +0900 | [diff] [blame] | 9776 | // Focus of the input method window changed. Perform layout if needed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9777 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9778 | performLayoutLockedInner(displayContent, true /*initial*/, updateInputWindows); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9779 | focusChanged &= ~WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9780 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 9781 | // Client will do the layout, but we need to assign layers |
| 9782 | // for handleNewWindowLocked() below. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9783 | assignLayersLocked(displayContent.getWindowList()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9784 | } |
| 9785 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9786 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 9787 | if ((focusChanged & WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9788 | // The change in focus caused us to need to do a layout. Okay. |
Jeff Brown | 2033763 | 2012-09-24 14:25:54 -0700 | [diff] [blame] | 9789 | displayContent.layoutNeeded = true; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9790 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9791 | performLayoutLockedInner(displayContent, true /*initial*/, updateInputWindows); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9792 | } |
| 9793 | } |
| 9794 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9795 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 9796 | // If we defer assigning layers, then the caller is responsible for |
| 9797 | // doing this part. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9798 | finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9799 | } |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 9800 | |
| 9801 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9802 | return true; |
| 9803 | } |
| 9804 | return false; |
| 9805 | } |
Craig Mautner | 66f78d7 | 2012-12-04 16:46:50 -0800 | [diff] [blame] | 9806 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9807 | private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) { |
| 9808 | mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9809 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9810 | |
| 9811 | private WindowState computeFocusedWindowLocked() { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 9812 | if (mAnimator.mUniverseBackground != null |
| 9813 | && mAnimator.mUniverseBackground.mWin.canReceiveKeys()) { |
| 9814 | return mAnimator.mUniverseBackground.mWin; |
| 9815 | } |
| 9816 | |
Jeff Brown | 2033763 | 2012-09-24 14:25:54 -0700 | [diff] [blame] | 9817 | final int displayCount = mDisplayContents.size(); |
| 9818 | for (int i = 0; i < displayCount; i++) { |
| 9819 | final DisplayContent displayContent = mDisplayContents.valueAt(i); |
| 9820 | WindowState win = findFocusedWindowLocked(displayContent); |
| 9821 | if (win != null) { |
| 9822 | return win; |
| 9823 | } |
| 9824 | } |
| 9825 | return null; |
| 9826 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9827 | |
Jeff Brown | 2033763 | 2012-09-24 14:25:54 -0700 | [diff] [blame] | 9828 | private WindowState findFocusedWindowLocked(DisplayContent displayContent) { |
Jeff Brown | 2033763 | 2012-09-24 14:25:54 -0700 | [diff] [blame] | 9829 | final WindowList windows = displayContent.getWindowList(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9830 | for (int i = windows.size() - 1; i >= 0; i--) { |
Jeff Brown | 2033763 | 2012-09-24 14:25:54 -0700 | [diff] [blame] | 9831 | final WindowState win = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9832 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9833 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9834 | TAG, "Looking for focus: " + i |
| 9835 | + " = " + win |
| 9836 | + ", flags=" + win.mAttrs.flags |
| 9837 | + ", canReceive=" + win.canReceiveKeys()); |
| 9838 | |
Craig Mautner | ac56514 | 2013-09-23 17:37:09 -0700 | [diff] [blame] | 9839 | AppWindowToken wtoken = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9840 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9841 | // If this window's application has been removed, just skip it. |
Craig Mautner | ac56514 | 2013-09-23 17:37:09 -0700 | [diff] [blame] | 9842 | if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) { |
| 9843 | if (DEBUG_FOCUS) Slog.v(TAG, "Skipping " + wtoken + " because " |
| 9844 | + (wtoken.removed ? "removed" : "sendingToBottom")); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9845 | continue; |
| 9846 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9847 | |
Craig Mautner | ac56514 | 2013-09-23 17:37:09 -0700 | [diff] [blame] | 9848 | if (!win.canReceiveKeys()) { |
| 9849 | continue; |
| 9850 | } |
| 9851 | |
| 9852 | // Descend through all of the app tokens and find the first that either matches |
| 9853 | // win.mAppToken (return win) or mFocusedApp (return null). |
| 9854 | if (wtoken != null && win.mAttrs.type != TYPE_APPLICATION_STARTING && |
| 9855 | mFocusedApp != null) { |
| 9856 | ArrayList<Task> tasks = displayContent.getTasks(); |
| 9857 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 9858 | AppTokenList tokens = tasks.get(taskNdx).mAppTokens; |
| 9859 | int tokenNdx = tokens.size() - 1; |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 9860 | for ( ; tokenNdx >= 0; --tokenNdx) { |
Craig Mautner | ac56514 | 2013-09-23 17:37:09 -0700 | [diff] [blame] | 9861 | final AppWindowToken token = tokens.get(tokenNdx); |
| 9862 | if (wtoken == token) { |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 9863 | break; |
| 9864 | } |
Craig Mautner | ac56514 | 2013-09-23 17:37:09 -0700 | [diff] [blame] | 9865 | if (mFocusedApp == token) { |
| 9866 | // Whoops, we are below the focused app... no focus for you! |
| 9867 | if (localLOGV || DEBUG_FOCUS_LIGHT) Slog.v(TAG, |
| 9868 | "findFocusedWindow: Reached focused app=" + mFocusedApp); |
| 9869 | return null; |
| 9870 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9871 | } |
Craig Mautner | ac56514 | 2013-09-23 17:37:09 -0700 | [diff] [blame] | 9872 | if (tokenNdx >= 0) { |
| 9873 | // Early exit from loop, must have found the matching token. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9874 | break; |
| 9875 | } |
| 9876 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9877 | } |
| 9878 | |
Craig Mautner | ac56514 | 2013-09-23 17:37:09 -0700 | [diff] [blame] | 9879 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "findFocusedWindow: Found new focus @ " + i + |
| 9880 | " = " + win); |
| 9881 | return win; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9882 | } |
Craig Mautner | ac56514 | 2013-09-23 17:37:09 -0700 | [diff] [blame] | 9883 | |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 9884 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "findFocusedWindow: No focusable windows."); |
Jeff Brown | 2033763 | 2012-09-24 14:25:54 -0700 | [diff] [blame] | 9885 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9886 | } |
| 9887 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 9888 | private void startFreezingDisplayLocked(boolean inTransaction, int exitAnim, int enterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9889 | if (mDisplayFrozen) { |
| 9890 | return; |
| 9891 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9892 | |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 9893 | if (!mDisplayReady || !mPolicy.isScreenOnFully()) { |
Dianne Hackborn | 8e8d65f | 2011-08-11 19:36:18 -0700 | [diff] [blame] | 9894 | // No need to freeze the screen before the system is ready or if |
| 9895 | // the screen is off. |
| 9896 | return; |
| 9897 | } |
| 9898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9899 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9901 | mDisplayFrozen = true; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 9902 | mDisplayFreezeTime = SystemClock.elapsedRealtime(); |
| 9903 | mLastFinishedFreezeSource = null; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9904 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9905 | mInputMonitor.freezeInputDispatchingLw(); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9906 | |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 9907 | // Clear the last input window -- that is just used for |
| 9908 | // clean transitions between IMEs, and if we are freezing |
| 9909 | // the screen then the whole world is changing behind the scenes. |
| 9910 | mPolicy.setLastInputMethodWindowLw(null, null); |
| 9911 | |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 9912 | if (mAppTransition.isTransitionSet()) { |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 9913 | mAppTransition.freeze(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9914 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9916 | if (PROFILE_ORIENTATION) { |
| 9917 | File file = new File("/data/system/frozen"); |
| 9918 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 9919 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 9920 | |
| 9921 | if (CUSTOM_SCREEN_ROTATION) { |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 9922 | mExitAnimId = exitAnim; |
| 9923 | mEnterAnimId = enterAnim; |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9924 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
| 9925 | final int displayId = displayContent.getDisplayId(); |
| 9926 | ScreenRotationAnimation screenRotationAnimation = |
| 9927 | mAnimator.getScreenRotationAnimationLocked(displayId); |
| 9928 | if (screenRotationAnimation != null) { |
| 9929 | screenRotationAnimation.kill(); |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 9930 | } |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 9931 | |
Craig Mautner | b98ee1e | 2014-03-24 14:38:33 +0000 | [diff] [blame] | 9932 | // Check whether the current screen contains any secure content. |
| 9933 | boolean isSecure = false; |
| 9934 | final WindowList windows = getDefaultWindowListLocked(); |
| 9935 | final int N = windows.size(); |
| 9936 | for (int i = 0; i < N; i++) { |
| 9937 | WindowState ws = windows.get(i); |
| 9938 | if (ws.isOnScreen() && (ws.mAttrs.flags & FLAG_SECURE) != 0) { |
| 9939 | isSecure = true; |
| 9940 | break; |
| 9941 | } |
| 9942 | } |
| 9943 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9944 | // TODO(multidisplay): rotation on main screen only. |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 9945 | displayContent.updateDisplayInfo(); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 9946 | screenRotationAnimation = new ScreenRotationAnimation(mContext, displayContent, |
Craig Mautner | b98ee1e | 2014-03-24 14:38:33 +0000 | [diff] [blame] | 9947 | mFxSession, inTransaction, mPolicy.isDefaultOrientationForced(), isSecure); |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9948 | mAnimator.setScreenRotationAnimationLocked(displayId, screenRotationAnimation); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 9949 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9950 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9952 | private void stopFreezingDisplayLocked() { |
| 9953 | if (!mDisplayFrozen) { |
| 9954 | return; |
| 9955 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9956 | |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 9957 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen |
| 9958 | || mClientFreezingScreen) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 9959 | if (DEBUG_ORIENTATION) Slog.d(TAG, |
| 9960 | "stopFreezingDisplayLocked: Returning mWaitingForConfig=" + mWaitingForConfig |
| 9961 | + ", mAppsFreezingScreen=" + mAppsFreezingScreen |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 9962 | + ", mWindowsFreezingScreen=" + mWindowsFreezingScreen |
| 9963 | + ", mClientFreezingScreen=" + mClientFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9964 | return; |
| 9965 | } |
Craig Mautner | 66f78d7 | 2012-12-04 16:46:50 -0800 | [diff] [blame] | 9966 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9967 | mDisplayFrozen = false; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 9968 | mLastDisplayFreezeDuration = (int)(SystemClock.elapsedRealtime() - mDisplayFreezeTime); |
| 9969 | StringBuilder sb = new StringBuilder(128); |
| 9970 | sb.append("Screen frozen for "); |
| 9971 | TimeUtils.formatDuration(mLastDisplayFreezeDuration, sb); |
| 9972 | if (mLastFinishedFreezeSource != null) { |
| 9973 | sb.append(" due to "); |
| 9974 | sb.append(mLastFinishedFreezeSource); |
| 9975 | } |
| 9976 | Slog.i(TAG, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9977 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 9978 | mH.removeMessages(H.CLIENT_FREEZE_TIMEOUT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9979 | if (PROFILE_ORIENTATION) { |
| 9980 | Debug.stopMethodTracing(); |
| 9981 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 9982 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9983 | boolean updateRotation = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9984 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9985 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
| 9986 | final int displayId = displayContent.getDisplayId(); |
| 9987 | ScreenRotationAnimation screenRotationAnimation = |
| 9988 | mAnimator.getScreenRotationAnimationLocked(displayId); |
| 9989 | if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null |
| 9990 | && screenRotationAnimation.hasScreenshot()) { |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 9991 | if (DEBUG_ORIENTATION) Slog.i(TAG, "**** Dismissing screen rotation animation"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9992 | // TODO(multidisplay): rotation on main screen only. |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9993 | DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 9994 | // Get rotation animation again, with new top window |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 9995 | boolean isDimming = displayContent.isDimming(); |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 9996 | if (!mPolicy.validateRotationAnimationLw(mExitAnimId, mEnterAnimId, isDimming)) { |
| 9997 | mExitAnimId = mEnterAnimId = 0; |
| 9998 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9999 | if (screenRotationAnimation.dismiss(mFxSession, MAX_ANIMATION_DURATION, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10000 | mTransitionAnimationScale, displayInfo.logicalWidth, |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 10001 | displayInfo.logicalHeight, mExitAnimId, mEnterAnimId)) { |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 10002 | scheduleAnimationLocked(); |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 10003 | } else { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 10004 | screenRotationAnimation.kill(); |
| 10005 | screenRotationAnimation = null; |
| 10006 | mAnimator.setScreenRotationAnimationLocked(displayId, screenRotationAnimation); |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 10007 | updateRotation = true; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 10008 | } |
| 10009 | } else { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 10010 | if (screenRotationAnimation != null) { |
| 10011 | screenRotationAnimation.kill(); |
| 10012 | screenRotationAnimation = null; |
| 10013 | mAnimator.setScreenRotationAnimationLocked(displayId, screenRotationAnimation); |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 10014 | } |
| 10015 | updateRotation = true; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 10016 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10017 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10018 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10019 | |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 10020 | boolean configChanged; |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 10021 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 10022 | // While the display is frozen we don't re-compute the orientation |
| 10023 | // to avoid inconsistent states. However, something interesting |
| 10024 | // could have actually changed during that time so re-evaluate it |
| 10025 | // now to catch that. |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 10026 | configChanged = updateOrientationFromAppTokensLocked(false); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 10027 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10028 | // A little kludge: a lot could have happened while the |
| 10029 | // display was frozen, so now that we are coming back we |
| 10030 | // do a gc so that any remote references the system |
| 10031 | // processes holds on others can be released if they are |
| 10032 | // no longer needed. |
| 10033 | mH.removeMessages(H.FORCE_GC); |
You Kim | cb6291c | 2012-12-04 23:22:28 +0900 | [diff] [blame] | 10034 | mH.sendEmptyMessageDelayed(H.FORCE_GC, 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10035 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10036 | mScreenFrozenLock.release(); |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 10037 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 10038 | if (updateRotation) { |
| 10039 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 10040 | configChanged |= updateRotationUncheckedLocked(false); |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 10041 | } |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 10042 | |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 10043 | if (configChanged) { |
| 10044 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 10045 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10046 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10047 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10048 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 10049 | DisplayMetrics dm) { |
| 10050 | if (index < tokens.length) { |
| 10051 | String str = tokens[index]; |
| 10052 | if (str != null && str.length() > 0) { |
| 10053 | try { |
| 10054 | int val = Integer.parseInt(str); |
| 10055 | return val; |
| 10056 | } catch (Exception e) { |
| 10057 | } |
| 10058 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10059 | } |
| 10060 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 10061 | return defDps; |
| 10062 | } |
| 10063 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 10064 | return val; |
| 10065 | } |
| 10066 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 10067 | void createWatermarkInTransaction() { |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10068 | if (mWatermark != null) { |
| 10069 | return; |
| 10070 | } |
| 10071 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10072 | File file = new File("/system/etc/setup.conf"); |
| 10073 | FileInputStream in = null; |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 10074 | DataInputStream ind = null; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10075 | try { |
| 10076 | in = new FileInputStream(file); |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 10077 | ind = new DataInputStream(in); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10078 | String line = ind.readLine(); |
| 10079 | if (line != null) { |
| 10080 | String[] toks = line.split("%"); |
| 10081 | if (toks != null && toks.length > 0) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10082 | mWatermark = new Watermark(getDefaultDisplayContentLocked().getDisplay(), |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 10083 | mRealDisplayMetrics, mFxSession, toks); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10084 | } |
| 10085 | } |
| 10086 | } catch (FileNotFoundException e) { |
| 10087 | } catch (IOException e) { |
| 10088 | } finally { |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 10089 | if (ind != null) { |
| 10090 | try { |
| 10091 | ind.close(); |
| 10092 | } catch (IOException e) { |
| 10093 | } |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 10094 | } else if (in != null) { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10095 | try { |
| 10096 | in.close(); |
| 10097 | } catch (IOException e) { |
| 10098 | } |
| 10099 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10100 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10101 | } |
| 10102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10103 | @Override |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 10104 | public void statusBarVisibilityChanged(int visibility) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10105 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR) |
| 10106 | != PackageManager.PERMISSION_GRANTED) { |
| 10107 | throw new SecurityException("Caller does not hold permission " |
| 10108 | + android.Manifest.permission.STATUS_BAR); |
| 10109 | } |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 10110 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 10111 | synchronized (mWindowMap) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10112 | mLastStatusBarVisibility = visibility; |
| 10113 | visibility = mPolicy.adjustSystemUiVisibilityLw(visibility); |
| 10114 | updateStatusBarVisibilityLocked(visibility); |
| 10115 | } |
| 10116 | } |
| 10117 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10118 | // TOOD(multidisplay): StatusBar on multiple screens? |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10119 | void updateStatusBarVisibilityLocked(int visibility) { |
| 10120 | mInputManager.setSystemUiVisibility(visibility); |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10121 | final WindowList windows = getDefaultWindowListLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10122 | final int N = windows.size(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10123 | for (int i = 0; i < N; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10124 | WindowState ws = windows.get(i); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10125 | try { |
| 10126 | int curValue = ws.mSystemUiVisibility; |
| 10127 | int diff = curValue ^ visibility; |
| 10128 | // We are only interested in differences of one of the |
| 10129 | // clearable flags... |
| 10130 | diff &= View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 10131 | // ...if it has actually been cleared. |
| 10132 | diff &= ~visibility; |
| 10133 | int newValue = (curValue&~diff) | (visibility&diff); |
| 10134 | if (newValue != curValue) { |
| 10135 | ws.mSeq++; |
| 10136 | ws.mSystemUiVisibility = newValue; |
| 10137 | } |
| 10138 | if (newValue != curValue || ws.mAttrs.hasSystemUiListeners) { |
| 10139 | ws.mClient.dispatchSystemUiVisibilityChanged(ws.mSeq, |
| 10140 | visibility, newValue, diff); |
| 10141 | } |
| 10142 | } catch (RemoteException e) { |
| 10143 | // so sorry |
| 10144 | } |
| 10145 | } |
| 10146 | } |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 10147 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10148 | @Override |
| 10149 | public void reevaluateStatusBarVisibility() { |
| 10150 | synchronized (mWindowMap) { |
| 10151 | int visibility = mPolicy.adjustSystemUiVisibilityLw(mLastStatusBarVisibility); |
| 10152 | updateStatusBarVisibilityLocked(visibility); |
| 10153 | performLayoutAndPlaceSurfacesLocked(); |
| 10154 | } |
| 10155 | } |
| 10156 | |
| 10157 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 10158 | public FakeWindow addFakeWindow(Looper looper, |
| 10159 | InputEventReceiver.Factory inputEventReceiverFactory, |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 10160 | String name, int windowType, int layoutParamsFlags, int layoutParamsPrivateFlags, |
| 10161 | boolean canReceiveKeys, boolean hasFocus, boolean touchFullscreen) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10162 | synchronized (mWindowMap) { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 10163 | FakeWindowImpl fw = new FakeWindowImpl(this, looper, inputEventReceiverFactory, |
| 10164 | name, windowType, |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 10165 | layoutParamsFlags, layoutParamsPrivateFlags, canReceiveKeys, |
| 10166 | hasFocus, touchFullscreen); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10167 | int i=0; |
| 10168 | while (i<mFakeWindows.size()) { |
| 10169 | if (mFakeWindows.get(i).mWindowLayer <= fw.mWindowLayer) { |
| 10170 | break; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 10171 | } |
| 10172 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10173 | mFakeWindows.add(i, fw); |
| 10174 | mInputMonitor.updateInputWindowsLw(true); |
| 10175 | return fw; |
| 10176 | } |
| 10177 | } |
| 10178 | |
| 10179 | boolean removeFakeWindowLocked(FakeWindow window) { |
| 10180 | synchronized (mWindowMap) { |
| 10181 | if (mFakeWindows.remove(window)) { |
| 10182 | mInputMonitor.updateInputWindowsLw(true); |
| 10183 | return true; |
| 10184 | } |
| 10185 | return false; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 10186 | } |
| 10187 | } |
| 10188 | |
satok | e0a9941 | 2012-05-10 02:22:58 +0900 | [diff] [blame] | 10189 | // It is assumed that this method is called only by InputMethodManagerService. |
| 10190 | public void saveLastInputMethodWindowForTransition() { |
| 10191 | synchronized (mWindowMap) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10192 | // TODO(multidisplay): Pass in the displayID. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10193 | DisplayContent displayContent = getDefaultDisplayContentLocked(); |
satok | e0a9941 | 2012-05-10 02:22:58 +0900 | [diff] [blame] | 10194 | if (mInputMethodWindow != null) { |
| 10195 | mPolicy.setLastInputMethodWindowLw(mInputMethodWindow, mInputMethodTarget); |
| 10196 | } |
| 10197 | } |
| 10198 | } |
| 10199 | |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 10200 | public int getInputMethodWindowVisibleHeight() { |
| 10201 | synchronized (mWindowMap) { |
| 10202 | return mPolicy.getInputMethodWindowVisibleHeightLw(); |
| 10203 | } |
| 10204 | } |
| 10205 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 10206 | @Override |
| 10207 | public boolean hasNavigationBar() { |
| 10208 | return mPolicy.hasNavigationBar(); |
| 10209 | } |
| 10210 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 10211 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 10212 | public void lockNow(Bundle options) { |
| 10213 | mPolicy.lockNow(options); |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 10214 | } |
Craig Mautner | 6cfa729 | 2013-01-15 09:05:42 -0800 | [diff] [blame] | 10215 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 10216 | @Override |
Jim Miller | bfec0a8 | 2012-11-05 20:05:22 -0800 | [diff] [blame] | 10217 | public boolean isSafeModeEnabled() { |
| 10218 | return mSafeMode; |
| 10219 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 10220 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10221 | void dumpPolicyLocked(PrintWriter pw, String[] args, boolean dumpAll) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10222 | pw.println("WINDOW MANAGER POLICY STATE (dumpsys window policy)"); |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10223 | mPolicy.dump(" ", pw, args); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10224 | } |
| 10225 | |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 10226 | void dumpAnimatorLocked(PrintWriter pw, String[] args, boolean dumpAll) { |
| 10227 | pw.println("WINDOW MANAGER ANIMATOR STATE (dumpsys window animator)"); |
| 10228 | mAnimator.dumpLocked(pw, " ", dumpAll); |
| 10229 | } |
| 10230 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10231 | void dumpTokensLocked(PrintWriter pw, boolean dumpAll) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10232 | pw.println("WINDOW MANAGER TOKENS (dumpsys window tokens)"); |
| 10233 | if (mTokenMap.size() > 0) { |
| 10234 | pw.println(" All tokens:"); |
| 10235 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10236 | while (it.hasNext()) { |
| 10237 | WindowToken token = it.next(); |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 10238 | pw.print(" "); pw.print(token); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10239 | if (dumpAll) { |
| 10240 | pw.println(':'); |
| 10241 | token.dump(pw, " "); |
| 10242 | } else { |
| 10243 | pw.println(); |
| 10244 | } |
| 10245 | } |
| 10246 | } |
| 10247 | if (mWallpaperTokens.size() > 0) { |
| 10248 | pw.println(); |
| 10249 | pw.println(" Wallpaper tokens:"); |
| 10250 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10251 | WindowToken token = mWallpaperTokens.get(i); |
| 10252 | pw.print(" Wallpaper #"); pw.print(i); |
| 10253 | pw.print(' '); pw.print(token); |
| 10254 | if (dumpAll) { |
| 10255 | pw.println(':'); |
| 10256 | token.dump(pw, " "); |
| 10257 | } else { |
| 10258 | pw.println(); |
| 10259 | } |
| 10260 | } |
| 10261 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10262 | if (mFinishedStarting.size() > 0) { |
| 10263 | pw.println(); |
| 10264 | pw.println(" Finishing start of application tokens:"); |
| 10265 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10266 | WindowToken token = mFinishedStarting.get(i); |
| 10267 | pw.print(" Finished Starting #"); pw.print(i); |
| 10268 | pw.print(' '); pw.print(token); |
| 10269 | if (dumpAll) { |
| 10270 | pw.println(':'); |
| 10271 | token.dump(pw, " "); |
| 10272 | } else { |
| 10273 | pw.println(); |
| 10274 | } |
| 10275 | } |
| 10276 | } |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 10277 | if (mOpeningApps.size() > 0 || mClosingApps.size() > 0) { |
| 10278 | pw.println(); |
| 10279 | if (mOpeningApps.size() > 0) { |
| 10280 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 10281 | } |
| 10282 | if (mClosingApps.size() > 0) { |
| 10283 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 10284 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10285 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10286 | } |
| 10287 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10288 | void dumpSessionsLocked(PrintWriter pw, boolean dumpAll) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10289 | pw.println("WINDOW MANAGER SESSIONS (dumpsys window sessions)"); |
| 10290 | if (mSessions.size() > 0) { |
| 10291 | Iterator<Session> it = mSessions.iterator(); |
| 10292 | while (it.hasNext()) { |
| 10293 | Session s = it.next(); |
| 10294 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| 10295 | s.dump(pw, " "); |
| 10296 | } |
| 10297 | } |
| 10298 | } |
| 10299 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 10300 | void dumpDisplayContentsLocked(PrintWriter pw, boolean dumpAll) { |
| 10301 | pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)"); |
| 10302 | if (mDisplayReady) { |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 10303 | final int numDisplays = mDisplayContents.size(); |
| 10304 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 10305 | final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx); |
Craig Mautner | 127299f | 2013-11-12 17:57:47 +0000 | [diff] [blame] | 10306 | displayContent.dump(" ", pw); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 10307 | } |
| 10308 | } else { |
| 10309 | pw.println(" NO DISPLAY"); |
| 10310 | } |
| 10311 | } |
| 10312 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10313 | void dumpWindowsLocked(PrintWriter pw, boolean dumpAll, |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10314 | ArrayList<WindowState> windows) { |
| 10315 | pw.println("WINDOW MANAGER WINDOWS (dumpsys window windows)"); |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10316 | dumpWindowsNoHeaderLocked(pw, dumpAll, windows); |
| 10317 | } |
| 10318 | |
| 10319 | void dumpWindowsNoHeaderLocked(PrintWriter pw, boolean dumpAll, |
| 10320 | ArrayList<WindowState> windows) { |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 10321 | final int numDisplays = mDisplayContents.size(); |
| 10322 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 10323 | final WindowList windowList = mDisplayContents.valueAt(displayNdx).getWindowList(); |
| 10324 | for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) { |
| 10325 | final WindowState w = windowList.get(winNdx); |
| 10326 | if (windows == null || windows.contains(w)) { |
Craig Mautner | b1885b8 | 2013-09-16 22:50:50 -0700 | [diff] [blame] | 10327 | pw.print(" Window #"); pw.print(winNdx); pw.print(' '); |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 10328 | pw.print(w); pw.println(":"); |
| 10329 | w.dump(pw, " ", dumpAll || windows != null); |
| 10330 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10331 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10332 | } |
| 10333 | if (mInputMethodDialogs.size() > 0) { |
| 10334 | pw.println(); |
| 10335 | pw.println(" Input method dialogs:"); |
| 10336 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10337 | WindowState w = mInputMethodDialogs.get(i); |
| 10338 | if (windows == null || windows.contains(w)) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10339 | 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] | 10340 | } |
| 10341 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10342 | } |
| 10343 | if (mPendingRemove.size() > 0) { |
| 10344 | pw.println(); |
| 10345 | pw.println(" Remove pending for:"); |
| 10346 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10347 | WindowState w = mPendingRemove.get(i); |
| 10348 | if (windows == null || windows.contains(w)) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10349 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10350 | pw.print(w); |
| 10351 | if (dumpAll) { |
| 10352 | pw.println(":"); |
| 10353 | w.dump(pw, " ", true); |
| 10354 | } else { |
| 10355 | pw.println(); |
| 10356 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10357 | } |
| 10358 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10359 | } |
| 10360 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10361 | pw.println(); |
| 10362 | pw.println(" Windows force removing:"); |
| 10363 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10364 | WindowState w = mForceRemoves.get(i); |
| 10365 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10366 | pw.print(w); |
| 10367 | if (dumpAll) { |
| 10368 | pw.println(":"); |
| 10369 | w.dump(pw, " ", true); |
| 10370 | } else { |
| 10371 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10372 | } |
| 10373 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10374 | } |
| 10375 | if (mDestroySurface.size() > 0) { |
| 10376 | pw.println(); |
| 10377 | pw.println(" Windows waiting to destroy their surface:"); |
| 10378 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10379 | WindowState w = mDestroySurface.get(i); |
| 10380 | if (windows == null || windows.contains(w)) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10381 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10382 | pw.print(w); |
| 10383 | if (dumpAll) { |
| 10384 | pw.println(":"); |
| 10385 | w.dump(pw, " ", true); |
| 10386 | } else { |
| 10387 | pw.println(); |
| 10388 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10389 | } |
| 10390 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10391 | } |
| 10392 | if (mLosingFocus.size() > 0) { |
| 10393 | pw.println(); |
| 10394 | pw.println(" Windows losing focus:"); |
| 10395 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10396 | WindowState w = mLosingFocus.get(i); |
| 10397 | if (windows == null || windows.contains(w)) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10398 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10399 | pw.print(w); |
| 10400 | if (dumpAll) { |
| 10401 | pw.println(":"); |
| 10402 | w.dump(pw, " ", true); |
| 10403 | } else { |
| 10404 | pw.println(); |
| 10405 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10406 | } |
| 10407 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10408 | } |
| 10409 | if (mResizingWindows.size() > 0) { |
| 10410 | pw.println(); |
| 10411 | pw.println(" Windows waiting to resize:"); |
| 10412 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10413 | WindowState w = mResizingWindows.get(i); |
| 10414 | if (windows == null || windows.contains(w)) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10415 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10416 | pw.print(w); |
| 10417 | if (dumpAll) { |
| 10418 | pw.println(":"); |
| 10419 | w.dump(pw, " ", true); |
| 10420 | } else { |
| 10421 | pw.println(); |
| 10422 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10423 | } |
| 10424 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10425 | } |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 10426 | if (mWaitingForDrawn.size() > 0) { |
| 10427 | pw.println(); |
| 10428 | pw.println(" Clients waiting for these windows to be drawn:"); |
| 10429 | for (int i=mWaitingForDrawn.size()-1; i>=0; i--) { |
| 10430 | Pair<WindowState, IRemoteCallback> pair = mWaitingForDrawn.get(i); |
| 10431 | pw.print(" Waiting #"); pw.print(i); pw.print(' '); pw.print(pair.first); |
| 10432 | pw.print(": "); pw.println(pair.second); |
| 10433 | } |
| 10434 | } |
Dianne Hackborn | 77119bc | 2012-10-23 14:32:48 -0700 | [diff] [blame] | 10435 | pw.println(); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10436 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 10437 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10438 | if (mLastFocus != mCurrentFocus) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10439 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10440 | } |
| 10441 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10442 | if (mInputMethodTarget != null) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10443 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10444 | } |
| 10445 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 10446 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 10447 | pw.print(" mLastDisplayFreezeDuration="); |
| 10448 | TimeUtils.formatDuration(mLastDisplayFreezeDuration, pw); |
| 10449 | if ( mLastFinishedFreezeSource != null) { |
| 10450 | pw.print(" due to "); |
| 10451 | pw.print(mLastFinishedFreezeSource); |
| 10452 | } |
| 10453 | pw.println(); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10454 | if (dumpAll) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 10455 | pw.print(" mSystemDecorLayer="); pw.print(mSystemDecorLayer); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 10456 | pw.print(" mScreenRect="); pw.println(mScreenRect.toShortString()); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10457 | if (mLastStatusBarVisibility != 0) { |
| 10458 | pw.print(" mLastStatusBarVisibility=0x"); |
| 10459 | pw.println(Integer.toHexString(mLastStatusBarVisibility)); |
| 10460 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10461 | if (mInputMethodWindow != null) { |
| 10462 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| 10463 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10464 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 10465 | if (mLowerWallpaperTarget != null || mUpperWallpaperTarget != null) { |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10466 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10467 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10468 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10469 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10470 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| 10471 | if (mInputMethodAnimLayerAdjustment != 0 || |
| 10472 | mWallpaperAnimLayerAdjustment != 0) { |
| 10473 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| 10474 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10475 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10476 | pw.println(mWallpaperAnimLayerAdjustment); |
| 10477 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10478 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10479 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 10480 | if (needsLayout()) { |
| 10481 | pw.print(" layoutNeeded on displays="); |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 10482 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 10483 | final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 10484 | if (displayContent.layoutNeeded) { |
| 10485 | pw.print(displayContent.getDisplayId()); |
| 10486 | } |
| 10487 | } |
| 10488 | pw.println(); |
| 10489 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 10490 | pw.print(" mTransactionSequence="); pw.println(mTransactionSequence); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10491 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 10492 | pw.print(" windows="); pw.print(mWindowsFreezingScreen); |
| 10493 | pw.print(" client="); pw.print(mClientFreezingScreen); |
| 10494 | pw.print(" apps="); pw.print(mAppsFreezingScreen); |
| 10495 | pw.print(" waitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10496 | pw.print(" mRotation="); pw.print(mRotation); |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 10497 | pw.print(" mAltOrientation="); pw.println(mAltOrientation); |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 10498 | pw.print(" mLastWindowForcedOrientation="); pw.print(mLastWindowForcedOrientation); |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 10499 | pw.print(" mForcedAppOrientation="); pw.println(mForcedAppOrientation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 10500 | pw.print(" mDeferredRotationPauseCount="); pw.println(mDeferredRotationPauseCount); |
Dianne Hackborn | 4dcece8 | 2012-02-10 14:50:32 -0800 | [diff] [blame] | 10501 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10502 | pw.print(" mTransitionWindowAnimationScale="); pw.print(mTransitionAnimationScale); |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 10503 | pw.print(" mAnimatorDurationScale="); pw.println(mAnimatorDurationScale); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 10504 | pw.print(" mTraversalScheduled="); pw.println(mTraversalScheduled); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10505 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 10506 | pw.print(" mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 10507 | pw.println(" mLayoutToAnim:"); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 10508 | mAppTransition.dump(pw); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10509 | } |
| 10510 | } |
| 10511 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10512 | boolean dumpWindows(PrintWriter pw, String name, String[] args, |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10513 | int opti, boolean dumpAll) { |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10514 | WindowList windows = new WindowList(); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10515 | if ("visible".equals(name)) { |
| 10516 | synchronized(mWindowMap) { |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 10517 | final int numDisplays = mDisplayContents.size(); |
| 10518 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 10519 | final WindowList windowList = |
| 10520 | mDisplayContents.valueAt(displayNdx).getWindowList(); |
| 10521 | for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) { |
| 10522 | final WindowState w = windowList.get(winNdx); |
| 10523 | if (w.mWinAnimator.mSurfaceShown) { |
| 10524 | windows.add(w); |
| 10525 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10526 | } |
| 10527 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10528 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10529 | } else { |
| 10530 | int objectId = 0; |
| 10531 | // See if this is an object ID. |
| 10532 | try { |
| 10533 | objectId = Integer.parseInt(name, 16); |
| 10534 | name = null; |
| 10535 | } catch (RuntimeException e) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10536 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10537 | synchronized(mWindowMap) { |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 10538 | final int numDisplays = mDisplayContents.size(); |
| 10539 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 10540 | final WindowList windowList = |
| 10541 | mDisplayContents.valueAt(displayNdx).getWindowList(); |
| 10542 | for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) { |
| 10543 | final WindowState w = windowList.get(winNdx); |
| 10544 | if (name != null) { |
| 10545 | if (w.mAttrs.getTitle().toString().contains(name)) { |
| 10546 | windows.add(w); |
| 10547 | } |
| 10548 | } else if (System.identityHashCode(w) == objectId) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10549 | windows.add(w); |
| 10550 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10551 | } |
| 10552 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10553 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10554 | } |
| 10555 | |
| 10556 | if (windows.size() <= 0) { |
| 10557 | return false; |
| 10558 | } |
| 10559 | |
| 10560 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10561 | dumpWindowsLocked(pw, dumpAll, windows); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10562 | } |
| 10563 | return true; |
| 10564 | } |
| 10565 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10566 | void dumpLastANRLocked(PrintWriter pw) { |
| 10567 | pw.println("WINDOW MANAGER LAST ANR (dumpsys window lastanr)"); |
| 10568 | if (mLastANRState == null) { |
| 10569 | pw.println(" <no ANR has occurred since boot>"); |
| 10570 | } else { |
| 10571 | pw.println(mLastANRState); |
| 10572 | } |
| 10573 | } |
| 10574 | |
| 10575 | /** |
| 10576 | * Saves information about the state of the window manager at |
| 10577 | * the time an ANR occurred before anything else in the system changes |
| 10578 | * in response. |
| 10579 | * |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 10580 | * @param appWindowToken The application that ANR'd, may be null. |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10581 | * @param windowState The window that ANR'd, may be null. |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 10582 | * @param reason The reason for the ANR, may be null. |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10583 | */ |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 10584 | public void saveANRStateLocked(AppWindowToken appWindowToken, WindowState windowState, |
| 10585 | String reason) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10586 | StringWriter sw = new StringWriter(); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 10587 | PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10588 | pw.println(" ANR time: " + DateFormat.getInstance().format(new Date())); |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 10589 | if (appWindowToken != null) { |
| 10590 | pw.println(" Application at fault: " + appWindowToken.stringName); |
| 10591 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10592 | if (windowState != null) { |
| 10593 | pw.println(" Window at fault: " + windowState.mAttrs.getTitle()); |
| 10594 | } |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 10595 | if (reason != null) { |
| 10596 | pw.println(" Reason: " + reason); |
| 10597 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10598 | pw.println(); |
| 10599 | dumpWindowsNoHeaderLocked(pw, true, null); |
| 10600 | pw.close(); |
| 10601 | mLastANRState = sw.toString(); |
| 10602 | } |
| 10603 | |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10604 | @Override |
| 10605 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10606 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10607 | != PackageManager.PERMISSION_GRANTED) { |
| 10608 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10609 | + Binder.getCallingPid() |
| 10610 | + ", uid=" + Binder.getCallingUid()); |
| 10611 | return; |
| 10612 | } |
| 10613 | |
| 10614 | boolean dumpAll = false; |
| 10615 | |
| 10616 | int opti = 0; |
| 10617 | while (opti < args.length) { |
| 10618 | String opt = args[opti]; |
| 10619 | if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') { |
| 10620 | break; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10621 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10622 | opti++; |
| 10623 | if ("-a".equals(opt)) { |
| 10624 | dumpAll = true; |
| 10625 | } else if ("-h".equals(opt)) { |
| 10626 | pw.println("Window manager dump options:"); |
| 10627 | pw.println(" [-a] [-h] [cmd] ..."); |
| 10628 | pw.println(" cmd may be one of:"); |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10629 | pw.println(" l[astanr]: last ANR information"); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10630 | pw.println(" p[policy]: policy state"); |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 10631 | pw.println(" a[animator]: animator state"); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10632 | pw.println(" s[essions]: active sessions"); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 10633 | pw.println(" d[isplays]: active display contents"); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10634 | pw.println(" t[okens]: token list"); |
| 10635 | pw.println(" w[indows]: window list"); |
| 10636 | pw.println(" cmd may also be a NAME to dump windows. NAME may"); |
| 10637 | pw.println(" be a partial substring in a window name, a"); |
| 10638 | pw.println(" Window hex object identifier, or"); |
| 10639 | pw.println(" \"all\" for all windows, or"); |
| 10640 | pw.println(" \"visible\" for the visible windows."); |
| 10641 | pw.println(" -a: include all available server state."); |
| 10642 | return; |
Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 10643 | } else { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10644 | pw.println("Unknown argument: " + opt + "; use -h for help"); |
Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 10645 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10646 | } |
| 10647 | |
| 10648 | // Is the caller requesting to dump a particular piece of data? |
| 10649 | if (opti < args.length) { |
| 10650 | String cmd = args[opti]; |
| 10651 | opti++; |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10652 | if ("lastanr".equals(cmd) || "l".equals(cmd)) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10653 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10654 | dumpLastANRLocked(pw); |
| 10655 | } |
| 10656 | return; |
| 10657 | } else if ("policy".equals(cmd) || "p".equals(cmd)) { |
| 10658 | synchronized(mWindowMap) { |
| 10659 | dumpPolicyLocked(pw, args, true); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10660 | } |
| 10661 | return; |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 10662 | } else if ("animator".equals(cmd) || "a".equals(cmd)) { |
| 10663 | synchronized(mWindowMap) { |
| 10664 | dumpAnimatorLocked(pw, args, true); |
| 10665 | } |
| 10666 | return; |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10667 | } else if ("sessions".equals(cmd) || "s".equals(cmd)) { |
| 10668 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10669 | dumpSessionsLocked(pw, true); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10670 | } |
| 10671 | return; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 10672 | } else if ("displays".equals(cmd) || "d".equals(cmd)) { |
| 10673 | synchronized(mWindowMap) { |
| 10674 | dumpDisplayContentsLocked(pw, true); |
| 10675 | } |
| 10676 | return; |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10677 | } else if ("tokens".equals(cmd) || "t".equals(cmd)) { |
| 10678 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10679 | dumpTokensLocked(pw, true); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10680 | } |
| 10681 | return; |
| 10682 | } else if ("windows".equals(cmd) || "w".equals(cmd)) { |
| 10683 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10684 | dumpWindowsLocked(pw, true, null); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10685 | } |
| 10686 | return; |
| 10687 | } else if ("all".equals(cmd) || "a".equals(cmd)) { |
| 10688 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10689 | dumpWindowsLocked(pw, true, null); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10690 | } |
| 10691 | return; |
| 10692 | } else { |
| 10693 | // Dumping a single name? |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10694 | if (!dumpWindows(pw, cmd, args, opti, dumpAll)) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10695 | pw.println("Bad window command, or no windows match: " + cmd); |
| 10696 | pw.println("Use -h for help."); |
| 10697 | } |
| 10698 | return; |
| 10699 | } |
| 10700 | } |
| 10701 | |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10702 | synchronized(mWindowMap) { |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 10703 | pw.println(); |
| 10704 | if (dumpAll) { |
| 10705 | pw.println("-------------------------------------------------------------------------------"); |
| 10706 | } |
| 10707 | dumpLastANRLocked(pw); |
| 10708 | pw.println(); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10709 | if (dumpAll) { |
| 10710 | pw.println("-------------------------------------------------------------------------------"); |
| 10711 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10712 | dumpPolicyLocked(pw, args, dumpAll); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10713 | pw.println(); |
| 10714 | if (dumpAll) { |
| 10715 | pw.println("-------------------------------------------------------------------------------"); |
| 10716 | } |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 10717 | dumpAnimatorLocked(pw, args, dumpAll); |
| 10718 | pw.println(); |
| 10719 | if (dumpAll) { |
| 10720 | pw.println("-------------------------------------------------------------------------------"); |
| 10721 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10722 | dumpSessionsLocked(pw, dumpAll); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10723 | pw.println(); |
| 10724 | if (dumpAll) { |
| 10725 | pw.println("-------------------------------------------------------------------------------"); |
| 10726 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 10727 | dumpDisplayContentsLocked(pw, dumpAll); |
| 10728 | pw.println(); |
| 10729 | if (dumpAll) { |
| 10730 | pw.println("-------------------------------------------------------------------------------"); |
| 10731 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10732 | dumpTokensLocked(pw, dumpAll); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10733 | pw.println(); |
| 10734 | if (dumpAll) { |
| 10735 | pw.println("-------------------------------------------------------------------------------"); |
| 10736 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10737 | dumpWindowsLocked(pw, dumpAll, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10738 | } |
| 10739 | } |
| 10740 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10741 | // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection). |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 10742 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10743 | public void monitor() { |
| 10744 | synchronized (mWindowMap) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10745 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10746 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 10747 | public interface OnHardKeyboardStatusChangeListener { |
| 10748 | public void onHardKeyboardStatusChange(boolean available, boolean enabled); |
| 10749 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 10750 | |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 10751 | void debugLayoutRepeats(final String msg, int pendingLayoutChanges) { |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 10752 | if (mLayoutRepeatCount >= LAYOUT_REPEAT_THRESHOLD) { |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 10753 | Slog.v(TAG, "Layouts looping: " + msg + ", mPendingLayoutChanges = 0x" + |
| 10754 | Integer.toHexString(pendingLayoutChanges)); |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 10755 | } |
| 10756 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10757 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 10758 | private DisplayContent newDisplayContentLocked(final Display display) { |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 10759 | DisplayContent displayContent = new DisplayContent(display, this); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 10760 | final int displayId = display.getDisplayId(); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 10761 | if (DEBUG_DISPLAY) Slog.v(TAG, "Adding display=" + display); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 10762 | mDisplayContents.put(displayId, displayContent); |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 10763 | |
| 10764 | DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 10765 | final Rect rect = new Rect(); |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 10766 | mDisplaySettings.getOverscanLocked(displayInfo.name, rect); |
| 10767 | synchronized (displayContent.mDisplaySizeLock) { |
| 10768 | displayInfo.overscanLeft = rect.left; |
| 10769 | displayInfo.overscanTop = rect.top; |
| 10770 | displayInfo.overscanRight = rect.right; |
| 10771 | displayInfo.overscanBottom = rect.bottom; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 10772 | mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager( |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 10773 | displayId, displayInfo); |
| 10774 | } |
| 10775 | configureDisplayPolicyLocked(displayContent); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 10776 | |
| 10777 | // TODO: Create an input channel for each display with touch capability. |
| 10778 | if (displayId == Display.DEFAULT_DISPLAY) { |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 10779 | displayContent.mTapDetector = new StackTapPointerEventListener(this, displayContent); |
| 10780 | registerPointerEventListener(displayContent.mTapDetector); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 10781 | } |
| 10782 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 10783 | return displayContent; |
| 10784 | } |
| 10785 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10786 | public void createDisplayContentLocked(final Display display) { |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10787 | if (display == null) { |
| 10788 | throw new IllegalArgumentException("getDisplayContent: display must not be null"); |
| 10789 | } |
keunyoung | 1eb0637 | 2013-08-09 14:32:36 -0700 | [diff] [blame] | 10790 | getDisplayContentLocked(display.getDisplayId()); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10791 | } |
| 10792 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 10793 | /** |
| 10794 | * Retrieve the DisplayContent for the specified displayId. Will create a new DisplayContent if |
| 10795 | * there is a Display for the displayId. |
| 10796 | * @param displayId The display the caller is interested in. |
| 10797 | * @return The DisplayContent associated with displayId or null if there is no Display for it. |
| 10798 | */ |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10799 | public DisplayContent getDisplayContentLocked(final int displayId) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10800 | DisplayContent displayContent = mDisplayContents.get(displayId); |
| 10801 | if (displayContent == null) { |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 10802 | final Display display = mDisplayManager.getDisplay(displayId); |
| 10803 | if (display != null) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 10804 | displayContent = newDisplayContentLocked(display); |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 10805 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10806 | } |
| 10807 | return displayContent; |
| 10808 | } |
| 10809 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 10810 | // There is an inherent assumption that this will never return null. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10811 | public DisplayContent getDefaultDisplayContentLocked() { |
| 10812 | return getDisplayContentLocked(Display.DEFAULT_DISPLAY); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10813 | } |
| 10814 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10815 | public WindowList getDefaultWindowListLocked() { |
| 10816 | return getDefaultDisplayContentLocked().getWindowList(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10817 | } |
| 10818 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10819 | public DisplayInfo getDefaultDisplayInfoLocked() { |
| 10820 | return getDefaultDisplayContentLocked().getDisplayInfo(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10821 | } |
| 10822 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 10823 | /** |
| 10824 | * Return the list of WindowStates associated on the passed display. |
| 10825 | * @param display The screen to return windows from. |
| 10826 | * @return The list of WindowStates on the screen, or null if the there is no screen. |
| 10827 | */ |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10828 | public WindowList getWindowListLocked(final Display display) { |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 10829 | return getWindowListLocked(display.getDisplayId()); |
| 10830 | } |
| 10831 | |
| 10832 | /** |
| 10833 | * Return the list of WindowStates associated on the passed display. |
| 10834 | * @param displayId The screen to return windows from. |
| 10835 | * @return The list of WindowStates on the screen, or null if the there is no screen. |
| 10836 | */ |
| 10837 | public WindowList getWindowListLocked(final int displayId) { |
| 10838 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 10839 | return displayContent != null ? displayContent.getWindowList() : null; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 10840 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10841 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10842 | public void onDisplayAdded(int displayId) { |
| 10843 | mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_ADDED, displayId, 0)); |
| 10844 | } |
| 10845 | |
Craig Mautner | ad25fa3 | 2014-01-12 21:19:06 -0800 | [diff] [blame] | 10846 | public void handleDisplayAdded(int displayId) { |
| 10847 | synchronized (mWindowMap) { |
| 10848 | final Display display = mDisplayManager.getDisplay(displayId); |
| 10849 | if (display != null) { |
| 10850 | createDisplayContentLocked(display); |
| 10851 | displayReady(displayId); |
| 10852 | } |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 10853 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10854 | } |
| 10855 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10856 | public void onDisplayRemoved(int displayId) { |
| 10857 | mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_REMOVED, displayId, 0)); |
| 10858 | } |
| 10859 | |
| 10860 | private void handleDisplayRemovedLocked(int displayId) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10861 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 10862 | if (displayContent != null) { |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 10863 | if (displayContent.isAnimating()) { |
| 10864 | displayContent.mDeferredRemoval = true; |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 10865 | return; |
| 10866 | } |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 10867 | if (DEBUG_DISPLAY) Slog.v(TAG, "Removing display=" + displayContent); |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 10868 | mDisplayContents.delete(displayId); |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 10869 | displayContent.close(); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 10870 | if (displayId == Display.DEFAULT_DISPLAY) { |
| 10871 | unregisterPointerEventListener(displayContent.mTapDetector); |
Andreas Huber | b551c6d | 2013-04-26 11:54:53 -0700 | [diff] [blame] | 10872 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10873 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 10874 | mAnimator.removeDisplayLocked(displayId); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10875 | } |
| 10876 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10877 | public void onDisplayChanged(int displayId) { |
| 10878 | mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_CHANGED, displayId, 0)); |
| 10879 | } |
| 10880 | |
| 10881 | private void handleDisplayChangedLocked(int displayId) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10882 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10883 | if (displayContent != null) { |
| 10884 | displayContent.updateDisplayInfo(); |
| 10885 | } |
| 10886 | } |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 10887 | |
| 10888 | @Override |
| 10889 | public Object getWindowManagerLock() { |
| 10890 | return mWindowMap; |
| 10891 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 10892 | |
| 10893 | private final class LocalService extends WindowManagerInternal { |
| 10894 | @Override |
| 10895 | public void requestTraversalFromDisplayManager() { |
| 10896 | requestTraversal(); |
| 10897 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 10898 | |
| 10899 | @Override |
| 10900 | public void setMagnificationSpec(MagnificationSpec spec) { |
| 10901 | synchronized (mWindowMap) { |
| 10902 | if (mAccessibilityController != null) { |
| 10903 | mAccessibilityController.setMagnificationSpecLocked(spec); |
| 10904 | } else { |
| 10905 | throw new IllegalStateException("Magnification callbacks not set!"); |
| 10906 | } |
| 10907 | } |
| 10908 | if (Binder.getCallingPid() != android.os.Process.myPid()) { |
| 10909 | spec.recycle(); |
| 10910 | } |
| 10911 | } |
| 10912 | |
| 10913 | @Override |
| 10914 | public MagnificationSpec getCompatibleMagnificationSpecForWindow(IBinder windowToken) { |
| 10915 | synchronized (mWindowMap) { |
| 10916 | WindowState windowState = mWindowMap.get(windowToken); |
| 10917 | if (windowState == null) { |
| 10918 | return null; |
| 10919 | } |
| 10920 | MagnificationSpec spec = null; |
| 10921 | if (mAccessibilityController != null) { |
| 10922 | spec = mAccessibilityController.getMagnificationSpecForWindowLocked(windowState); |
| 10923 | } |
| 10924 | if ((spec == null || spec.isNop()) && windowState.mGlobalScale == 1.0f) { |
| 10925 | return null; |
| 10926 | } |
| 10927 | spec = (spec == null) ? MagnificationSpec.obtain() : MagnificationSpec.obtain(spec); |
| 10928 | spec.scale *= windowState.mGlobalScale; |
| 10929 | return spec; |
| 10930 | } |
| 10931 | } |
| 10932 | |
| 10933 | @Override |
| 10934 | public void setMagnificationCallbacks(MagnificationCallbacks callbacks) { |
| 10935 | synchronized (mWindowMap) { |
| 10936 | if (mAccessibilityController == null) { |
| 10937 | mAccessibilityController = new AccessibilityController( |
| 10938 | WindowManagerService.this); |
| 10939 | } |
| 10940 | mAccessibilityController.setMagnificationCallbacksLocked(callbacks); |
| 10941 | if (!mAccessibilityController.hasCallbacksLocked()) { |
| 10942 | mAccessibilityController = null; |
| 10943 | } |
| 10944 | } |
| 10945 | } |
| 10946 | |
| 10947 | @Override |
| 10948 | public void setWindowsForAccessibilityCallback(WindowsForAccessibilityCallback callback) { |
| 10949 | synchronized (mWindowMap) { |
| 10950 | if (mAccessibilityController == null) { |
| 10951 | mAccessibilityController = new AccessibilityController( |
| 10952 | WindowManagerService.this); |
| 10953 | } |
| 10954 | mAccessibilityController.setWindowsForAccessibilityCallback(callback); |
| 10955 | if (!mAccessibilityController.hasCallbacksLocked()) { |
| 10956 | mAccessibilityController = null; |
| 10957 | } |
| 10958 | } |
| 10959 | } |
| 10960 | |
| 10961 | @Override |
| 10962 | public void setInputFilter(IInputFilter filter) { |
| 10963 | mInputManager.setInputFilter(filter); |
| 10964 | } |
| 10965 | |
| 10966 | @Override |
| 10967 | public IBinder getFocusedWindowToken() { |
| 10968 | synchronized (mWindowMap) { |
| 10969 | WindowState windowState = getFocusedWindowLocked(); |
| 10970 | if (windowState != null) { |
| 10971 | return windowState.mClient.asBinder(); |
| 10972 | } |
| 10973 | return null; |
| 10974 | } |
| 10975 | } |
| 10976 | |
| 10977 | @Override |
| 10978 | public boolean isKeyguardLocked() { |
| 10979 | return isKeyguardLocked(); |
| 10980 | } |
| 10981 | |
| 10982 | @Override |
| 10983 | public void getWindowFrame(IBinder token, Rect outBounds) { |
| 10984 | synchronized (mWindowMap) { |
| 10985 | WindowState windowState = mWindowMap.get(token); |
| 10986 | if (windowState != null) { |
| 10987 | outBounds.set(windowState.mFrame); |
| 10988 | } else { |
| 10989 | outBounds.setEmpty(); |
| 10990 | } |
| 10991 | } |
| 10992 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 10993 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10994 | } |