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