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