Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.view; |
| 18 | |
| 19 | import android.animation.ValueAnimator; |
Alan Viverette | 1761cfa | 2019-02-13 17:44:08 -0500 | [diff] [blame] | 20 | import android.annotation.NonNull; |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 21 | import android.annotation.UnsupportedAppUsage; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 22 | import android.app.ActivityManager; |
| 23 | import android.content.ComponentCallbacks2; |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 24 | import android.content.Context; |
Alan Viverette | d70b9e7 | 2015-05-27 14:29:20 -0700 | [diff] [blame] | 25 | import android.content.pm.ApplicationInfo; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 26 | import android.content.res.Configuration; |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 27 | import android.os.Build; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 28 | import android.os.IBinder; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 29 | import android.os.RemoteException; |
| 30 | import android.os.ServiceManager; |
| 31 | import android.os.SystemProperties; |
| 32 | import android.util.AndroidRuntimeException; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 33 | import android.util.ArraySet; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 34 | import android.util.Log; |
| 35 | import android.view.inputmethod.InputMethodManager; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 36 | |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 37 | import com.android.internal.util.FastPrintWriter; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 38 | |
| 39 | import java.io.FileDescriptor; |
| 40 | import java.io.FileOutputStream; |
| 41 | import java.io.PrintWriter; |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 42 | import java.util.ArrayList; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Provides low-level communication with the system window manager for |
| 46 | * operations that are not associated with any particular context. |
| 47 | * |
| 48 | * This class is only used internally to implement global functions where |
| 49 | * the caller already knows the display and relevant compatibility information |
| 50 | * for the operation. For most purposes, you should use {@link WindowManager} instead |
| 51 | * since it is bound to a context. |
| 52 | * |
| 53 | * @see WindowManagerImpl |
| 54 | * @hide |
| 55 | */ |
| 56 | public final class WindowManagerGlobal { |
| 57 | private static final String TAG = "WindowManager"; |
| 58 | |
| 59 | /** |
| 60 | * The user is navigating with keys (not the touch screen), so |
| 61 | * navigational focus should be shown. |
| 62 | */ |
| 63 | public static final int RELAYOUT_RES_IN_TOUCH_MODE = 0x1; |
| 64 | |
| 65 | /** |
| 66 | * This is the first time the window is being drawn, |
| 67 | * so the client must call drawingFinished() when done |
| 68 | */ |
| 69 | public static final int RELAYOUT_RES_FIRST_TIME = 0x2; |
| 70 | |
| 71 | /** |
| 72 | * The window manager has changed the surface from the last call. |
| 73 | */ |
| 74 | public static final int RELAYOUT_RES_SURFACE_CHANGED = 0x4; |
| 75 | |
| 76 | /** |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 77 | * The window is being resized by dragging on the docked divider. The client should render |
| 78 | * at (0, 0) and extend its background to the background frame passed into |
| 79 | * {@link IWindow#resized}. |
| 80 | */ |
| 81 | public static final int RELAYOUT_RES_DRAG_RESIZING_DOCKED = 0x8; |
| 82 | |
| 83 | /** |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 84 | * The window is being resized by dragging one of the window corners, |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 85 | * in this case the surface would be fullscreen-sized. The client should |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 86 | * render to the actual frame location (instead of (0,curScrollY)). |
| 87 | */ |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 88 | public static final int RELAYOUT_RES_DRAG_RESIZING_FREEFORM = 0x10; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 91 | * The window manager has changed the size of the surface from the last call. |
| 92 | */ |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 93 | public static final int RELAYOUT_RES_SURFACE_RESIZED = 0x20; |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 94 | |
| 95 | /** |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 96 | * In multi-window we force show the navigation bar. Because we don't want that the surface size |
| 97 | * changes in this mode, we instead have a flag whether the navigation bar size should always be |
| 98 | * consumed, so the app is treated like there is no virtual navigation bar at all. |
| 99 | */ |
| 100 | public static final int RELAYOUT_RES_CONSUME_ALWAYS_NAV_BAR = 0x40; |
| 101 | |
| 102 | /** |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 103 | * Flag for relayout: the client will be later giving |
| 104 | * internal insets; as a result, the window will not impact other window |
| 105 | * layouts until the insets are given. |
| 106 | */ |
| 107 | public static final int RELAYOUT_INSETS_PENDING = 0x1; |
| 108 | |
| 109 | /** |
| 110 | * Flag for relayout: the client may be currently using the current surface, |
| 111 | * so if it is to be destroyed as a part of the relayout the destroy must |
| 112 | * be deferred until later. The client will call performDeferredDestroy() |
| 113 | * when it is okay. |
| 114 | */ |
| 115 | public static final int RELAYOUT_DEFER_SURFACE_DESTROY = 0x2; |
| 116 | |
| 117 | public static final int ADD_FLAG_APP_VISIBLE = 0x2; |
| 118 | public static final int ADD_FLAG_IN_TOUCH_MODE = RELAYOUT_RES_IN_TOUCH_MODE; |
| 119 | |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 120 | /** |
| 121 | * Like {@link #RELAYOUT_RES_CONSUME_ALWAYS_NAV_BAR}, but as a "hint" when adding the window. |
| 122 | */ |
| 123 | public static final int ADD_FLAG_ALWAYS_CONSUME_NAV_BAR = 0x4; |
| 124 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 125 | public static final int ADD_OKAY = 0; |
| 126 | public static final int ADD_BAD_APP_TOKEN = -1; |
| 127 | public static final int ADD_BAD_SUBWINDOW_TOKEN = -2; |
| 128 | public static final int ADD_NOT_APP_TOKEN = -3; |
| 129 | public static final int ADD_APP_EXITING = -4; |
| 130 | public static final int ADD_DUPLICATE_ADD = -5; |
| 131 | public static final int ADD_STARTING_NOT_NEEDED = -6; |
| 132 | public static final int ADD_MULTIPLE_SINGLETON = -7; |
| 133 | public static final int ADD_PERMISSION_DENIED = -8; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 134 | public static final int ADD_INVALID_DISPLAY = -9; |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 135 | public static final int ADD_INVALID_TYPE = -10; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 136 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 137 | @UnsupportedAppUsage |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 138 | private static WindowManagerGlobal sDefaultWindowManager; |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 139 | @UnsupportedAppUsage |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 140 | private static IWindowManager sWindowManagerService; |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 141 | @UnsupportedAppUsage |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 142 | private static IWindowSession sWindowSession; |
| 143 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 144 | @UnsupportedAppUsage |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 145 | private final Object mLock = new Object(); |
| 146 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 147 | @UnsupportedAppUsage |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 148 | private final ArrayList<View> mViews = new ArrayList<View>(); |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 149 | @UnsupportedAppUsage |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 150 | private final ArrayList<ViewRootImpl> mRoots = new ArrayList<ViewRootImpl>(); |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 151 | @UnsupportedAppUsage |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 152 | private final ArrayList<WindowManager.LayoutParams> mParams = |
| 153 | new ArrayList<WindowManager.LayoutParams>(); |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 154 | private final ArraySet<View> mDyingViews = new ArraySet<View>(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 155 | |
| 156 | private Runnable mSystemPropertyUpdater; |
| 157 | |
| 158 | private WindowManagerGlobal() { |
| 159 | } |
| 160 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 161 | @UnsupportedAppUsage |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 162 | public static void initialize() { |
| 163 | getWindowManagerService(); |
| 164 | } |
| 165 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 166 | @UnsupportedAppUsage |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 167 | public static WindowManagerGlobal getInstance() { |
| 168 | synchronized (WindowManagerGlobal.class) { |
| 169 | if (sDefaultWindowManager == null) { |
| 170 | sDefaultWindowManager = new WindowManagerGlobal(); |
| 171 | } |
| 172 | return sDefaultWindowManager; |
| 173 | } |
| 174 | } |
| 175 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 176 | @UnsupportedAppUsage |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 177 | public static IWindowManager getWindowManagerService() { |
| 178 | synchronized (WindowManagerGlobal.class) { |
| 179 | if (sWindowManagerService == null) { |
| 180 | sWindowManagerService = IWindowManager.Stub.asInterface( |
| 181 | ServiceManager.getService("window")); |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 182 | try { |
Phil Weaver | 7eec379 | 2017-02-14 16:51:55 -0800 | [diff] [blame] | 183 | if (sWindowManagerService != null) { |
| 184 | ValueAnimator.setDurationScale( |
| 185 | sWindowManagerService.getCurrentAnimatorScale()); |
| 186 | } |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 187 | } catch (RemoteException e) { |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 188 | throw e.rethrowFromSystemServer(); |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 189 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 190 | } |
| 191 | return sWindowManagerService; |
| 192 | } |
| 193 | } |
| 194 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 195 | @UnsupportedAppUsage |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 196 | public static IWindowSession getWindowSession() { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 197 | synchronized (WindowManagerGlobal.class) { |
| 198 | if (sWindowSession == null) { |
| 199 | try { |
Yohei Yukawa | 6c07572 | 2018-09-21 14:52:12 -0700 | [diff] [blame] | 200 | // Emulate the legacy behavior. The global instance of InputMethodManager |
| 201 | // was instantiated here. |
| 202 | // TODO(b/116157766): Remove this hack after cleaning up @UnsupportedAppUsage |
| 203 | InputMethodManager.ensureDefaultInstanceForDefaultDisplayIfNecessary(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 204 | IWindowManager windowManager = getWindowManagerService(); |
| 205 | sWindowSession = windowManager.openSession( |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 206 | new IWindowSessionCallback.Stub() { |
| 207 | @Override |
| 208 | public void onAnimatorScaleChanged(float scale) { |
| 209 | ValueAnimator.setDurationScale(scale); |
| 210 | } |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 211 | }); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 212 | } catch (RemoteException e) { |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 213 | throw e.rethrowFromSystemServer(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | return sWindowSession; |
| 217 | } |
| 218 | } |
| 219 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 220 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 221 | public static IWindowSession peekWindowSession() { |
| 222 | synchronized (WindowManagerGlobal.class) { |
| 223 | return sWindowSession; |
| 224 | } |
| 225 | } |
| 226 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 227 | @UnsupportedAppUsage |
Siva Velusamy | 945bfb6 | 2013-01-06 16:03:12 -0800 | [diff] [blame] | 228 | public String[] getViewRootNames() { |
| 229 | synchronized (mLock) { |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 230 | final int numRoots = mRoots.size(); |
| 231 | String[] mViewRoots = new String[numRoots]; |
| 232 | for (int i = 0; i < numRoots; ++i) { |
| 233 | mViewRoots[i] = getWindowName(mRoots.get(i)); |
Siva Velusamy | 945bfb6 | 2013-01-06 16:03:12 -0800 | [diff] [blame] | 234 | } |
| 235 | return mViewRoots; |
| 236 | } |
| 237 | } |
| 238 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 239 | @UnsupportedAppUsage |
Dianne Hackborn | a7bb6fb | 2015-02-03 18:13:40 -0800 | [diff] [blame] | 240 | public ArrayList<ViewRootImpl> getRootViews(IBinder token) { |
| 241 | ArrayList<ViewRootImpl> views = new ArrayList<>(); |
| 242 | synchronized (mLock) { |
| 243 | final int numRoots = mRoots.size(); |
| 244 | for (int i = 0; i < numRoots; ++i) { |
| 245 | WindowManager.LayoutParams params = mParams.get(i); |
| 246 | if (params.token == null) { |
| 247 | continue; |
| 248 | } |
| 249 | if (params.token != token) { |
| 250 | boolean isChild = false; |
| 251 | if (params.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 252 | && params.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 253 | for (int j = 0 ; j < numRoots; ++j) { |
| 254 | View viewj = mViews.get(j); |
| 255 | WindowManager.LayoutParams paramsj = mParams.get(j); |
| 256 | if (params.token == viewj.getWindowToken() |
| 257 | && paramsj.token == token) { |
| 258 | isChild = true; |
| 259 | break; |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | if (!isChild) { |
| 264 | continue; |
| 265 | } |
| 266 | } |
| 267 | views.add(mRoots.get(i)); |
| 268 | } |
| 269 | } |
| 270 | return views; |
| 271 | } |
| 272 | |
Alan Viverette | 1761cfa | 2019-02-13 17:44:08 -0500 | [diff] [blame] | 273 | /** |
| 274 | * @return the list of all views attached to the global window manager |
| 275 | */ |
| 276 | @NonNull |
| 277 | public ArrayList<View> getWindowViews() { |
| 278 | synchronized (mLock) { |
| 279 | return new ArrayList<>(mViews); |
| 280 | } |
| 281 | } |
| 282 | |
Vladislav Kaznacheev | 7039cbc | 2017-01-04 10:15:31 -0800 | [diff] [blame] | 283 | public View getWindowView(IBinder windowToken) { |
| 284 | synchronized (mLock) { |
| 285 | final int numViews = mViews.size(); |
| 286 | for (int i = 0; i < numViews; ++i) { |
| 287 | final View view = mViews.get(i); |
| 288 | if (view.getWindowToken() == windowToken) { |
| 289 | return view; |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | return null; |
| 294 | } |
| 295 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 296 | @UnsupportedAppUsage |
Siva Velusamy | 945bfb6 | 2013-01-06 16:03:12 -0800 | [diff] [blame] | 297 | public View getRootView(String name) { |
| 298 | synchronized (mLock) { |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 299 | for (int i = mRoots.size() - 1; i >= 0; --i) { |
| 300 | final ViewRootImpl root = mRoots.get(i); |
Siva Velusamy | 945bfb6 | 2013-01-06 16:03:12 -0800 | [diff] [blame] | 301 | if (name.equals(getWindowName(root))) return root.getView(); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | return null; |
| 306 | } |
| 307 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 308 | public void addView(View view, ViewGroup.LayoutParams params, |
| 309 | Display display, Window parentWindow) { |
| 310 | if (view == null) { |
| 311 | throw new IllegalArgumentException("view must not be null"); |
| 312 | } |
| 313 | if (display == null) { |
| 314 | throw new IllegalArgumentException("display must not be null"); |
| 315 | } |
| 316 | if (!(params instanceof WindowManager.LayoutParams)) { |
| 317 | throw new IllegalArgumentException("Params must be WindowManager.LayoutParams"); |
| 318 | } |
| 319 | |
Alan Viverette | 9ecb73c | 2014-12-15 13:40:28 -0800 | [diff] [blame] | 320 | final WindowManager.LayoutParams wparams = (WindowManager.LayoutParams) params; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 321 | if (parentWindow != null) { |
| 322 | parentWindow.adjustLayoutParamsForSubWindow(wparams); |
Alan Viverette | 9b0ab65 | 2015-03-18 14:21:04 -0700 | [diff] [blame] | 323 | } else { |
| 324 | // If there's no parent, then hardware acceleration for this view is |
| 325 | // set from the application's hardware acceleration setting. |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 326 | final Context context = view.getContext(); |
Alan Viverette | 9b0ab65 | 2015-03-18 14:21:04 -0700 | [diff] [blame] | 327 | if (context != null |
Alan Viverette | d70b9e7 | 2015-05-27 14:29:20 -0700 | [diff] [blame] | 328 | && (context.getApplicationInfo().flags |
| 329 | & ApplicationInfo.FLAG_HARDWARE_ACCELERATED) != 0) { |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 330 | wparams.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 331 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | ViewRootImpl root; |
| 335 | View panelParentView = null; |
| 336 | |
| 337 | synchronized (mLock) { |
| 338 | // Start watching for system property changes. |
| 339 | if (mSystemPropertyUpdater == null) { |
| 340 | mSystemPropertyUpdater = new Runnable() { |
| 341 | @Override public void run() { |
| 342 | synchronized (mLock) { |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 343 | for (int i = mRoots.size() - 1; i >= 0; --i) { |
| 344 | mRoots.get(i).loadSystemProperties(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | } |
| 348 | }; |
| 349 | SystemProperties.addChangeCallback(mSystemPropertyUpdater); |
| 350 | } |
| 351 | |
| 352 | int index = findViewLocked(view, false); |
| 353 | if (index >= 0) { |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 354 | if (mDyingViews.contains(view)) { |
| 355 | // Don't wait for MSG_DIE to make it's way through root's queue. |
| 356 | mRoots.get(index).doDie(); |
| 357 | } else { |
| 358 | throw new IllegalStateException("View " + view |
| 359 | + " has already been added to the window manager."); |
| 360 | } |
| 361 | // The previous removeView() had not completed executing. Now it has. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | // If this is a panel window, then find the window it is being |
| 365 | // attached to for future reference. |
| 366 | if (wparams.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW && |
| 367 | wparams.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 368 | final int count = mViews.size(); |
| 369 | for (int i = 0; i < count; i++) { |
| 370 | if (mRoots.get(i).mWindow.asBinder() == wparams.token) { |
| 371 | panelParentView = mViews.get(i); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | root = new ViewRootImpl(view.getContext(), display); |
| 377 | |
| 378 | view.setLayoutParams(wparams); |
| 379 | |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 380 | mViews.add(view); |
| 381 | mRoots.add(root); |
| 382 | mParams.add(wparams); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 383 | |
Gopal Krishna Shukla | f7abcda | 2016-07-06 08:14:59 +0530 | [diff] [blame] | 384 | // do this last because it fires off messages to start doing things |
| 385 | try { |
| 386 | root.setView(view, wparams, panelParentView); |
| 387 | } catch (RuntimeException e) { |
| 388 | // BadTokenException or InvalidDisplayException, clean up. |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 389 | if (index >= 0) { |
| 390 | removeViewLocked(index, true); |
| 391 | } |
Gopal Krishna Shukla | f7abcda | 2016-07-06 08:14:59 +0530 | [diff] [blame] | 392 | throw e; |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 393 | } |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 394 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | public void updateViewLayout(View view, ViewGroup.LayoutParams params) { |
| 398 | if (view == null) { |
| 399 | throw new IllegalArgumentException("view must not be null"); |
| 400 | } |
| 401 | if (!(params instanceof WindowManager.LayoutParams)) { |
| 402 | throw new IllegalArgumentException("Params must be WindowManager.LayoutParams"); |
| 403 | } |
| 404 | |
| 405 | final WindowManager.LayoutParams wparams = (WindowManager.LayoutParams)params; |
| 406 | |
| 407 | view.setLayoutParams(wparams); |
| 408 | |
| 409 | synchronized (mLock) { |
| 410 | int index = findViewLocked(view, true); |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 411 | ViewRootImpl root = mRoots.get(index); |
| 412 | mParams.remove(index); |
| 413 | mParams.add(index, wparams); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 414 | root.setLayoutParams(wparams, false); |
| 415 | } |
| 416 | } |
| 417 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 418 | @UnsupportedAppUsage |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 419 | public void removeView(View view, boolean immediate) { |
| 420 | if (view == null) { |
| 421 | throw new IllegalArgumentException("view must not be null"); |
| 422 | } |
| 423 | |
| 424 | synchronized (mLock) { |
| 425 | int index = findViewLocked(view, true); |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 426 | View curView = mRoots.get(index).getView(); |
Craig Mautner | 05eb730 | 2013-06-03 17:24:21 -0700 | [diff] [blame] | 427 | removeViewLocked(index, immediate); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 428 | if (curView == view) { |
| 429 | return; |
| 430 | } |
| 431 | |
| 432 | throw new IllegalStateException("Calling with view " + view |
| 433 | + " but the ViewAncestor is attached to " + curView); |
| 434 | } |
| 435 | } |
| 436 | |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 437 | /** |
| 438 | * Remove all roots with specified token. |
| 439 | * |
| 440 | * @param token app or window token. |
| 441 | * @param who name of caller, used in logs. |
| 442 | * @param what type of caller, used in logs. |
| 443 | */ |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 444 | public void closeAll(IBinder token, String who, String what) { |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 445 | closeAllExceptView(token, null /* view */, who, what); |
| 446 | } |
| 447 | |
| 448 | /** |
| 449 | * Remove all roots with specified token, except maybe one view. |
| 450 | * |
| 451 | * @param token app or window token. |
| 452 | * @param view view that should be should be preserved along with it's root. |
| 453 | * Pass null if everything should be removed. |
| 454 | * @param who name of caller, used in logs. |
| 455 | * @param what type of caller, used in logs. |
| 456 | */ |
| 457 | public void closeAllExceptView(IBinder token, View view, String who, String what) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 458 | synchronized (mLock) { |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 459 | int count = mViews.size(); |
Craig Mautner | 05eb730 | 2013-06-03 17:24:21 -0700 | [diff] [blame] | 460 | for (int i = 0; i < count; i++) { |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 461 | if ((view == null || mViews.get(i) != view) |
| 462 | && (token == null || mParams.get(i).token == token)) { |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 463 | ViewRootImpl root = mRoots.get(i); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 464 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 465 | if (who != null) { |
| 466 | WindowLeaked leak = new WindowLeaked( |
| 467 | what + " " + who + " has leaked window " |
| 468 | + root.getView() + " that was originally added here"); |
| 469 | leak.setStackTrace(root.getLocation().getStackTrace()); |
Craig Mautner | 05eb730 | 2013-06-03 17:24:21 -0700 | [diff] [blame] | 470 | Log.e(TAG, "", leak); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | removeViewLocked(i, false); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | |
Craig Mautner | 05eb730 | 2013-06-03 17:24:21 -0700 | [diff] [blame] | 479 | private void removeViewLocked(int index, boolean immediate) { |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 480 | ViewRootImpl root = mRoots.get(index); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 481 | View view = root.getView(); |
| 482 | |
| 483 | if (view != null) { |
Yohei Yukawa | 484d4af | 2018-09-17 16:47:08 -0700 | [diff] [blame] | 484 | InputMethodManager imm = view.getContext().getSystemService(InputMethodManager.class); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 485 | if (imm != null) { |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 486 | imm.windowDismissed(mViews.get(index).getWindowToken()); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 487 | } |
| 488 | } |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 489 | boolean deferred = root.die(immediate); |
Craig Mautner | 92098c7 | 2013-06-10 11:27:26 -0700 | [diff] [blame] | 490 | if (view != null) { |
| 491 | view.assignParent(null); |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 492 | if (deferred) { |
| 493 | mDyingViews.add(view); |
| 494 | } |
Craig Mautner | 92098c7 | 2013-06-10 11:27:26 -0700 | [diff] [blame] | 495 | } |
Craig Mautner | 05eb730 | 2013-06-03 17:24:21 -0700 | [diff] [blame] | 496 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 497 | |
Craig Mautner | 05eb730 | 2013-06-03 17:24:21 -0700 | [diff] [blame] | 498 | void doRemoveView(ViewRootImpl root) { |
| 499 | synchronized (mLock) { |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 500 | final int index = mRoots.indexOf(root); |
| 501 | if (index >= 0) { |
| 502 | mRoots.remove(index); |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 503 | mParams.remove(index); |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 504 | final View view = mViews.remove(index); |
| 505 | mDyingViews.remove(view); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 506 | } |
| 507 | } |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 508 | if (ThreadedRenderer.sTrimForeground && ThreadedRenderer.isAvailable()) { |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 509 | doTrimForeground(); |
| 510 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | private int findViewLocked(View view, boolean required) { |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 514 | final int index = mViews.indexOf(view); |
| 515 | if (required && index < 0) { |
Craig Mautner | 05eb730 | 2013-06-03 17:24:21 -0700 | [diff] [blame] | 516 | throw new IllegalArgumentException("View=" + view + " not attached to window manager"); |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 517 | } |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 518 | return index; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 519 | } |
| 520 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 521 | public static boolean shouldDestroyEglContext(int trimLevel) { |
| 522 | // On low-end gfx devices we trim when memory is moderate; |
| 523 | // on high-end devices we do this when low. |
| 524 | if (trimLevel >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE) { |
| 525 | return true; |
| 526 | } |
| 527 | if (trimLevel >= ComponentCallbacks2.TRIM_MEMORY_MODERATE |
| 528 | && !ActivityManager.isHighEndGfx()) { |
| 529 | return true; |
| 530 | } |
| 531 | return false; |
| 532 | } |
| 533 | |
Sergey Vasilinets | 8b8d3b8 | 2019-02-08 14:27:31 +0000 | [diff] [blame] | 534 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 535 | public void trimMemory(int level) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 536 | if (ThreadedRenderer.isAvailable()) { |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 537 | if (shouldDestroyEglContext(level)) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 538 | // Destroy all hardware surfaces and resources associated to |
| 539 | // known windows |
| 540 | synchronized (mLock) { |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 541 | for (int i = mRoots.size() - 1; i >= 0; --i) { |
Romain Guy | 46bfc48 | 2013-08-16 18:38:29 -0700 | [diff] [blame] | 542 | mRoots.get(i).destroyHardwareResources(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 543 | } |
| 544 | } |
| 545 | // Force a full memory flush |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 546 | level = ComponentCallbacks2.TRIM_MEMORY_COMPLETE; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 547 | } |
| 548 | |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 549 | ThreadedRenderer.trimMemory(level); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 550 | |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 551 | if (ThreadedRenderer.sTrimForeground) { |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 552 | doTrimForeground(); |
| 553 | } |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | public static void trimForeground() { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 558 | if (ThreadedRenderer.sTrimForeground && ThreadedRenderer.isAvailable()) { |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 559 | WindowManagerGlobal wm = WindowManagerGlobal.getInstance(); |
| 560 | wm.doTrimForeground(); |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | private void doTrimForeground() { |
| 565 | boolean hasVisibleWindows = false; |
| 566 | synchronized (mLock) { |
| 567 | for (int i = mRoots.size() - 1; i >= 0; --i) { |
John Reck | ccf2fa0 | 2014-09-25 08:33:05 -0700 | [diff] [blame] | 568 | final ViewRootImpl root = mRoots.get(i); |
| 569 | if (root.mView != null && root.getHostVisibility() == View.VISIBLE |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 570 | && root.mAttachInfo.mThreadedRenderer != null) { |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 571 | hasVisibleWindows = true; |
| 572 | } else { |
John Reck | ccf2fa0 | 2014-09-25 08:33:05 -0700 | [diff] [blame] | 573 | root.destroyHardwareResources(); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | } |
| 577 | if (!hasVisibleWindows) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 578 | ThreadedRenderer.trimMemory( |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 579 | ComponentCallbacks2.TRIM_MEMORY_COMPLETE); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 583 | public void dumpGfxInfo(FileDescriptor fd, String[] args) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 584 | FileOutputStream fout = new FileOutputStream(fd); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 585 | PrintWriter pw = new FastPrintWriter(fout); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 586 | try { |
| 587 | synchronized (mLock) { |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 588 | final int count = mViews.size(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 589 | |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 590 | pw.println("Profile data in ms:"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 591 | |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 592 | for (int i = 0; i < count; i++) { |
| 593 | ViewRootImpl root = mRoots.get(i); |
| 594 | String name = getWindowName(root); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 595 | pw.printf("\n\t%s (visibility=%d)", name, root.getHostVisibility()); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 596 | |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 597 | ThreadedRenderer renderer = |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 598 | root.getView().mAttachInfo.mThreadedRenderer; |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 599 | if (renderer != null) { |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 600 | renderer.dumpGfxInfo(pw, fd, args); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 601 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 602 | } |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 603 | |
| 604 | pw.println("\nView hierarchy:\n"); |
| 605 | |
| 606 | int viewsCount = 0; |
| 607 | int displayListsSize = 0; |
| 608 | int[] info = new int[2]; |
| 609 | |
| 610 | for (int i = 0; i < count; i++) { |
| 611 | ViewRootImpl root = mRoots.get(i); |
| 612 | root.dumpGfxInfo(info); |
| 613 | |
| 614 | String name = getWindowName(root); |
| 615 | pw.printf(" %s\n %d views, %.2f kB of display lists", |
| 616 | name, info[0], info[1] / 1024.0f); |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 617 | pw.printf("\n\n"); |
| 618 | |
| 619 | viewsCount += info[0]; |
| 620 | displayListsSize += info[1]; |
| 621 | } |
| 622 | |
| 623 | pw.printf("\nTotal ViewRootImpl: %d\n", count); |
| 624 | pw.printf("Total Views: %d\n", viewsCount); |
| 625 | pw.printf("Total DisplayList: %.2f kB\n\n", displayListsSize / 1024.0f); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 626 | } |
| 627 | } finally { |
| 628 | pw.flush(); |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | private static String getWindowName(ViewRootImpl root) { |
| 633 | return root.mWindowAttributes.getTitle() + "/" + |
| 634 | root.getClass().getName() + '@' + Integer.toHexString(root.hashCode()); |
| 635 | } |
| 636 | |
| 637 | public void setStoppedState(IBinder token, boolean stopped) { |
| 638 | synchronized (mLock) { |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 639 | int count = mViews.size(); |
Tetsutoki Shiozawa | 978e7f8 | 2017-11-01 11:38:34 +0900 | [diff] [blame] | 640 | for (int i = count - 1; i >= 0; i--) { |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 641 | if (token == null || mParams.get(i).token == token) { |
| 642 | ViewRootImpl root = mRoots.get(i); |
Tetsutoki Shiozawa | 978e7f8 | 2017-11-01 11:38:34 +0900 | [diff] [blame] | 643 | // Client might remove the view by "stopped" event. |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 644 | root.setWindowStopped(stopped); |
Robert Carr | 3f7bd97 | 2018-04-02 15:09:10 -0700 | [diff] [blame] | 645 | // Recursively forward stopped state to View's attached |
| 646 | // to this Window rather than the root application token, |
| 647 | // e.g. PopupWindow's. |
| 648 | setStoppedState(root.mAttachInfo.mWindowToken, stopped); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | public void reportNewConfiguration(Configuration config) { |
| 655 | synchronized (mLock) { |
Craig Mautner | 652fdfa | 2013-06-06 07:51:57 -0700 | [diff] [blame] | 656 | int count = mViews.size(); |
| 657 | config = new Configuration(config); |
| 658 | for (int i=0; i < count; i++) { |
| 659 | ViewRootImpl root = mRoots.get(i); |
| 660 | root.requestUpdateConfiguration(config); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 661 | } |
| 662 | } |
| 663 | } |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 664 | |
| 665 | /** @hide */ |
| 666 | public void changeCanvasOpacity(IBinder token, boolean opaque) { |
| 667 | if (token == null) { |
| 668 | return; |
| 669 | } |
| 670 | synchronized (mLock) { |
| 671 | for (int i = mParams.size() - 1; i >= 0; --i) { |
| 672 | if (mParams.get(i).token == token) { |
| 673 | mRoots.get(i).changeCanvasOpacity(opaque); |
| 674 | return; |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | final class WindowLeaked extends AndroidRuntimeException { |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 682 | @UnsupportedAppUsage |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 683 | public WindowLeaked(String msg) { |
| 684 | super(msg); |
| 685 | } |
| 686 | } |