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