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