Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Phil Weaver | d321075e | 2017-06-13 09:13:35 -0700 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY; |
Robert Carr | 132c9f5 | 2017-07-31 17:02:30 -0700 | [diff] [blame] | 20 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY; |
Phil Weaver | d321075e | 2017-06-13 09:13:35 -0700 | [diff] [blame] | 21 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 22 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 23 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 24 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 25 | import android.animation.ObjectAnimator; |
| 26 | import android.animation.ValueAnimator; |
Alan Viverette | 59e53a1 | 2016-03-28 13:41:32 -0400 | [diff] [blame] | 27 | import android.annotation.NonNull; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 28 | import android.app.Service; |
| 29 | import android.content.Context; |
| 30 | import android.graphics.Canvas; |
| 31 | import android.graphics.Color; |
| 32 | import android.graphics.Matrix; |
| 33 | import android.graphics.Paint; |
| 34 | import android.graphics.Path; |
| 35 | import android.graphics.PixelFormat; |
| 36 | import android.graphics.Point; |
| 37 | import android.graphics.PorterDuff.Mode; |
| 38 | import android.graphics.Rect; |
| 39 | import android.graphics.RectF; |
| 40 | import android.graphics.Region; |
| 41 | import android.os.Handler; |
| 42 | import android.os.IBinder; |
| 43 | import android.os.Looper; |
| 44 | import android.os.Message; |
Phil Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 45 | import android.text.TextUtils; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 46 | import android.util.ArraySet; |
| 47 | import android.util.Log; |
| 48 | import android.util.Slog; |
| 49 | import android.util.SparseArray; |
| 50 | import android.util.TypedValue; |
| 51 | import android.view.MagnificationSpec; |
| 52 | import android.view.Surface; |
| 53 | import android.view.Surface.OutOfResourcesException; |
| 54 | import android.view.SurfaceControl; |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 55 | import android.view.ViewConfiguration; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 56 | import android.view.WindowInfo; |
| 57 | import android.view.WindowManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 58 | import android.view.animation.DecelerateInterpolator; |
| 59 | import android.view.animation.Interpolator; |
| 60 | |
| 61 | import com.android.internal.R; |
| 62 | import com.android.internal.os.SomeArgs; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 63 | import com.android.server.policy.WindowManagerPolicy; |
| 64 | import com.android.server.wm.WindowManagerInternal.MagnificationCallbacks; |
| 65 | import com.android.server.wm.WindowManagerInternal.WindowsForAccessibilityCallback; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 66 | |
| 67 | import java.util.ArrayList; |
Allen Hair | f20ac2c | 2016-02-11 17:42:59 -0800 | [diff] [blame] | 68 | import java.util.HashSet; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 69 | import java.util.List; |
| 70 | import java.util.Set; |
| 71 | |
| 72 | /** |
| 73 | * This class contains the accessibility related logic of the window manger. |
| 74 | */ |
| 75 | final class AccessibilityController { |
| 76 | |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 77 | private final WindowManagerService mService; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 78 | |
| 79 | private static final float[] sTempFloats = new float[9]; |
| 80 | |
| 81 | public AccessibilityController(WindowManagerService service) { |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 82 | mService = service; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | private DisplayMagnifier mDisplayMagnifier; |
| 86 | |
| 87 | private WindowsForAccessibilityObserver mWindowsForAccessibilityObserver; |
| 88 | |
| 89 | public void setMagnificationCallbacksLocked(MagnificationCallbacks callbacks) { |
| 90 | if (callbacks != null) { |
| 91 | if (mDisplayMagnifier != null) { |
| 92 | throw new IllegalStateException("Magnification callbacks already set!"); |
| 93 | } |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 94 | mDisplayMagnifier = new DisplayMagnifier(mService, callbacks); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 95 | } else { |
| 96 | if (mDisplayMagnifier == null) { |
| 97 | throw new IllegalStateException("Magnification callbacks already cleared!"); |
| 98 | } |
| 99 | mDisplayMagnifier.destroyLocked(); |
| 100 | mDisplayMagnifier = null; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | public void setWindowsForAccessibilityCallback(WindowsForAccessibilityCallback callback) { |
| 105 | if (callback != null) { |
| 106 | if (mWindowsForAccessibilityObserver != null) { |
| 107 | throw new IllegalStateException( |
| 108 | "Windows for accessibility callback already set!"); |
| 109 | } |
| 110 | mWindowsForAccessibilityObserver = new WindowsForAccessibilityObserver( |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 111 | mService, callback); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 112 | } else { |
| 113 | if (mWindowsForAccessibilityObserver == null) { |
| 114 | throw new IllegalStateException( |
| 115 | "Windows for accessibility callback already cleared!"); |
| 116 | } |
| 117 | mWindowsForAccessibilityObserver = null; |
| 118 | } |
| 119 | } |
| 120 | |
Svetoslav Ganov | fd13889 | 2016-07-13 18:20:42 -0700 | [diff] [blame] | 121 | public void performComputeChangedWindowsNotLocked() { |
| 122 | WindowsForAccessibilityObserver observer = null; |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 123 | synchronized (mService) { |
Svetoslav Ganov | fd13889 | 2016-07-13 18:20:42 -0700 | [diff] [blame] | 124 | observer = mWindowsForAccessibilityObserver; |
| 125 | } |
| 126 | if (observer != null) { |
| 127 | observer.performComputeChangedWindowsNotLocked(); |
| 128 | } |
| 129 | } |
| 130 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 131 | public void setMagnificationSpecLocked(MagnificationSpec spec) { |
| 132 | if (mDisplayMagnifier != null) { |
| 133 | mDisplayMagnifier.setMagnificationSpecLocked(spec); |
| 134 | } |
| 135 | if (mWindowsForAccessibilityObserver != null) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 136 | mWindowsForAccessibilityObserver.scheduleComputeChangedWindowsLocked(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 140 | public void getMagnificationRegionLocked(Region outMagnificationRegion) { |
Alan Viverette | 59e53a1 | 2016-03-28 13:41:32 -0400 | [diff] [blame] | 141 | if (mDisplayMagnifier != null) { |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 142 | mDisplayMagnifier.getMagnificationRegionLocked(outMagnificationRegion); |
Alan Viverette | 59e53a1 | 2016-03-28 13:41:32 -0400 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 146 | public void onRectangleOnScreenRequestedLocked(Rect rectangle) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 147 | if (mDisplayMagnifier != null) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 148 | mDisplayMagnifier.onRectangleOnScreenRequestedLocked(rectangle); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 149 | } |
| 150 | // Not relevant for the window observer. |
| 151 | } |
| 152 | |
| 153 | public void onWindowLayersChangedLocked() { |
| 154 | if (mDisplayMagnifier != null) { |
| 155 | mDisplayMagnifier.onWindowLayersChangedLocked(); |
| 156 | } |
| 157 | if (mWindowsForAccessibilityObserver != null) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 158 | mWindowsForAccessibilityObserver.scheduleComputeChangedWindowsLocked(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 162 | public void onRotationChangedLocked(DisplayContent displayContent) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 163 | if (mDisplayMagnifier != null) { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 164 | mDisplayMagnifier.onRotationChangedLocked(displayContent); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 165 | } |
| 166 | if (mWindowsForAccessibilityObserver != null) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 167 | mWindowsForAccessibilityObserver.scheduleComputeChangedWindowsLocked(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
| 171 | public void onAppWindowTransitionLocked(WindowState windowState, int transition) { |
| 172 | if (mDisplayMagnifier != null) { |
| 173 | mDisplayMagnifier.onAppWindowTransitionLocked(windowState, transition); |
| 174 | } |
| 175 | // Not relevant for the window observer. |
| 176 | } |
| 177 | |
| 178 | public void onWindowTransitionLocked(WindowState windowState, int transition) { |
| 179 | if (mDisplayMagnifier != null) { |
| 180 | mDisplayMagnifier.onWindowTransitionLocked(windowState, transition); |
| 181 | } |
| 182 | if (mWindowsForAccessibilityObserver != null) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 183 | mWindowsForAccessibilityObserver.scheduleComputeChangedWindowsLocked(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
Svetoslav | 3a0d878 | 2014-12-04 12:50:11 -0800 | [diff] [blame] | 187 | public void onWindowFocusChangedNotLocked() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 188 | // Not relevant for the display magnifier. |
| 189 | |
Svetoslav | 3a0d878 | 2014-12-04 12:50:11 -0800 | [diff] [blame] | 190 | WindowsForAccessibilityObserver observer = null; |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 191 | synchronized (mService) { |
Svetoslav | 3a0d878 | 2014-12-04 12:50:11 -0800 | [diff] [blame] | 192 | observer = mWindowsForAccessibilityObserver; |
| 193 | } |
| 194 | if (observer != null) { |
| 195 | observer.performComputeChangedWindowsNotLocked(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
Svetoslav | 4604abc | 2014-06-10 18:59:30 -0700 | [diff] [blame] | 199 | |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 200 | public void onSomeWindowResizedOrMovedLocked() { |
Svetoslav | 4604abc | 2014-06-10 18:59:30 -0700 | [diff] [blame] | 201 | // Not relevant for the display magnifier. |
| 202 | |
| 203 | if (mWindowsForAccessibilityObserver != null) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 204 | mWindowsForAccessibilityObserver.scheduleComputeChangedWindowsLocked(); |
Svetoslav | 4604abc | 2014-06-10 18:59:30 -0700 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 208 | /** NOTE: This has to be called within a surface transaction. */ |
| 209 | public void drawMagnifiedRegionBorderIfNeededLocked() { |
| 210 | if (mDisplayMagnifier != null) { |
| 211 | mDisplayMagnifier.drawMagnifiedRegionBorderIfNeededLocked(); |
| 212 | } |
| 213 | // Not relevant for the window observer. |
| 214 | } |
| 215 | |
| 216 | public MagnificationSpec getMagnificationSpecForWindowLocked(WindowState windowState) { |
| 217 | if (mDisplayMagnifier != null) { |
| 218 | return mDisplayMagnifier.getMagnificationSpecForWindowLocked(windowState); |
| 219 | } |
| 220 | return null; |
| 221 | } |
| 222 | |
| 223 | public boolean hasCallbacksLocked() { |
| 224 | return (mDisplayMagnifier != null |
| 225 | || mWindowsForAccessibilityObserver != null); |
| 226 | } |
| 227 | |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 228 | public void setForceShowMagnifiableBoundsLocked(boolean show) { |
| 229 | if (mDisplayMagnifier != null) { |
| 230 | mDisplayMagnifier.setForceShowMagnifiableBoundsLocked(show); |
Phil Weaver | 251db07 | 2017-03-28 08:35:38 -0700 | [diff] [blame] | 231 | mDisplayMagnifier.showMagnificationBoundsIfNeeded(); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 235 | private static void populateTransformationMatrixLocked(WindowState windowState, |
| 236 | Matrix outMatrix) { |
Jorim Jaggi | eb0d3bc | 2017-12-15 14:56:19 +0100 | [diff] [blame^] | 237 | windowState.getTransformationMatrix(sTempFloats, outMatrix); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /** |
| 241 | * This class encapsulates the functionality related to display magnification. |
| 242 | */ |
| 243 | private static final class DisplayMagnifier { |
| 244 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 245 | private static final String LOG_TAG = TAG_WITH_CLASS_NAME ? "DisplayMagnifier" : TAG_WM; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 246 | |
| 247 | private static final boolean DEBUG_WINDOW_TRANSITIONS = false; |
| 248 | private static final boolean DEBUG_ROTATION = false; |
| 249 | private static final boolean DEBUG_LAYERS = false; |
| 250 | private static final boolean DEBUG_RECTANGLE_REQUESTED = false; |
| 251 | private static final boolean DEBUG_VIEWPORT_WINDOW = false; |
| 252 | |
| 253 | private final Rect mTempRect1 = new Rect(); |
| 254 | private final Rect mTempRect2 = new Rect(); |
| 255 | |
| 256 | private final Region mTempRegion1 = new Region(); |
| 257 | private final Region mTempRegion2 = new Region(); |
| 258 | private final Region mTempRegion3 = new Region(); |
| 259 | private final Region mTempRegion4 = new Region(); |
| 260 | |
| 261 | private final Context mContext; |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 262 | private final WindowManagerService mService; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 263 | private final MagnifiedViewport mMagnifedViewport; |
| 264 | private final Handler mHandler; |
| 265 | |
| 266 | private final MagnificationCallbacks mCallbacks; |
| 267 | |
| 268 | private final long mLongAnimationDuration; |
| 269 | |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 270 | private boolean mForceShowMagnifiableBounds = false; |
| 271 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 272 | public DisplayMagnifier(WindowManagerService windowManagerService, |
| 273 | MagnificationCallbacks callbacks) { |
| 274 | mContext = windowManagerService.mContext; |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 275 | mService = windowManagerService; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 276 | mCallbacks = callbacks; |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 277 | mHandler = new MyHandler(mService.mH.getLooper()); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 278 | mMagnifedViewport = new MagnifiedViewport(); |
| 279 | mLongAnimationDuration = mContext.getResources().getInteger( |
| 280 | com.android.internal.R.integer.config_longAnimTime); |
| 281 | } |
| 282 | |
| 283 | public void setMagnificationSpecLocked(MagnificationSpec spec) { |
| 284 | mMagnifedViewport.updateMagnificationSpecLocked(spec); |
| 285 | mMagnifedViewport.recomputeBoundsLocked(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 286 | |
| 287 | mService.applyMagnificationSpec(spec); |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 288 | mService.scheduleAnimationLocked(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 289 | } |
| 290 | |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 291 | public void setForceShowMagnifiableBoundsLocked(boolean show) { |
| 292 | mForceShowMagnifiableBounds = show; |
| 293 | mMagnifedViewport.setMagnifiedRegionBorderShownLocked(show, true); |
| 294 | } |
| 295 | |
| 296 | public boolean isForceShowingMagnifiableBoundsLocked() { |
| 297 | return mForceShowMagnifiableBounds; |
| 298 | } |
| 299 | |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 300 | public void onRectangleOnScreenRequestedLocked(Rect rectangle) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 301 | if (DEBUG_RECTANGLE_REQUESTED) { |
| 302 | Slog.i(LOG_TAG, "Rectangle on screen requested: " + rectangle); |
| 303 | } |
| 304 | if (!mMagnifedViewport.isMagnifyingLocked()) { |
| 305 | return; |
| 306 | } |
| 307 | Rect magnifiedRegionBounds = mTempRect2; |
| 308 | mMagnifedViewport.getMagnifiedFrameInContentCoordsLocked(magnifiedRegionBounds); |
| 309 | if (magnifiedRegionBounds.contains(rectangle)) { |
| 310 | return; |
| 311 | } |
| 312 | SomeArgs args = SomeArgs.obtain(); |
| 313 | args.argi1 = rectangle.left; |
| 314 | args.argi2 = rectangle.top; |
| 315 | args.argi3 = rectangle.right; |
| 316 | args.argi4 = rectangle.bottom; |
| 317 | mHandler.obtainMessage(MyHandler.MESSAGE_NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED, |
| 318 | args).sendToTarget(); |
| 319 | } |
| 320 | |
| 321 | public void onWindowLayersChangedLocked() { |
| 322 | if (DEBUG_LAYERS) { |
| 323 | Slog.i(LOG_TAG, "Layers changed."); |
| 324 | } |
| 325 | mMagnifedViewport.recomputeBoundsLocked(); |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 326 | mService.scheduleAnimationLocked(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 327 | } |
| 328 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 329 | public void onRotationChangedLocked(DisplayContent displayContent) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 330 | if (DEBUG_ROTATION) { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 331 | final int rotation = displayContent.getRotation(); |
| 332 | Slog.i(LOG_TAG, "Rotation: " + Surface.rotationToString(rotation) |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 333 | + " displayId: " + displayContent.getDisplayId()); |
| 334 | } |
| 335 | mMagnifedViewport.onRotationChangedLocked(); |
| 336 | mHandler.sendEmptyMessage(MyHandler.MESSAGE_NOTIFY_ROTATION_CHANGED); |
| 337 | } |
| 338 | |
| 339 | public void onAppWindowTransitionLocked(WindowState windowState, int transition) { |
| 340 | if (DEBUG_WINDOW_TRANSITIONS) { |
| 341 | Slog.i(LOG_TAG, "Window transition: " |
| 342 | + AppTransition.appTransitionToString(transition) |
| 343 | + " displayId: " + windowState.getDisplayId()); |
| 344 | } |
| 345 | final boolean magnifying = mMagnifedViewport.isMagnifyingLocked(); |
| 346 | if (magnifying) { |
| 347 | switch (transition) { |
| 348 | case AppTransition.TRANSIT_ACTIVITY_OPEN: |
| 349 | case AppTransition.TRANSIT_TASK_OPEN: |
| 350 | case AppTransition.TRANSIT_TASK_TO_FRONT: |
| 351 | case AppTransition.TRANSIT_WALLPAPER_OPEN: |
| 352 | case AppTransition.TRANSIT_WALLPAPER_CLOSE: |
| 353 | case AppTransition.TRANSIT_WALLPAPER_INTRA_OPEN: { |
| 354 | mHandler.sendEmptyMessage(MyHandler.MESSAGE_NOTIFY_USER_CONTEXT_CHANGED); |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | public void onWindowTransitionLocked(WindowState windowState, int transition) { |
| 361 | if (DEBUG_WINDOW_TRANSITIONS) { |
| 362 | Slog.i(LOG_TAG, "Window transition: " |
| 363 | + AppTransition.appTransitionToString(transition) |
| 364 | + " displayId: " + windowState.getDisplayId()); |
| 365 | } |
| 366 | final boolean magnifying = mMagnifedViewport.isMagnifyingLocked(); |
| 367 | final int type = windowState.mAttrs.type; |
| 368 | switch (transition) { |
| 369 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 370 | case WindowManagerPolicy.TRANSIT_SHOW: { |
| 371 | if (!magnifying) { |
| 372 | break; |
| 373 | } |
| 374 | switch (type) { |
| 375 | case WindowManager.LayoutParams.TYPE_APPLICATION: |
Chong Zhang | fea963e | 2016-08-15 17:14:16 -0700 | [diff] [blame] | 376 | case WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION: |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 377 | case WindowManager.LayoutParams.TYPE_APPLICATION_PANEL: |
| 378 | case WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA: |
| 379 | case WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL: |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 380 | case WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL: |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 381 | case WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG: |
| 382 | case WindowManager.LayoutParams.TYPE_SEARCH_BAR: |
| 383 | case WindowManager.LayoutParams.TYPE_PHONE: |
| 384 | case WindowManager.LayoutParams.TYPE_SYSTEM_ALERT: |
| 385 | case WindowManager.LayoutParams.TYPE_TOAST: |
| 386 | case WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY: |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 387 | case WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY: |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 388 | case WindowManager.LayoutParams.TYPE_PRIORITY_PHONE: |
| 389 | case WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG: |
| 390 | case WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG: |
| 391 | case WindowManager.LayoutParams.TYPE_SYSTEM_ERROR: |
| 392 | case WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY: |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 393 | case WindowManager.LayoutParams.TYPE_QS_DIALOG: |
Adrian Roos | 9a64513 | 2014-10-08 02:59:56 +0200 | [diff] [blame] | 394 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL: { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 395 | Rect magnifiedRegionBounds = mTempRect2; |
| 396 | mMagnifedViewport.getMagnifiedFrameInContentCoordsLocked( |
| 397 | magnifiedRegionBounds); |
| 398 | Rect touchableRegionBounds = mTempRect1; |
| 399 | windowState.getTouchableRegion(mTempRegion1); |
| 400 | mTempRegion1.getBounds(touchableRegionBounds); |
| 401 | if (!magnifiedRegionBounds.intersect(touchableRegionBounds)) { |
| 402 | mCallbacks.onRectangleOnScreenRequested( |
| 403 | touchableRegionBounds.left, |
| 404 | touchableRegionBounds.top, |
| 405 | touchableRegionBounds.right, |
| 406 | touchableRegionBounds.bottom); |
| 407 | } |
| 408 | } break; |
| 409 | } break; |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | public MagnificationSpec getMagnificationSpecForWindowLocked(WindowState windowState) { |
| 415 | MagnificationSpec spec = mMagnifedViewport.getMagnificationSpecLocked(); |
| 416 | if (spec != null && !spec.isNop()) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 417 | if (!windowState.shouldMagnify()) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 418 | return null; |
| 419 | } |
| 420 | } |
| 421 | return spec; |
| 422 | } |
| 423 | |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 424 | public void getMagnificationRegionLocked(Region outMagnificationRegion) { |
Phil Weaver | 53b690b | 2017-08-14 17:42:39 -0700 | [diff] [blame] | 425 | // Make sure we're working with the most current bounds |
| 426 | mMagnifedViewport.recomputeBoundsLocked(); |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 427 | mMagnifedViewport.getMagnificationRegionLocked(outMagnificationRegion); |
Alan Viverette | 59e53a1 | 2016-03-28 13:41:32 -0400 | [diff] [blame] | 428 | } |
| 429 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 430 | public void destroyLocked() { |
| 431 | mMagnifedViewport.destroyWindow(); |
| 432 | } |
| 433 | |
Phil Weaver | 251db07 | 2017-03-28 08:35:38 -0700 | [diff] [blame] | 434 | // Can be called outside of a surface transaction |
| 435 | public void showMagnificationBoundsIfNeeded() { |
| 436 | mHandler.obtainMessage(MyHandler.MESSAGE_SHOW_MAGNIFIED_REGION_BOUNDS_IF_NEEDED) |
| 437 | .sendToTarget(); |
| 438 | } |
| 439 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 440 | /** NOTE: This has to be called within a surface transaction. */ |
| 441 | public void drawMagnifiedRegionBorderIfNeededLocked() { |
| 442 | mMagnifedViewport.drawWindowIfNeededLocked(); |
| 443 | } |
| 444 | |
| 445 | private final class MagnifiedViewport { |
| 446 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 447 | private final SparseArray<WindowState> mTempWindowStates = |
| 448 | new SparseArray<WindowState>(); |
| 449 | |
| 450 | private final RectF mTempRectF = new RectF(); |
| 451 | |
| 452 | private final Point mTempPoint = new Point(); |
| 453 | |
| 454 | private final Matrix mTempMatrix = new Matrix(); |
| 455 | |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 456 | private final Region mMagnificationRegion = new Region(); |
| 457 | private final Region mOldMagnificationRegion = new Region(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 458 | |
Casey Burkhardt | d29a1e4 | 2015-02-12 14:07:55 -0800 | [diff] [blame] | 459 | private final Path mCircularPath; |
| 460 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 461 | private final MagnificationSpec mMagnificationSpec = MagnificationSpec.obtain(); |
| 462 | |
| 463 | private final WindowManager mWindowManager; |
| 464 | |
Svetoslav | 7505e33 | 2014-08-22 12:14:28 -0700 | [diff] [blame] | 465 | private final float mBorderWidth; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 466 | private final int mHalfBorderWidth; |
Svetoslav | 7505e33 | 2014-08-22 12:14:28 -0700 | [diff] [blame] | 467 | private final int mDrawBorderInset; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 468 | |
| 469 | private final ViewportWindow mWindow; |
| 470 | |
| 471 | private boolean mFullRedrawNeeded; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 472 | private int mTempLayer = 0; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 473 | |
| 474 | public MagnifiedViewport() { |
| 475 | mWindowManager = (WindowManager) mContext.getSystemService(Service.WINDOW_SERVICE); |
Casey Burkhardt | d29a1e4 | 2015-02-12 14:07:55 -0800 | [diff] [blame] | 476 | mBorderWidth = mContext.getResources().getDimension( |
| 477 | com.android.internal.R.dimen.accessibility_magnification_indicator_width); |
Svetoslav | 7505e33 | 2014-08-22 12:14:28 -0700 | [diff] [blame] | 478 | mHalfBorderWidth = (int) Math.ceil(mBorderWidth / 2); |
| 479 | mDrawBorderInset = (int) mBorderWidth / 2; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 480 | mWindow = new ViewportWindow(mContext); |
Casey Burkhardt | d29a1e4 | 2015-02-12 14:07:55 -0800 | [diff] [blame] | 481 | |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 482 | if (mContext.getResources().getConfiguration().isScreenRound()) { |
Casey Burkhardt | d29a1e4 | 2015-02-12 14:07:55 -0800 | [diff] [blame] | 483 | mCircularPath = new Path(); |
| 484 | mWindowManager.getDefaultDisplay().getRealSize(mTempPoint); |
| 485 | final int centerXY = mTempPoint.x / 2; |
| 486 | mCircularPath.addCircle(centerXY, centerXY, centerXY, Path.Direction.CW); |
| 487 | } else { |
| 488 | mCircularPath = null; |
| 489 | } |
| 490 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 491 | recomputeBoundsLocked(); |
| 492 | } |
| 493 | |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 494 | public void getMagnificationRegionLocked(@NonNull Region outMagnificationRegion) { |
| 495 | outMagnificationRegion.set(mMagnificationRegion); |
Alan Viverette | 59e53a1 | 2016-03-28 13:41:32 -0400 | [diff] [blame] | 496 | } |
| 497 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 498 | public void updateMagnificationSpecLocked(MagnificationSpec spec) { |
| 499 | if (spec != null) { |
| 500 | mMagnificationSpec.initialize(spec.scale, spec.offsetX, spec.offsetY); |
| 501 | } else { |
| 502 | mMagnificationSpec.clear(); |
| 503 | } |
| 504 | // If this message is pending we are in a rotation animation and do not want |
| 505 | // to show the border. We will do so when the pending message is handled. |
Svetoslav | 7505e33 | 2014-08-22 12:14:28 -0700 | [diff] [blame] | 506 | if (!mHandler.hasMessages( |
| 507 | MyHandler.MESSAGE_SHOW_MAGNIFIED_REGION_BOUNDS_IF_NEEDED)) { |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 508 | setMagnifiedRegionBorderShownLocked( |
| 509 | isMagnifyingLocked() || isForceShowingMagnifiableBoundsLocked(), true); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
| 513 | public void recomputeBoundsLocked() { |
| 514 | mWindowManager.getDefaultDisplay().getRealSize(mTempPoint); |
| 515 | final int screenWidth = mTempPoint.x; |
| 516 | final int screenHeight = mTempPoint.y; |
| 517 | |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 518 | mMagnificationRegion.set(0, 0, 0, 0); |
| 519 | final Region availableBounds = mTempRegion1; |
| 520 | availableBounds.set(0, 0, screenWidth, screenHeight); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 521 | |
Casey Burkhardt | d29a1e4 | 2015-02-12 14:07:55 -0800 | [diff] [blame] | 522 | if (mCircularPath != null) { |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 523 | availableBounds.setPath(mCircularPath, availableBounds); |
Casey Burkhardt | d29a1e4 | 2015-02-12 14:07:55 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 526 | Region nonMagnifiedBounds = mTempRegion4; |
Svet Ganov | b21df80 | 2014-09-01 19:06:33 -0700 | [diff] [blame] | 527 | nonMagnifiedBounds.set(0, 0, 0, 0); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 528 | |
| 529 | SparseArray<WindowState> visibleWindows = mTempWindowStates; |
| 530 | visibleWindows.clear(); |
| 531 | populateWindowsOnScreenLocked(visibleWindows); |
| 532 | |
| 533 | final int visibleWindowCount = visibleWindows.size(); |
| 534 | for (int i = visibleWindowCount - 1; i >= 0; i--) { |
| 535 | WindowState windowState = visibleWindows.valueAt(i); |
Phil Weaver | d321075e | 2017-06-13 09:13:35 -0700 | [diff] [blame] | 536 | if ((windowState.mAttrs.type == TYPE_MAGNIFICATION_OVERLAY) |
| 537 | || ((windowState.mAttrs.privateFlags |
Robert Carr | 132c9f5 | 2017-07-31 17:02:30 -0700 | [diff] [blame] | 538 | & PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY) != 0)) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 539 | continue; |
| 540 | } |
| 541 | |
Phil Weaver | 65c0670 | 2016-03-15 15:33:46 -0700 | [diff] [blame] | 542 | // Consider the touchable portion of the window |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 543 | Matrix matrix = mTempMatrix; |
| 544 | populateTransformationMatrixLocked(windowState, matrix); |
Phil Weaver | 65c0670 | 2016-03-15 15:33:46 -0700 | [diff] [blame] | 545 | Region touchableRegion = mTempRegion3; |
| 546 | windowState.getTouchableRegion(touchableRegion); |
| 547 | Rect touchableFrame = mTempRect1; |
| 548 | touchableRegion.getBounds(touchableFrame); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 549 | RectF windowFrame = mTempRectF; |
Phil Weaver | 65c0670 | 2016-03-15 15:33:46 -0700 | [diff] [blame] | 550 | windowFrame.set(touchableFrame); |
| 551 | windowFrame.offset(-windowState.mFrame.left, -windowState.mFrame.top); |
| 552 | matrix.mapRect(windowFrame); |
| 553 | Region windowBounds = mTempRegion2; |
| 554 | windowBounds.set((int) windowFrame.left, (int) windowFrame.top, |
| 555 | (int) windowFrame.right, (int) windowFrame.bottom); |
| 556 | // Only update new regions |
| 557 | Region portionOfWindowAlreadyAccountedFor = mTempRegion3; |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 558 | portionOfWindowAlreadyAccountedFor.set(mMagnificationRegion); |
Phil Weaver | 65c0670 | 2016-03-15 15:33:46 -0700 | [diff] [blame] | 559 | portionOfWindowAlreadyAccountedFor.op(nonMagnifiedBounds, Region.Op.UNION); |
| 560 | windowBounds.op(portionOfWindowAlreadyAccountedFor, Region.Op.DIFFERENCE); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 561 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 562 | if (windowState.shouldMagnify()) { |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 563 | mMagnificationRegion.op(windowBounds, Region.Op.UNION); |
| 564 | mMagnificationRegion.op(availableBounds, Region.Op.INTERSECT); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 565 | } else { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 566 | nonMagnifiedBounds.op(windowBounds, Region.Op.UNION); |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 567 | availableBounds.op(windowBounds, Region.Op.DIFFERENCE); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 568 | } |
| 569 | |
Phil Weaver | 65c0670 | 2016-03-15 15:33:46 -0700 | [diff] [blame] | 570 | // Update accounted bounds |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 571 | Region accountedBounds = mTempRegion2; |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 572 | accountedBounds.set(mMagnificationRegion); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 573 | accountedBounds.op(nonMagnifiedBounds, Region.Op.UNION); |
| 574 | accountedBounds.op(0, 0, screenWidth, screenHeight, Region.Op.INTERSECT); |
| 575 | |
| 576 | if (accountedBounds.isRect()) { |
| 577 | Rect accountedFrame = mTempRect1; |
| 578 | accountedBounds.getBounds(accountedFrame); |
| 579 | if (accountedFrame.width() == screenWidth |
| 580 | && accountedFrame.height() == screenHeight) { |
| 581 | break; |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | visibleWindows.clear(); |
| 587 | |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 588 | mMagnificationRegion.op(mDrawBorderInset, mDrawBorderInset, |
Svetoslav | 7505e33 | 2014-08-22 12:14:28 -0700 | [diff] [blame] | 589 | screenWidth - mDrawBorderInset, screenHeight - mDrawBorderInset, |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 590 | Region.Op.INTERSECT); |
| 591 | |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 592 | final boolean magnifiedChanged = |
| 593 | !mOldMagnificationRegion.equals(mMagnificationRegion); |
| 594 | if (magnifiedChanged) { |
| 595 | mWindow.setBounds(mMagnificationRegion); |
| 596 | final Rect dirtyRect = mTempRect1; |
| 597 | if (mFullRedrawNeeded) { |
| 598 | mFullRedrawNeeded = false; |
| 599 | dirtyRect.set(mDrawBorderInset, mDrawBorderInset, |
| 600 | screenWidth - mDrawBorderInset, |
| 601 | screenHeight - mDrawBorderInset); |
| 602 | mWindow.invalidate(dirtyRect); |
| 603 | } else { |
| 604 | final Region dirtyRegion = mTempRegion3; |
| 605 | dirtyRegion.set(mMagnificationRegion); |
| 606 | dirtyRegion.op(mOldMagnificationRegion, Region.Op.UNION); |
| 607 | dirtyRegion.op(nonMagnifiedBounds, Region.Op.INTERSECT); |
| 608 | dirtyRegion.getBounds(dirtyRect); |
| 609 | mWindow.invalidate(dirtyRect); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 610 | } |
| 611 | |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 612 | mOldMagnificationRegion.set(mMagnificationRegion); |
Alan Viverette | 214fb68 | 2015-11-17 09:47:11 -0500 | [diff] [blame] | 613 | final SomeArgs args = SomeArgs.obtain(); |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 614 | args.arg1 = Region.obtain(mMagnificationRegion); |
Alan Viverette | 214fb68 | 2015-11-17 09:47:11 -0500 | [diff] [blame] | 615 | mHandler.obtainMessage( |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 616 | MyHandler.MESSAGE_NOTIFY_MAGNIFICATION_REGION_CHANGED, args) |
| 617 | .sendToTarget(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | |
| 621 | public void onRotationChangedLocked() { |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 622 | // If we are showing the magnification border, hide it immediately so |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 623 | // the user does not see strange artifacts during rotation. The screenshot |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 624 | // used for rotation already has the border. After the rotation is complete |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 625 | // we will show the border. |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 626 | if (isMagnifyingLocked() || isForceShowingMagnifiableBoundsLocked()) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 627 | setMagnifiedRegionBorderShownLocked(false, false); |
| 628 | final long delay = (long) (mLongAnimationDuration |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 629 | * mService.getWindowAnimationScaleLocked()); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 630 | Message message = mHandler.obtainMessage( |
| 631 | MyHandler.MESSAGE_SHOW_MAGNIFIED_REGION_BOUNDS_IF_NEEDED); |
| 632 | mHandler.sendMessageDelayed(message, delay); |
| 633 | } |
| 634 | recomputeBoundsLocked(); |
| 635 | mWindow.updateSize(); |
| 636 | } |
| 637 | |
| 638 | public void setMagnifiedRegionBorderShownLocked(boolean shown, boolean animate) { |
| 639 | if (shown) { |
| 640 | mFullRedrawNeeded = true; |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 641 | mOldMagnificationRegion.set(0, 0, 0, 0); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 642 | } |
| 643 | mWindow.setShown(shown, animate); |
| 644 | } |
| 645 | |
| 646 | public void getMagnifiedFrameInContentCoordsLocked(Rect rect) { |
| 647 | MagnificationSpec spec = mMagnificationSpec; |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 648 | mMagnificationRegion.getBounds(rect); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 649 | rect.offset((int) -spec.offsetX, (int) -spec.offsetY); |
| 650 | rect.scale(1.0f / spec.scale); |
| 651 | } |
| 652 | |
| 653 | public boolean isMagnifyingLocked() { |
| 654 | return mMagnificationSpec.scale > 1.0f; |
| 655 | } |
| 656 | |
| 657 | public MagnificationSpec getMagnificationSpecLocked() { |
| 658 | return mMagnificationSpec; |
| 659 | } |
| 660 | |
| 661 | /** NOTE: This has to be called within a surface transaction. */ |
| 662 | public void drawWindowIfNeededLocked() { |
| 663 | recomputeBoundsLocked(); |
| 664 | mWindow.drawIfNeeded(); |
| 665 | } |
| 666 | |
| 667 | public void destroyWindow() { |
| 668 | mWindow.releaseSurface(); |
| 669 | } |
| 670 | |
| 671 | private void populateWindowsOnScreenLocked(SparseArray<WindowState> outWindows) { |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 672 | final DisplayContent dc = mService.getDefaultDisplayContentLocked(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 673 | mTempLayer = 0; |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 674 | dc.forAllWindows((w) -> { |
| 675 | if (w.isOnScreen() && w.isVisibleLw() |
| 676 | && !w.mWinAnimator.mEnterAnimationPending) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 677 | mTempLayer++; |
| 678 | outWindows.put(mTempLayer, w); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 679 | } |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 680 | }, false /* traverseTopToBottom */ ); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | private final class ViewportWindow { |
| 684 | private static final String SURFACE_TITLE = "Magnification Overlay"; |
| 685 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 686 | private final Region mBounds = new Region(); |
| 687 | private final Rect mDirtyRect = new Rect(); |
| 688 | private final Paint mPaint = new Paint(); |
| 689 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 690 | private final SurfaceControl mSurfaceControl; |
| 691 | private final Surface mSurface = new Surface(); |
| 692 | |
Svet Ganov | b21df80 | 2014-09-01 19:06:33 -0700 | [diff] [blame] | 693 | private final AnimationController mAnimationController; |
| 694 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 695 | private boolean mShown; |
| 696 | private int mAlpha; |
| 697 | |
| 698 | private boolean mInvalidated; |
| 699 | |
| 700 | public ViewportWindow(Context context) { |
| 701 | SurfaceControl surfaceControl = null; |
| 702 | try { |
| 703 | mWindowManager.getDefaultDisplay().getRealSize(mTempPoint); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 704 | surfaceControl = mService.getDefaultDisplayContentLocked().makeOverlay() |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 705 | .setName(SURFACE_TITLE) |
| 706 | .setSize(mTempPoint.x, mTempPoint.y) // not a typo |
| 707 | .setFormat(PixelFormat.TRANSLUCENT) |
| 708 | .build(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 709 | } catch (OutOfResourcesException oore) { |
| 710 | /* ignore */ |
| 711 | } |
| 712 | mSurfaceControl = surfaceControl; |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 713 | mSurfaceControl.setLayer(mService.mPolicy.getWindowLayerFromTypeLw( |
Phil Weaver | d321075e | 2017-06-13 09:13:35 -0700 | [diff] [blame] | 714 | TYPE_MAGNIFICATION_OVERLAY) |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 715 | * WindowManagerService.TYPE_LAYER_MULTIPLIER); |
| 716 | mSurfaceControl.setPosition(0, 0); |
| 717 | mSurface.copyFrom(mSurfaceControl); |
| 718 | |
Svet Ganov | b21df80 | 2014-09-01 19:06:33 -0700 | [diff] [blame] | 719 | mAnimationController = new AnimationController(context, |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 720 | mService.mH.getLooper()); |
Svet Ganov | b21df80 | 2014-09-01 19:06:33 -0700 | [diff] [blame] | 721 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 722 | TypedValue typedValue = new TypedValue(); |
| 723 | context.getTheme().resolveAttribute(R.attr.colorActivatedHighlight, |
| 724 | typedValue, true); |
Alan Viverette | 4a357cd | 2015-03-18 18:37:18 -0700 | [diff] [blame] | 725 | final int borderColor = context.getColor(typedValue.resourceId); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 726 | |
| 727 | mPaint.setStyle(Paint.Style.STROKE); |
| 728 | mPaint.setStrokeWidth(mBorderWidth); |
| 729 | mPaint.setColor(borderColor); |
| 730 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 731 | mInvalidated = true; |
| 732 | } |
| 733 | |
| 734 | public void setShown(boolean shown, boolean animate) { |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 735 | synchronized (mService.mWindowMap) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 736 | if (mShown == shown) { |
| 737 | return; |
| 738 | } |
| 739 | mShown = shown; |
Svet Ganov | b21df80 | 2014-09-01 19:06:33 -0700 | [diff] [blame] | 740 | mAnimationController.onFrameShownStateChanged(shown, animate); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 741 | if (DEBUG_VIEWPORT_WINDOW) { |
| 742 | Slog.i(LOG_TAG, "ViewportWindow shown: " + mShown); |
| 743 | } |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | @SuppressWarnings("unused") |
| 748 | // Called reflectively from an animator. |
| 749 | public int getAlpha() { |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 750 | synchronized (mService.mWindowMap) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 751 | return mAlpha; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | public void setAlpha(int alpha) { |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 756 | synchronized (mService.mWindowMap) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 757 | if (mAlpha == alpha) { |
| 758 | return; |
| 759 | } |
| 760 | mAlpha = alpha; |
| 761 | invalidate(null); |
| 762 | if (DEBUG_VIEWPORT_WINDOW) { |
| 763 | Slog.i(LOG_TAG, "ViewportWindow set alpha: " + alpha); |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | public void setBounds(Region bounds) { |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 769 | synchronized (mService.mWindowMap) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 770 | if (mBounds.equals(bounds)) { |
| 771 | return; |
| 772 | } |
| 773 | mBounds.set(bounds); |
| 774 | invalidate(mDirtyRect); |
| 775 | if (DEBUG_VIEWPORT_WINDOW) { |
| 776 | Slog.i(LOG_TAG, "ViewportWindow set bounds: " + bounds); |
| 777 | } |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | public void updateSize() { |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 782 | synchronized (mService.mWindowMap) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 783 | mWindowManager.getDefaultDisplay().getRealSize(mTempPoint); |
| 784 | mSurfaceControl.setSize(mTempPoint.x, mTempPoint.y); |
| 785 | invalidate(mDirtyRect); |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | public void invalidate(Rect dirtyRect) { |
| 790 | if (dirtyRect != null) { |
| 791 | mDirtyRect.set(dirtyRect); |
| 792 | } else { |
| 793 | mDirtyRect.setEmpty(); |
| 794 | } |
| 795 | mInvalidated = true; |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 796 | mService.scheduleAnimationLocked(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | /** NOTE: This has to be called within a surface transaction. */ |
| 800 | public void drawIfNeeded() { |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 801 | synchronized (mService.mWindowMap) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 802 | if (!mInvalidated) { |
| 803 | return; |
| 804 | } |
| 805 | mInvalidated = false; |
| 806 | Canvas canvas = null; |
| 807 | try { |
| 808 | // Empty dirty rectangle means unspecified. |
| 809 | if (mDirtyRect.isEmpty()) { |
| 810 | mBounds.getBounds(mDirtyRect); |
| 811 | } |
| 812 | mDirtyRect.inset(- mHalfBorderWidth, - mHalfBorderWidth); |
| 813 | canvas = mSurface.lockCanvas(mDirtyRect); |
| 814 | if (DEBUG_VIEWPORT_WINDOW) { |
| 815 | Slog.i(LOG_TAG, "Dirty rect: " + mDirtyRect); |
| 816 | } |
| 817 | } catch (IllegalArgumentException iae) { |
| 818 | /* ignore */ |
| 819 | } catch (Surface.OutOfResourcesException oore) { |
| 820 | /* ignore */ |
| 821 | } |
| 822 | if (canvas == null) { |
| 823 | return; |
| 824 | } |
| 825 | if (DEBUG_VIEWPORT_WINDOW) { |
| 826 | Slog.i(LOG_TAG, "Bounds: " + mBounds); |
| 827 | } |
| 828 | canvas.drawColor(Color.TRANSPARENT, Mode.CLEAR); |
| 829 | mPaint.setAlpha(mAlpha); |
| 830 | Path path = mBounds.getBoundaryPath(); |
| 831 | canvas.drawPath(path, mPaint); |
| 832 | |
| 833 | mSurface.unlockCanvasAndPost(canvas); |
| 834 | |
| 835 | if (mAlpha > 0) { |
| 836 | mSurfaceControl.show(); |
| 837 | } else { |
| 838 | mSurfaceControl.hide(); |
| 839 | } |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | public void releaseSurface() { |
| 844 | mSurfaceControl.release(); |
| 845 | mSurface.release(); |
| 846 | } |
Svet Ganov | b21df80 | 2014-09-01 19:06:33 -0700 | [diff] [blame] | 847 | |
| 848 | private final class AnimationController extends Handler { |
| 849 | private static final String PROPERTY_NAME_ALPHA = "alpha"; |
| 850 | |
| 851 | private static final int MIN_ALPHA = 0; |
| 852 | private static final int MAX_ALPHA = 255; |
| 853 | |
| 854 | private static final int MSG_FRAME_SHOWN_STATE_CHANGED = 1; |
| 855 | |
| 856 | private final ValueAnimator mShowHideFrameAnimator; |
| 857 | |
| 858 | public AnimationController(Context context, Looper looper) { |
| 859 | super(looper); |
| 860 | mShowHideFrameAnimator = ObjectAnimator.ofInt(ViewportWindow.this, |
| 861 | PROPERTY_NAME_ALPHA, MIN_ALPHA, MAX_ALPHA); |
| 862 | |
| 863 | Interpolator interpolator = new DecelerateInterpolator(2.5f); |
| 864 | final long longAnimationDuration = context.getResources().getInteger( |
| 865 | com.android.internal.R.integer.config_longAnimTime); |
| 866 | |
| 867 | mShowHideFrameAnimator.setInterpolator(interpolator); |
| 868 | mShowHideFrameAnimator.setDuration(longAnimationDuration); |
| 869 | } |
| 870 | |
| 871 | public void onFrameShownStateChanged(boolean shown, boolean animate) { |
| 872 | obtainMessage(MSG_FRAME_SHOWN_STATE_CHANGED, |
| 873 | shown ? 1 : 0, animate ? 1 : 0).sendToTarget(); |
| 874 | } |
| 875 | |
| 876 | @Override |
| 877 | public void handleMessage(Message message) { |
| 878 | switch (message.what) { |
| 879 | case MSG_FRAME_SHOWN_STATE_CHANGED: { |
| 880 | final boolean shown = message.arg1 == 1; |
| 881 | final boolean animate = message.arg2 == 1; |
| 882 | |
| 883 | if (animate) { |
| 884 | if (mShowHideFrameAnimator.isRunning()) { |
| 885 | mShowHideFrameAnimator.reverse(); |
| 886 | } else { |
| 887 | if (shown) { |
| 888 | mShowHideFrameAnimator.start(); |
| 889 | } else { |
| 890 | mShowHideFrameAnimator.reverse(); |
| 891 | } |
| 892 | } |
| 893 | } else { |
| 894 | mShowHideFrameAnimator.cancel(); |
| 895 | if (shown) { |
| 896 | setAlpha(MAX_ALPHA); |
| 897 | } else { |
| 898 | setAlpha(MIN_ALPHA); |
| 899 | } |
| 900 | } |
| 901 | } break; |
| 902 | } |
| 903 | } |
| 904 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 905 | } |
| 906 | } |
| 907 | |
| 908 | private class MyHandler extends Handler { |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 909 | public static final int MESSAGE_NOTIFY_MAGNIFICATION_REGION_CHANGED = 1; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 910 | public static final int MESSAGE_NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED = 2; |
| 911 | public static final int MESSAGE_NOTIFY_USER_CONTEXT_CHANGED = 3; |
| 912 | public static final int MESSAGE_NOTIFY_ROTATION_CHANGED = 4; |
| 913 | public static final int MESSAGE_SHOW_MAGNIFIED_REGION_BOUNDS_IF_NEEDED = 5; |
| 914 | |
| 915 | public MyHandler(Looper looper) { |
| 916 | super(looper); |
| 917 | } |
| 918 | |
| 919 | @Override |
| 920 | public void handleMessage(Message message) { |
| 921 | switch (message.what) { |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 922 | case MESSAGE_NOTIFY_MAGNIFICATION_REGION_CHANGED: { |
Alan Viverette | 214fb68 | 2015-11-17 09:47:11 -0500 | [diff] [blame] | 923 | final SomeArgs args = (SomeArgs) message.obj; |
| 924 | final Region magnifiedBounds = (Region) args.arg1; |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 925 | mCallbacks.onMagnificationRegionChanged(magnifiedBounds); |
Alan Viverette | 214fb68 | 2015-11-17 09:47:11 -0500 | [diff] [blame] | 926 | magnifiedBounds.recycle(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 927 | } break; |
| 928 | |
| 929 | case MESSAGE_NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED: { |
| 930 | SomeArgs args = (SomeArgs) message.obj; |
| 931 | final int left = args.argi1; |
| 932 | final int top = args.argi2; |
| 933 | final int right = args.argi3; |
| 934 | final int bottom = args.argi4; |
| 935 | mCallbacks.onRectangleOnScreenRequested(left, top, right, bottom); |
| 936 | args.recycle(); |
| 937 | } break; |
| 938 | |
| 939 | case MESSAGE_NOTIFY_USER_CONTEXT_CHANGED: { |
| 940 | mCallbacks.onUserContextChanged(); |
| 941 | } break; |
| 942 | |
| 943 | case MESSAGE_NOTIFY_ROTATION_CHANGED: { |
| 944 | final int rotation = message.arg1; |
| 945 | mCallbacks.onRotationChanged(rotation); |
| 946 | } break; |
| 947 | |
| 948 | case MESSAGE_SHOW_MAGNIFIED_REGION_BOUNDS_IF_NEEDED : { |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 949 | synchronized (mService.mWindowMap) { |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 950 | if (mMagnifedViewport.isMagnifyingLocked() |
| 951 | || isForceShowingMagnifiableBoundsLocked()) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 952 | mMagnifedViewport.setMagnifiedRegionBorderShownLocked(true, true); |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 953 | mService.scheduleAnimationLocked(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 954 | } |
| 955 | } |
| 956 | } break; |
| 957 | } |
| 958 | } |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | /** |
| 963 | * This class encapsulates the functionality related to computing the windows |
| 964 | * reported for accessibility purposes. These windows are all windows a sighted |
| 965 | * user can see on the screen. |
| 966 | */ |
| 967 | private static final class WindowsForAccessibilityObserver { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 968 | private static final String LOG_TAG = TAG_WITH_CLASS_NAME ? |
| 969 | "WindowsForAccessibilityObserver" : TAG_WM; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 970 | |
| 971 | private static final boolean DEBUG = false; |
| 972 | |
| 973 | private final SparseArray<WindowState> mTempWindowStates = |
| 974 | new SparseArray<WindowState>(); |
| 975 | |
| 976 | private final List<WindowInfo> mOldWindows = new ArrayList<WindowInfo>(); |
| 977 | |
| 978 | private final Set<IBinder> mTempBinderSet = new ArraySet<IBinder>(); |
| 979 | |
| 980 | private final RectF mTempRectF = new RectF(); |
| 981 | |
| 982 | private final Matrix mTempMatrix = new Matrix(); |
| 983 | |
| 984 | private final Point mTempPoint = new Point(); |
| 985 | |
| 986 | private final Rect mTempRect = new Rect(); |
| 987 | |
| 988 | private final Region mTempRegion = new Region(); |
| 989 | |
| 990 | private final Region mTempRegion1 = new Region(); |
| 991 | |
| 992 | private final Context mContext; |
| 993 | |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 994 | private final WindowManagerService mService; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 995 | |
| 996 | private final Handler mHandler; |
| 997 | |
| 998 | private final WindowsForAccessibilityCallback mCallback; |
| 999 | |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1000 | private final long mRecurringAccessibilityEventsIntervalMillis; |
| 1001 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1002 | private int mTempLayer = 0; |
| 1003 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1004 | public WindowsForAccessibilityObserver(WindowManagerService windowManagerService, |
| 1005 | WindowsForAccessibilityCallback callback) { |
| 1006 | mContext = windowManagerService.mContext; |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 1007 | mService = windowManagerService; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1008 | mCallback = callback; |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 1009 | mHandler = new MyHandler(mService.mH.getLooper()); |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1010 | mRecurringAccessibilityEventsIntervalMillis = ViewConfiguration |
| 1011 | .getSendRecurringAccessibilityEventsInterval(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1012 | computeChangedWindows(); |
| 1013 | } |
| 1014 | |
Svetoslav | 3a0d878 | 2014-12-04 12:50:11 -0800 | [diff] [blame] | 1015 | public void performComputeChangedWindowsNotLocked() { |
| 1016 | mHandler.removeMessages(MyHandler.MESSAGE_COMPUTE_CHANGED_WINDOWS); |
| 1017 | computeChangedWindows(); |
| 1018 | } |
| 1019 | |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1020 | public void scheduleComputeChangedWindowsLocked() { |
Svetoslav | 3a0d878 | 2014-12-04 12:50:11 -0800 | [diff] [blame] | 1021 | if (!mHandler.hasMessages(MyHandler.MESSAGE_COMPUTE_CHANGED_WINDOWS)) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1022 | mHandler.sendEmptyMessageDelayed(MyHandler.MESSAGE_COMPUTE_CHANGED_WINDOWS, |
| 1023 | mRecurringAccessibilityEventsIntervalMillis); |
| 1024 | } |
| 1025 | } |
| 1026 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1027 | public void computeChangedWindows() { |
| 1028 | if (DEBUG) { |
| 1029 | Slog.i(LOG_TAG, "computeChangedWindows()"); |
| 1030 | } |
| 1031 | |
Svetoslav | 3a0d878 | 2014-12-04 12:50:11 -0800 | [diff] [blame] | 1032 | boolean windowsChanged = false; |
| 1033 | List<WindowInfo> windows = new ArrayList<WindowInfo>(); |
| 1034 | |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 1035 | synchronized (mService.mWindowMap) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1036 | // Do not send the windows if there is no current focus as |
| 1037 | // the window manager is still looking for where to put it. |
| 1038 | // We will do the work when we get a focus change callback. |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 1039 | if (mService.mCurrentFocus == null) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1040 | return; |
| 1041 | } |
| 1042 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1043 | WindowManager windowManager = (WindowManager) |
| 1044 | mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1045 | windowManager.getDefaultDisplay().getRealSize(mTempPoint); |
| 1046 | final int screenWidth = mTempPoint.x; |
| 1047 | final int screenHeight = mTempPoint.y; |
| 1048 | |
| 1049 | Region unaccountedSpace = mTempRegion; |
| 1050 | unaccountedSpace.set(0, 0, screenWidth, screenHeight); |
| 1051 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1052 | final SparseArray<WindowState> visibleWindows = mTempWindowStates; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1053 | populateVisibleWindowsOnScreenLocked(visibleWindows); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1054 | Set<IBinder> addedWindows = mTempBinderSet; |
| 1055 | addedWindows.clear(); |
| 1056 | |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1057 | boolean focusedWindowAdded = false; |
| 1058 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1059 | final int visibleWindowCount = visibleWindows.size(); |
Allen Hair | f20ac2c | 2016-02-11 17:42:59 -0800 | [diff] [blame] | 1060 | HashSet<Integer> skipRemainingWindowsForTasks = new HashSet<>(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1061 | for (int i = visibleWindowCount - 1; i >= 0; i--) { |
Alan Viverette | 9538eea | 2014-11-13 14:49:20 -0800 | [diff] [blame] | 1062 | final WindowState windowState = visibleWindows.valueAt(i); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1063 | final int flags = windowState.mAttrs.flags; |
Allen Hair | f20ac2c | 2016-02-11 17:42:59 -0800 | [diff] [blame] | 1064 | final Task task = windowState.getTask(); |
| 1065 | |
| 1066 | // If the window is part of a task that we're finished with - ignore. |
| 1067 | if (task != null && skipRemainingWindowsForTasks.contains(task.mTaskId)) { |
| 1068 | continue; |
| 1069 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1070 | |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 1071 | // If the window is not touchable - ignore. |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1072 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1073 | continue; |
| 1074 | } |
| 1075 | |
Alan Viverette | 9538eea | 2014-11-13 14:49:20 -0800 | [diff] [blame] | 1076 | // Compute the bounds in the screen. |
| 1077 | final Rect boundsInScreen = mTempRect; |
| 1078 | computeWindowBoundsInScreen(windowState, boundsInScreen); |
| 1079 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1080 | // If the window is completely covered by other windows - ignore. |
| 1081 | if (unaccountedSpace.quickReject(boundsInScreen)) { |
| 1082 | continue; |
| 1083 | } |
| 1084 | |
| 1085 | // Add windows of certain types not covered by modal windows. |
| 1086 | if (isReportedWindowType(windowState.mAttrs.type)) { |
| 1087 | // Add the window to the ones to be reported. |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1088 | WindowInfo window = obtainPopulatedWindowInfo(windowState, boundsInScreen); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1089 | window.layer = addedWindows.size(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1090 | addedWindows.add(window.token); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1091 | windows.add(window); |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1092 | if (windowState.isFocused()) { |
| 1093 | focusedWindowAdded = true; |
| 1094 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1095 | } |
| 1096 | |
Alan Viverette | d0c73f4 | 2014-11-18 10:25:04 -0800 | [diff] [blame] | 1097 | // Account for the space this window takes if the window |
| 1098 | // is not an accessibility overlay which does not change |
| 1099 | // the reported windows. |
| 1100 | if (windowState.mAttrs.type != |
| 1101 | WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY) { |
| 1102 | unaccountedSpace.op(boundsInScreen, unaccountedSpace, |
| 1103 | Region.Op.REVERSE_DIFFERENCE); |
| 1104 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1105 | |
Allen Hair | f20ac2c | 2016-02-11 17:42:59 -0800 | [diff] [blame] | 1106 | // If a window is modal it prevents other windows from being touched |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1107 | if ((flags & (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1108 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL)) == 0) { |
Phil Weaver | ac9ad70 | 2016-07-27 18:03:10 -0700 | [diff] [blame] | 1109 | // Account for all space in the task, whether the windows in it are |
| 1110 | // touchable or not. The modal window blocks all touches from the task's |
| 1111 | // area. |
| 1112 | unaccountedSpace.op(windowState.getDisplayFrameLw(), unaccountedSpace, |
| 1113 | Region.Op.REVERSE_DIFFERENCE); |
| 1114 | |
Allen Hair | f20ac2c | 2016-02-11 17:42:59 -0800 | [diff] [blame] | 1115 | if (task != null) { |
| 1116 | // If the window is associated with a particular task, we can skip the |
| 1117 | // rest of the windows for that task. |
| 1118 | skipRemainingWindowsForTasks.add(task.mTaskId); |
| 1119 | continue; |
| 1120 | } else { |
| 1121 | // If the window is not associated with a particular task, then it is |
| 1122 | // globally modal. In this case we can skip all remaining windows. |
| 1123 | break; |
| 1124 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1125 | } |
Phil Weaver | ac9ad70 | 2016-07-27 18:03:10 -0700 | [diff] [blame] | 1126 | // We figured out what is touchable for the entire screen - done. |
| 1127 | if (unaccountedSpace.isEmpty()) { |
| 1128 | break; |
| 1129 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1130 | } |
| 1131 | |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1132 | // Always report the focused window. |
| 1133 | if (!focusedWindowAdded) { |
| 1134 | for (int i = visibleWindowCount - 1; i >= 0; i--) { |
| 1135 | WindowState windowState = visibleWindows.valueAt(i); |
| 1136 | if (windowState.isFocused()) { |
| 1137 | // Compute the bounds in the screen. |
| 1138 | Rect boundsInScreen = mTempRect; |
| 1139 | computeWindowBoundsInScreen(windowState, boundsInScreen); |
| 1140 | |
| 1141 | // Add the window to the ones to be reported. |
| 1142 | WindowInfo window = obtainPopulatedWindowInfo(windowState, |
| 1143 | boundsInScreen); |
| 1144 | addedWindows.add(window.token); |
| 1145 | windows.add(window); |
| 1146 | break; |
| 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1151 | // Remove child/parent references to windows that were not added. |
| 1152 | final int windowCount = windows.size(); |
| 1153 | for (int i = 0; i < windowCount; i++) { |
| 1154 | WindowInfo window = windows.get(i); |
| 1155 | if (!addedWindows.contains(window.parentToken)) { |
| 1156 | window.parentToken = null; |
| 1157 | } |
| 1158 | if (window.childTokens != null) { |
| 1159 | final int childTokenCount = window.childTokens.size(); |
| 1160 | for (int j = childTokenCount - 1; j >= 0; j--) { |
| 1161 | if (!addedWindows.contains(window.childTokens.get(j))) { |
| 1162 | window.childTokens.remove(j); |
| 1163 | } |
| 1164 | } |
| 1165 | // Leave the child token list if empty. |
| 1166 | } |
| 1167 | } |
| 1168 | |
| 1169 | visibleWindows.clear(); |
| 1170 | addedWindows.clear(); |
| 1171 | |
| 1172 | // We computed the windows and if they changed notify the client. |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1173 | if (mOldWindows.size() != windows.size()) { |
| 1174 | // Different size means something changed. |
| 1175 | windowsChanged = true; |
| 1176 | } else if (!mOldWindows.isEmpty() || !windows.isEmpty()) { |
| 1177 | // Since we always traverse windows from high to low layer |
| 1178 | // the old and new windows at the same index should be the |
| 1179 | // same, otherwise something changed. |
| 1180 | for (int i = 0; i < windowCount; i++) { |
| 1181 | WindowInfo oldWindow = mOldWindows.get(i); |
| 1182 | WindowInfo newWindow = windows.get(i); |
| 1183 | // We do not care for layer changes given the window |
| 1184 | // order does not change. This brings no new information |
| 1185 | // to the clients. |
| 1186 | if (windowChangedNoLayer(oldWindow, newWindow)) { |
| 1187 | windowsChanged = true; |
| 1188 | break; |
| 1189 | } |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | if (windowsChanged) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1194 | cacheWindows(windows); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1195 | } |
| 1196 | } |
Svetoslav | 3a0d878 | 2014-12-04 12:50:11 -0800 | [diff] [blame] | 1197 | |
| 1198 | // Now we do not hold the lock, so send the windows over. |
| 1199 | if (windowsChanged) { |
| 1200 | if (DEBUG) { |
| 1201 | Log.i(LOG_TAG, "Windows changed:" + windows); |
| 1202 | } |
| 1203 | mCallback.onWindowsForAccessibilityChanged(windows); |
| 1204 | } else { |
| 1205 | if (DEBUG) { |
| 1206 | Log.i(LOG_TAG, "No windows changed."); |
| 1207 | } |
| 1208 | } |
| 1209 | |
| 1210 | // Recycle the windows as we do not need them. |
| 1211 | clearAndRecycleWindows(windows); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1212 | } |
| 1213 | |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1214 | private void computeWindowBoundsInScreen(WindowState windowState, Rect outBounds) { |
| 1215 | // Get the touchable frame. |
| 1216 | Region touchableRegion = mTempRegion1; |
| 1217 | windowState.getTouchableRegion(touchableRegion); |
| 1218 | Rect touchableFrame = mTempRect; |
| 1219 | touchableRegion.getBounds(touchableFrame); |
| 1220 | |
| 1221 | // Move to origin as all transforms are captured by the matrix. |
| 1222 | RectF windowFrame = mTempRectF; |
| 1223 | windowFrame.set(touchableFrame); |
| 1224 | windowFrame.offset(-windowState.mFrame.left, -windowState.mFrame.top); |
| 1225 | |
| 1226 | // Map the frame to get what appears on the screen. |
| 1227 | Matrix matrix = mTempMatrix; |
| 1228 | populateTransformationMatrixLocked(windowState, matrix); |
| 1229 | matrix.mapRect(windowFrame); |
| 1230 | |
| 1231 | // Got the bounds. |
| 1232 | outBounds.set((int) windowFrame.left, (int) windowFrame.top, |
| 1233 | (int) windowFrame.right, (int) windowFrame.bottom); |
| 1234 | } |
| 1235 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1236 | private static WindowInfo obtainPopulatedWindowInfo( |
| 1237 | WindowState windowState, Rect boundsInScreen) { |
| 1238 | final WindowInfo window = windowState.getWindowInfo(); |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1239 | window.boundsInScreen.set(boundsInScreen); |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1240 | return window; |
| 1241 | } |
| 1242 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1243 | private void cacheWindows(List<WindowInfo> windows) { |
| 1244 | final int oldWindowCount = mOldWindows.size(); |
| 1245 | for (int i = oldWindowCount - 1; i >= 0; i--) { |
| 1246 | mOldWindows.remove(i).recycle(); |
| 1247 | } |
| 1248 | final int newWindowCount = windows.size(); |
| 1249 | for (int i = 0; i < newWindowCount; i++) { |
| 1250 | WindowInfo newWindow = windows.get(i); |
| 1251 | mOldWindows.add(WindowInfo.obtain(newWindow)); |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | private boolean windowChangedNoLayer(WindowInfo oldWindow, WindowInfo newWindow) { |
| 1256 | if (oldWindow == newWindow) { |
| 1257 | return false; |
| 1258 | } |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1259 | if (oldWindow == null) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1260 | return true; |
| 1261 | } |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1262 | if (newWindow == null) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1263 | return true; |
| 1264 | } |
| 1265 | if (oldWindow.type != newWindow.type) { |
| 1266 | return true; |
| 1267 | } |
| 1268 | if (oldWindow.focused != newWindow.focused) { |
| 1269 | return true; |
| 1270 | } |
| 1271 | if (oldWindow.token == null) { |
| 1272 | if (newWindow.token != null) { |
| 1273 | return true; |
| 1274 | } |
| 1275 | } else if (!oldWindow.token.equals(newWindow.token)) { |
| 1276 | return true; |
| 1277 | } |
| 1278 | if (oldWindow.parentToken == null) { |
| 1279 | if (newWindow.parentToken != null) { |
| 1280 | return true; |
| 1281 | } |
| 1282 | } else if (!oldWindow.parentToken.equals(newWindow.parentToken)) { |
| 1283 | return true; |
| 1284 | } |
| 1285 | if (!oldWindow.boundsInScreen.equals(newWindow.boundsInScreen)) { |
| 1286 | return true; |
| 1287 | } |
| 1288 | if (oldWindow.childTokens != null && newWindow.childTokens != null |
| 1289 | && !oldWindow.childTokens.equals(newWindow.childTokens)) { |
| 1290 | return true; |
| 1291 | } |
Phil Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 1292 | if (!TextUtils.equals(oldWindow.title, newWindow.title)) { |
| 1293 | return true; |
| 1294 | } |
| 1295 | if (oldWindow.accessibilityIdOfAnchor != newWindow.accessibilityIdOfAnchor) { |
| 1296 | return true; |
| 1297 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1298 | return false; |
| 1299 | } |
| 1300 | |
Svetoslav | 3a0d878 | 2014-12-04 12:50:11 -0800 | [diff] [blame] | 1301 | private static void clearAndRecycleWindows(List<WindowInfo> windows) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1302 | final int windowCount = windows.size(); |
| 1303 | for (int i = windowCount - 1; i >= 0; i--) { |
| 1304 | windows.remove(i).recycle(); |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | private static boolean isReportedWindowType(int windowType) { |
Jorim Jaggi | 73294b6 | 2016-10-26 18:02:36 -0700 | [diff] [blame] | 1309 | return (windowType != WindowManager.LayoutParams.TYPE_WALLPAPER |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1310 | && windowType != WindowManager.LayoutParams.TYPE_BOOT_PROGRESS |
| 1311 | && windowType != WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY |
| 1312 | && windowType != WindowManager.LayoutParams.TYPE_DRAG |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1313 | && windowType != WindowManager.LayoutParams.TYPE_INPUT_CONSUMER |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1314 | && windowType != WindowManager.LayoutParams.TYPE_POINTER |
Phil Weaver | d321075e | 2017-06-13 09:13:35 -0700 | [diff] [blame] | 1315 | && windowType != TYPE_MAGNIFICATION_OVERLAY |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1316 | && windowType != WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY |
| 1317 | && windowType != WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY |
| 1318 | && windowType != WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION); |
| 1319 | } |
| 1320 | |
| 1321 | private void populateVisibleWindowsOnScreenLocked(SparseArray<WindowState> outWindows) { |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 1322 | final DisplayContent dc = mService.getDefaultDisplayContentLocked(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1323 | mTempLayer = 0; |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 1324 | dc.forAllWindows((w) -> { |
| 1325 | if (w.isVisibleLw()) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1326 | outWindows.put(mTempLayer++, w); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1327 | } |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 1328 | }, false /* traverseTopToBottom */ ); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | private class MyHandler extends Handler { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1332 | public static final int MESSAGE_COMPUTE_CHANGED_WINDOWS = 1; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1333 | |
| 1334 | public MyHandler(Looper looper) { |
| 1335 | super(looper, null, false); |
| 1336 | } |
| 1337 | |
| 1338 | @Override |
| 1339 | @SuppressWarnings("unchecked") |
| 1340 | public void handleMessage(Message message) { |
| 1341 | switch (message.what) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1342 | case MESSAGE_COMPUTE_CHANGED_WINDOWS: { |
| 1343 | computeChangedWindows(); |
| 1344 | } break; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | } |
| 1348 | } |
| 1349 | } |