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(); |
| 652 | final ReadOnlyWindowList windowList = dc.getReadOnlyWindowList(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 653 | final int windowCount = windowList.size(); |
| 654 | for (int i = 0; i < windowCount; i++) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame^] | 655 | final WindowState windowState = windowList.get(i); |
Phil Weaver | 473af05 | 2016-09-30 18:11:39 -0700 | [diff] [blame] | 656 | if (windowState.isOnScreen() && windowState.isVisibleLw() && |
Craig Mautner | 165be0c | 2015-01-27 15:16:58 -0800 | [diff] [blame] | 657 | !windowState.mWinAnimator.mEnterAnimationPending) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 658 | outWindows.put(windowState.mLayer, windowState); |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | private final class ViewportWindow { |
| 664 | private static final String SURFACE_TITLE = "Magnification Overlay"; |
| 665 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 666 | private final Region mBounds = new Region(); |
| 667 | private final Rect mDirtyRect = new Rect(); |
| 668 | private final Paint mPaint = new Paint(); |
| 669 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 670 | private final SurfaceControl mSurfaceControl; |
| 671 | private final Surface mSurface = new Surface(); |
| 672 | |
Svet Ganov | b21df80 | 2014-09-01 19:06:33 -0700 | [diff] [blame] | 673 | private final AnimationController mAnimationController; |
| 674 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 675 | private boolean mShown; |
| 676 | private int mAlpha; |
| 677 | |
| 678 | private boolean mInvalidated; |
| 679 | |
| 680 | public ViewportWindow(Context context) { |
| 681 | SurfaceControl surfaceControl = null; |
| 682 | try { |
| 683 | mWindowManager.getDefaultDisplay().getRealSize(mTempPoint); |
| 684 | surfaceControl = new SurfaceControl(mWindowManagerService.mFxSession, |
| 685 | SURFACE_TITLE, mTempPoint.x, mTempPoint.y, PixelFormat.TRANSLUCENT, |
| 686 | SurfaceControl.HIDDEN); |
| 687 | } catch (OutOfResourcesException oore) { |
| 688 | /* ignore */ |
| 689 | } |
| 690 | mSurfaceControl = surfaceControl; |
| 691 | mSurfaceControl.setLayerStack(mWindowManager.getDefaultDisplay() |
| 692 | .getLayerStack()); |
| 693 | mSurfaceControl.setLayer(mWindowManagerService.mPolicy.windowTypeToLayerLw( |
| 694 | WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY) |
| 695 | * WindowManagerService.TYPE_LAYER_MULTIPLIER); |
| 696 | mSurfaceControl.setPosition(0, 0); |
| 697 | mSurface.copyFrom(mSurfaceControl); |
| 698 | |
Svet Ganov | b21df80 | 2014-09-01 19:06:33 -0700 | [diff] [blame] | 699 | mAnimationController = new AnimationController(context, |
| 700 | mWindowManagerService.mH.getLooper()); |
| 701 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 702 | TypedValue typedValue = new TypedValue(); |
| 703 | context.getTheme().resolveAttribute(R.attr.colorActivatedHighlight, |
| 704 | typedValue, true); |
Alan Viverette | 4a357cd | 2015-03-18 18:37:18 -0700 | [diff] [blame] | 705 | final int borderColor = context.getColor(typedValue.resourceId); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 706 | |
| 707 | mPaint.setStyle(Paint.Style.STROKE); |
| 708 | mPaint.setStrokeWidth(mBorderWidth); |
| 709 | mPaint.setColor(borderColor); |
| 710 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 711 | mInvalidated = true; |
| 712 | } |
| 713 | |
| 714 | public void setShown(boolean shown, boolean animate) { |
| 715 | synchronized (mWindowManagerService.mWindowMap) { |
| 716 | if (mShown == shown) { |
| 717 | return; |
| 718 | } |
| 719 | mShown = shown; |
Svet Ganov | b21df80 | 2014-09-01 19:06:33 -0700 | [diff] [blame] | 720 | mAnimationController.onFrameShownStateChanged(shown, animate); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 721 | if (DEBUG_VIEWPORT_WINDOW) { |
| 722 | Slog.i(LOG_TAG, "ViewportWindow shown: " + mShown); |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | @SuppressWarnings("unused") |
| 728 | // Called reflectively from an animator. |
| 729 | public int getAlpha() { |
| 730 | synchronized (mWindowManagerService.mWindowMap) { |
| 731 | return mAlpha; |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | public void setAlpha(int alpha) { |
| 736 | synchronized (mWindowManagerService.mWindowMap) { |
| 737 | if (mAlpha == alpha) { |
| 738 | return; |
| 739 | } |
| 740 | mAlpha = alpha; |
| 741 | invalidate(null); |
| 742 | if (DEBUG_VIEWPORT_WINDOW) { |
| 743 | Slog.i(LOG_TAG, "ViewportWindow set alpha: " + alpha); |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | public void setBounds(Region bounds) { |
| 749 | synchronized (mWindowManagerService.mWindowMap) { |
| 750 | if (mBounds.equals(bounds)) { |
| 751 | return; |
| 752 | } |
| 753 | mBounds.set(bounds); |
| 754 | invalidate(mDirtyRect); |
| 755 | if (DEBUG_VIEWPORT_WINDOW) { |
| 756 | Slog.i(LOG_TAG, "ViewportWindow set bounds: " + bounds); |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | public void updateSize() { |
| 762 | synchronized (mWindowManagerService.mWindowMap) { |
| 763 | mWindowManager.getDefaultDisplay().getRealSize(mTempPoint); |
| 764 | mSurfaceControl.setSize(mTempPoint.x, mTempPoint.y); |
| 765 | invalidate(mDirtyRect); |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | public void invalidate(Rect dirtyRect) { |
| 770 | if (dirtyRect != null) { |
| 771 | mDirtyRect.set(dirtyRect); |
| 772 | } else { |
| 773 | mDirtyRect.setEmpty(); |
| 774 | } |
| 775 | mInvalidated = true; |
| 776 | mWindowManagerService.scheduleAnimationLocked(); |
| 777 | } |
| 778 | |
| 779 | /** NOTE: This has to be called within a surface transaction. */ |
| 780 | public void drawIfNeeded() { |
| 781 | synchronized (mWindowManagerService.mWindowMap) { |
| 782 | if (!mInvalidated) { |
| 783 | return; |
| 784 | } |
| 785 | mInvalidated = false; |
| 786 | Canvas canvas = null; |
| 787 | try { |
| 788 | // Empty dirty rectangle means unspecified. |
| 789 | if (mDirtyRect.isEmpty()) { |
| 790 | mBounds.getBounds(mDirtyRect); |
| 791 | } |
| 792 | mDirtyRect.inset(- mHalfBorderWidth, - mHalfBorderWidth); |
| 793 | canvas = mSurface.lockCanvas(mDirtyRect); |
| 794 | if (DEBUG_VIEWPORT_WINDOW) { |
| 795 | Slog.i(LOG_TAG, "Dirty rect: " + mDirtyRect); |
| 796 | } |
| 797 | } catch (IllegalArgumentException iae) { |
| 798 | /* ignore */ |
| 799 | } catch (Surface.OutOfResourcesException oore) { |
| 800 | /* ignore */ |
| 801 | } |
| 802 | if (canvas == null) { |
| 803 | return; |
| 804 | } |
| 805 | if (DEBUG_VIEWPORT_WINDOW) { |
| 806 | Slog.i(LOG_TAG, "Bounds: " + mBounds); |
| 807 | } |
| 808 | canvas.drawColor(Color.TRANSPARENT, Mode.CLEAR); |
| 809 | mPaint.setAlpha(mAlpha); |
| 810 | Path path = mBounds.getBoundaryPath(); |
| 811 | canvas.drawPath(path, mPaint); |
| 812 | |
| 813 | mSurface.unlockCanvasAndPost(canvas); |
| 814 | |
| 815 | if (mAlpha > 0) { |
| 816 | mSurfaceControl.show(); |
| 817 | } else { |
| 818 | mSurfaceControl.hide(); |
| 819 | } |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | public void releaseSurface() { |
| 824 | mSurfaceControl.release(); |
| 825 | mSurface.release(); |
| 826 | } |
Svet Ganov | b21df80 | 2014-09-01 19:06:33 -0700 | [diff] [blame] | 827 | |
| 828 | private final class AnimationController extends Handler { |
| 829 | private static final String PROPERTY_NAME_ALPHA = "alpha"; |
| 830 | |
| 831 | private static final int MIN_ALPHA = 0; |
| 832 | private static final int MAX_ALPHA = 255; |
| 833 | |
| 834 | private static final int MSG_FRAME_SHOWN_STATE_CHANGED = 1; |
| 835 | |
| 836 | private final ValueAnimator mShowHideFrameAnimator; |
| 837 | |
| 838 | public AnimationController(Context context, Looper looper) { |
| 839 | super(looper); |
| 840 | mShowHideFrameAnimator = ObjectAnimator.ofInt(ViewportWindow.this, |
| 841 | PROPERTY_NAME_ALPHA, MIN_ALPHA, MAX_ALPHA); |
| 842 | |
| 843 | Interpolator interpolator = new DecelerateInterpolator(2.5f); |
| 844 | final long longAnimationDuration = context.getResources().getInteger( |
| 845 | com.android.internal.R.integer.config_longAnimTime); |
| 846 | |
| 847 | mShowHideFrameAnimator.setInterpolator(interpolator); |
| 848 | mShowHideFrameAnimator.setDuration(longAnimationDuration); |
| 849 | } |
| 850 | |
| 851 | public void onFrameShownStateChanged(boolean shown, boolean animate) { |
| 852 | obtainMessage(MSG_FRAME_SHOWN_STATE_CHANGED, |
| 853 | shown ? 1 : 0, animate ? 1 : 0).sendToTarget(); |
| 854 | } |
| 855 | |
| 856 | @Override |
| 857 | public void handleMessage(Message message) { |
| 858 | switch (message.what) { |
| 859 | case MSG_FRAME_SHOWN_STATE_CHANGED: { |
| 860 | final boolean shown = message.arg1 == 1; |
| 861 | final boolean animate = message.arg2 == 1; |
| 862 | |
| 863 | if (animate) { |
| 864 | if (mShowHideFrameAnimator.isRunning()) { |
| 865 | mShowHideFrameAnimator.reverse(); |
| 866 | } else { |
| 867 | if (shown) { |
| 868 | mShowHideFrameAnimator.start(); |
| 869 | } else { |
| 870 | mShowHideFrameAnimator.reverse(); |
| 871 | } |
| 872 | } |
| 873 | } else { |
| 874 | mShowHideFrameAnimator.cancel(); |
| 875 | if (shown) { |
| 876 | setAlpha(MAX_ALPHA); |
| 877 | } else { |
| 878 | setAlpha(MIN_ALPHA); |
| 879 | } |
| 880 | } |
| 881 | } break; |
| 882 | } |
| 883 | } |
| 884 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | |
| 888 | private class MyHandler extends Handler { |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 889 | public static final int MESSAGE_NOTIFY_MAGNIFICATION_REGION_CHANGED = 1; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 890 | public static final int MESSAGE_NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED = 2; |
| 891 | public static final int MESSAGE_NOTIFY_USER_CONTEXT_CHANGED = 3; |
| 892 | public static final int MESSAGE_NOTIFY_ROTATION_CHANGED = 4; |
| 893 | public static final int MESSAGE_SHOW_MAGNIFIED_REGION_BOUNDS_IF_NEEDED = 5; |
| 894 | |
| 895 | public MyHandler(Looper looper) { |
| 896 | super(looper); |
| 897 | } |
| 898 | |
| 899 | @Override |
| 900 | public void handleMessage(Message message) { |
| 901 | switch (message.what) { |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 902 | case MESSAGE_NOTIFY_MAGNIFICATION_REGION_CHANGED: { |
Alan Viverette | 214fb68 | 2015-11-17 09:47:11 -0500 | [diff] [blame] | 903 | final SomeArgs args = (SomeArgs) message.obj; |
| 904 | final Region magnifiedBounds = (Region) args.arg1; |
Phil Weaver | 7043924 | 2016-03-10 15:15:49 -0800 | [diff] [blame] | 905 | mCallbacks.onMagnificationRegionChanged(magnifiedBounds); |
Alan Viverette | 214fb68 | 2015-11-17 09:47:11 -0500 | [diff] [blame] | 906 | magnifiedBounds.recycle(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 907 | } break; |
| 908 | |
| 909 | case MESSAGE_NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED: { |
| 910 | SomeArgs args = (SomeArgs) message.obj; |
| 911 | final int left = args.argi1; |
| 912 | final int top = args.argi2; |
| 913 | final int right = args.argi3; |
| 914 | final int bottom = args.argi4; |
| 915 | mCallbacks.onRectangleOnScreenRequested(left, top, right, bottom); |
| 916 | args.recycle(); |
| 917 | } break; |
| 918 | |
| 919 | case MESSAGE_NOTIFY_USER_CONTEXT_CHANGED: { |
| 920 | mCallbacks.onUserContextChanged(); |
| 921 | } break; |
| 922 | |
| 923 | case MESSAGE_NOTIFY_ROTATION_CHANGED: { |
| 924 | final int rotation = message.arg1; |
| 925 | mCallbacks.onRotationChanged(rotation); |
| 926 | } break; |
| 927 | |
| 928 | case MESSAGE_SHOW_MAGNIFIED_REGION_BOUNDS_IF_NEEDED : { |
| 929 | synchronized (mWindowManagerService.mWindowMap) { |
| 930 | if (mMagnifedViewport.isMagnifyingLocked()) { |
| 931 | mMagnifedViewport.setMagnifiedRegionBorderShownLocked(true, true); |
| 932 | mWindowManagerService.scheduleAnimationLocked(); |
| 933 | } |
| 934 | } |
| 935 | } break; |
| 936 | } |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | /** |
| 942 | * This class encapsulates the functionality related to computing the windows |
| 943 | * reported for accessibility purposes. These windows are all windows a sighted |
| 944 | * user can see on the screen. |
| 945 | */ |
| 946 | private static final class WindowsForAccessibilityObserver { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 947 | private static final String LOG_TAG = TAG_WITH_CLASS_NAME ? |
| 948 | "WindowsForAccessibilityObserver" : TAG_WM; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 949 | |
| 950 | private static final boolean DEBUG = false; |
| 951 | |
| 952 | private final SparseArray<WindowState> mTempWindowStates = |
| 953 | new SparseArray<WindowState>(); |
| 954 | |
| 955 | private final List<WindowInfo> mOldWindows = new ArrayList<WindowInfo>(); |
| 956 | |
| 957 | private final Set<IBinder> mTempBinderSet = new ArraySet<IBinder>(); |
| 958 | |
| 959 | private final RectF mTempRectF = new RectF(); |
| 960 | |
| 961 | private final Matrix mTempMatrix = new Matrix(); |
| 962 | |
| 963 | private final Point mTempPoint = new Point(); |
| 964 | |
| 965 | private final Rect mTempRect = new Rect(); |
| 966 | |
| 967 | private final Region mTempRegion = new Region(); |
| 968 | |
| 969 | private final Region mTempRegion1 = new Region(); |
| 970 | |
| 971 | private final Context mContext; |
| 972 | |
| 973 | private final WindowManagerService mWindowManagerService; |
| 974 | |
| 975 | private final Handler mHandler; |
| 976 | |
| 977 | private final WindowsForAccessibilityCallback mCallback; |
| 978 | |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 979 | private final long mRecurringAccessibilityEventsIntervalMillis; |
| 980 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 981 | public WindowsForAccessibilityObserver(WindowManagerService windowManagerService, |
| 982 | WindowsForAccessibilityCallback callback) { |
| 983 | mContext = windowManagerService.mContext; |
| 984 | mWindowManagerService = windowManagerService; |
| 985 | mCallback = callback; |
| 986 | mHandler = new MyHandler(mWindowManagerService.mH.getLooper()); |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 987 | mRecurringAccessibilityEventsIntervalMillis = ViewConfiguration |
| 988 | .getSendRecurringAccessibilityEventsInterval(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 989 | computeChangedWindows(); |
| 990 | } |
| 991 | |
Svetoslav | 3a0d878 | 2014-12-04 12:50:11 -0800 | [diff] [blame] | 992 | public void performComputeChangedWindowsNotLocked() { |
| 993 | mHandler.removeMessages(MyHandler.MESSAGE_COMPUTE_CHANGED_WINDOWS); |
| 994 | computeChangedWindows(); |
| 995 | } |
| 996 | |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 997 | public void scheduleComputeChangedWindowsLocked() { |
Svetoslav | 3a0d878 | 2014-12-04 12:50:11 -0800 | [diff] [blame] | 998 | if (!mHandler.hasMessages(MyHandler.MESSAGE_COMPUTE_CHANGED_WINDOWS)) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 999 | mHandler.sendEmptyMessageDelayed(MyHandler.MESSAGE_COMPUTE_CHANGED_WINDOWS, |
| 1000 | mRecurringAccessibilityEventsIntervalMillis); |
| 1001 | } |
| 1002 | } |
| 1003 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1004 | public void computeChangedWindows() { |
| 1005 | if (DEBUG) { |
| 1006 | Slog.i(LOG_TAG, "computeChangedWindows()"); |
| 1007 | } |
| 1008 | |
Svetoslav | 3a0d878 | 2014-12-04 12:50:11 -0800 | [diff] [blame] | 1009 | boolean windowsChanged = false; |
| 1010 | List<WindowInfo> windows = new ArrayList<WindowInfo>(); |
| 1011 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1012 | synchronized (mWindowManagerService.mWindowMap) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1013 | // Do not send the windows if there is no current focus as |
| 1014 | // the window manager is still looking for where to put it. |
| 1015 | // We will do the work when we get a focus change callback. |
| 1016 | if (mWindowManagerService.mCurrentFocus == null) { |
| 1017 | return; |
| 1018 | } |
| 1019 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1020 | WindowManager windowManager = (WindowManager) |
| 1021 | mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1022 | windowManager.getDefaultDisplay().getRealSize(mTempPoint); |
| 1023 | final int screenWidth = mTempPoint.x; |
| 1024 | final int screenHeight = mTempPoint.y; |
| 1025 | |
| 1026 | Region unaccountedSpace = mTempRegion; |
| 1027 | unaccountedSpace.set(0, 0, screenWidth, screenHeight); |
| 1028 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame^] | 1029 | final SparseArray<WindowState> visibleWindows = mTempWindowStates; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1030 | populateVisibleWindowsOnScreenLocked(visibleWindows); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1031 | Set<IBinder> addedWindows = mTempBinderSet; |
| 1032 | addedWindows.clear(); |
| 1033 | |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1034 | boolean focusedWindowAdded = false; |
| 1035 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1036 | final int visibleWindowCount = visibleWindows.size(); |
Allen Hair | f20ac2c | 2016-02-11 17:42:59 -0800 | [diff] [blame] | 1037 | int skipRemainingWindowsForTaskId = -1; |
| 1038 | HashSet<Integer> skipRemainingWindowsForTasks = new HashSet<>(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1039 | for (int i = visibleWindowCount - 1; i >= 0; i--) { |
Alan Viverette | 9538eea | 2014-11-13 14:49:20 -0800 | [diff] [blame] | 1040 | final WindowState windowState = visibleWindows.valueAt(i); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1041 | final int flags = windowState.mAttrs.flags; |
Allen Hair | f20ac2c | 2016-02-11 17:42:59 -0800 | [diff] [blame] | 1042 | final Task task = windowState.getTask(); |
| 1043 | |
| 1044 | // If the window is part of a task that we're finished with - ignore. |
| 1045 | if (task != null && skipRemainingWindowsForTasks.contains(task.mTaskId)) { |
| 1046 | continue; |
| 1047 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1048 | |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 1049 | // If the window is not touchable - ignore. |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1050 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1051 | continue; |
| 1052 | } |
| 1053 | |
Alan Viverette | 9538eea | 2014-11-13 14:49:20 -0800 | [diff] [blame] | 1054 | // Compute the bounds in the screen. |
| 1055 | final Rect boundsInScreen = mTempRect; |
| 1056 | computeWindowBoundsInScreen(windowState, boundsInScreen); |
| 1057 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1058 | // If the window is completely covered by other windows - ignore. |
| 1059 | if (unaccountedSpace.quickReject(boundsInScreen)) { |
| 1060 | continue; |
| 1061 | } |
| 1062 | |
| 1063 | // Add windows of certain types not covered by modal windows. |
| 1064 | if (isReportedWindowType(windowState.mAttrs.type)) { |
| 1065 | // Add the window to the ones to be reported. |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1066 | WindowInfo window = obtainPopulatedWindowInfo(windowState, boundsInScreen); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1067 | addedWindows.add(window.token); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1068 | windows.add(window); |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1069 | if (windowState.isFocused()) { |
| 1070 | focusedWindowAdded = true; |
| 1071 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1072 | } |
| 1073 | |
Alan Viverette | d0c73f4 | 2014-11-18 10:25:04 -0800 | [diff] [blame] | 1074 | // Account for the space this window takes if the window |
| 1075 | // is not an accessibility overlay which does not change |
| 1076 | // the reported windows. |
| 1077 | if (windowState.mAttrs.type != |
| 1078 | WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY) { |
| 1079 | unaccountedSpace.op(boundsInScreen, unaccountedSpace, |
| 1080 | Region.Op.REVERSE_DIFFERENCE); |
| 1081 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1082 | |
Allen Hair | f20ac2c | 2016-02-11 17:42:59 -0800 | [diff] [blame] | 1083 | // If a window is modal it prevents other windows from being touched |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1084 | if ((flags & (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1085 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL)) == 0) { |
Phil Weaver | ac9ad70 | 2016-07-27 18:03:10 -0700 | [diff] [blame] | 1086 | // Account for all space in the task, whether the windows in it are |
| 1087 | // touchable or not. The modal window blocks all touches from the task's |
| 1088 | // area. |
| 1089 | unaccountedSpace.op(windowState.getDisplayFrameLw(), unaccountedSpace, |
| 1090 | Region.Op.REVERSE_DIFFERENCE); |
| 1091 | |
Allen Hair | f20ac2c | 2016-02-11 17:42:59 -0800 | [diff] [blame] | 1092 | if (task != null) { |
| 1093 | // If the window is associated with a particular task, we can skip the |
| 1094 | // rest of the windows for that task. |
| 1095 | skipRemainingWindowsForTasks.add(task.mTaskId); |
| 1096 | continue; |
| 1097 | } else { |
| 1098 | // If the window is not associated with a particular task, then it is |
| 1099 | // globally modal. In this case we can skip all remaining windows. |
| 1100 | break; |
| 1101 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1102 | } |
Phil Weaver | ac9ad70 | 2016-07-27 18:03:10 -0700 | [diff] [blame] | 1103 | // We figured out what is touchable for the entire screen - done. |
| 1104 | if (unaccountedSpace.isEmpty()) { |
| 1105 | break; |
| 1106 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1107 | } |
| 1108 | |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1109 | // Always report the focused window. |
| 1110 | if (!focusedWindowAdded) { |
| 1111 | for (int i = visibleWindowCount - 1; i >= 0; i--) { |
| 1112 | WindowState windowState = visibleWindows.valueAt(i); |
| 1113 | if (windowState.isFocused()) { |
| 1114 | // Compute the bounds in the screen. |
| 1115 | Rect boundsInScreen = mTempRect; |
| 1116 | computeWindowBoundsInScreen(windowState, boundsInScreen); |
| 1117 | |
| 1118 | // Add the window to the ones to be reported. |
| 1119 | WindowInfo window = obtainPopulatedWindowInfo(windowState, |
| 1120 | boundsInScreen); |
| 1121 | addedWindows.add(window.token); |
| 1122 | windows.add(window); |
| 1123 | break; |
| 1124 | } |
| 1125 | } |
| 1126 | } |
| 1127 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1128 | // Remove child/parent references to windows that were not added. |
| 1129 | final int windowCount = windows.size(); |
| 1130 | for (int i = 0; i < windowCount; i++) { |
| 1131 | WindowInfo window = windows.get(i); |
| 1132 | if (!addedWindows.contains(window.parentToken)) { |
| 1133 | window.parentToken = null; |
| 1134 | } |
| 1135 | if (window.childTokens != null) { |
| 1136 | final int childTokenCount = window.childTokens.size(); |
| 1137 | for (int j = childTokenCount - 1; j >= 0; j--) { |
| 1138 | if (!addedWindows.contains(window.childTokens.get(j))) { |
| 1139 | window.childTokens.remove(j); |
| 1140 | } |
| 1141 | } |
| 1142 | // Leave the child token list if empty. |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | visibleWindows.clear(); |
| 1147 | addedWindows.clear(); |
| 1148 | |
| 1149 | // We computed the windows and if they changed notify the client. |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1150 | if (mOldWindows.size() != windows.size()) { |
| 1151 | // Different size means something changed. |
| 1152 | windowsChanged = true; |
| 1153 | } else if (!mOldWindows.isEmpty() || !windows.isEmpty()) { |
| 1154 | // Since we always traverse windows from high to low layer |
| 1155 | // the old and new windows at the same index should be the |
| 1156 | // same, otherwise something changed. |
| 1157 | for (int i = 0; i < windowCount; i++) { |
| 1158 | WindowInfo oldWindow = mOldWindows.get(i); |
| 1159 | WindowInfo newWindow = windows.get(i); |
| 1160 | // We do not care for layer changes given the window |
| 1161 | // order does not change. This brings no new information |
| 1162 | // to the clients. |
| 1163 | if (windowChangedNoLayer(oldWindow, newWindow)) { |
| 1164 | windowsChanged = true; |
| 1165 | break; |
| 1166 | } |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | if (windowsChanged) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1171 | cacheWindows(windows); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1172 | } |
| 1173 | } |
Svetoslav | 3a0d878 | 2014-12-04 12:50:11 -0800 | [diff] [blame] | 1174 | |
| 1175 | // Now we do not hold the lock, so send the windows over. |
| 1176 | if (windowsChanged) { |
| 1177 | if (DEBUG) { |
| 1178 | Log.i(LOG_TAG, "Windows changed:" + windows); |
| 1179 | } |
| 1180 | mCallback.onWindowsForAccessibilityChanged(windows); |
| 1181 | } else { |
| 1182 | if (DEBUG) { |
| 1183 | Log.i(LOG_TAG, "No windows changed."); |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | // Recycle the windows as we do not need them. |
| 1188 | clearAndRecycleWindows(windows); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1189 | } |
| 1190 | |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1191 | private void computeWindowBoundsInScreen(WindowState windowState, Rect outBounds) { |
| 1192 | // Get the touchable frame. |
| 1193 | Region touchableRegion = mTempRegion1; |
| 1194 | windowState.getTouchableRegion(touchableRegion); |
| 1195 | Rect touchableFrame = mTempRect; |
| 1196 | touchableRegion.getBounds(touchableFrame); |
| 1197 | |
| 1198 | // Move to origin as all transforms are captured by the matrix. |
| 1199 | RectF windowFrame = mTempRectF; |
| 1200 | windowFrame.set(touchableFrame); |
| 1201 | windowFrame.offset(-windowState.mFrame.left, -windowState.mFrame.top); |
| 1202 | |
| 1203 | // Map the frame to get what appears on the screen. |
| 1204 | Matrix matrix = mTempMatrix; |
| 1205 | populateTransformationMatrixLocked(windowState, matrix); |
| 1206 | matrix.mapRect(windowFrame); |
| 1207 | |
| 1208 | // Got the bounds. |
| 1209 | outBounds.set((int) windowFrame.left, (int) windowFrame.top, |
| 1210 | (int) windowFrame.right, (int) windowFrame.bottom); |
| 1211 | } |
| 1212 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1213 | private static WindowInfo obtainPopulatedWindowInfo( |
| 1214 | WindowState windowState, Rect boundsInScreen) { |
| 1215 | final WindowInfo window = windowState.getWindowInfo(); |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1216 | window.boundsInScreen.set(boundsInScreen); |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1217 | return window; |
| 1218 | } |
| 1219 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1220 | private void cacheWindows(List<WindowInfo> windows) { |
| 1221 | final int oldWindowCount = mOldWindows.size(); |
| 1222 | for (int i = oldWindowCount - 1; i >= 0; i--) { |
| 1223 | mOldWindows.remove(i).recycle(); |
| 1224 | } |
| 1225 | final int newWindowCount = windows.size(); |
| 1226 | for (int i = 0; i < newWindowCount; i++) { |
| 1227 | WindowInfo newWindow = windows.get(i); |
| 1228 | mOldWindows.add(WindowInfo.obtain(newWindow)); |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | private boolean windowChangedNoLayer(WindowInfo oldWindow, WindowInfo newWindow) { |
| 1233 | if (oldWindow == newWindow) { |
| 1234 | return false; |
| 1235 | } |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1236 | if (oldWindow == null) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1237 | return true; |
| 1238 | } |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1239 | if (newWindow == null) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1240 | return true; |
| 1241 | } |
| 1242 | if (oldWindow.type != newWindow.type) { |
| 1243 | return true; |
| 1244 | } |
| 1245 | if (oldWindow.focused != newWindow.focused) { |
| 1246 | return true; |
| 1247 | } |
| 1248 | if (oldWindow.token == null) { |
| 1249 | if (newWindow.token != null) { |
| 1250 | return true; |
| 1251 | } |
| 1252 | } else if (!oldWindow.token.equals(newWindow.token)) { |
| 1253 | return true; |
| 1254 | } |
| 1255 | if (oldWindow.parentToken == null) { |
| 1256 | if (newWindow.parentToken != null) { |
| 1257 | return true; |
| 1258 | } |
| 1259 | } else if (!oldWindow.parentToken.equals(newWindow.parentToken)) { |
| 1260 | return true; |
| 1261 | } |
| 1262 | if (!oldWindow.boundsInScreen.equals(newWindow.boundsInScreen)) { |
| 1263 | return true; |
| 1264 | } |
| 1265 | if (oldWindow.childTokens != null && newWindow.childTokens != null |
| 1266 | && !oldWindow.childTokens.equals(newWindow.childTokens)) { |
| 1267 | return true; |
| 1268 | } |
Phil Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 1269 | if (!TextUtils.equals(oldWindow.title, newWindow.title)) { |
| 1270 | return true; |
| 1271 | } |
| 1272 | if (oldWindow.accessibilityIdOfAnchor != newWindow.accessibilityIdOfAnchor) { |
| 1273 | return true; |
| 1274 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1275 | return false; |
| 1276 | } |
| 1277 | |
Svetoslav | 3a0d878 | 2014-12-04 12:50:11 -0800 | [diff] [blame] | 1278 | private static void clearAndRecycleWindows(List<WindowInfo> windows) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1279 | final int windowCount = windows.size(); |
| 1280 | for (int i = windowCount - 1; i >= 0; i--) { |
| 1281 | windows.remove(i).recycle(); |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | private static boolean isReportedWindowType(int windowType) { |
| 1286 | return (windowType != WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
| 1287 | && windowType != WindowManager.LayoutParams.TYPE_WALLPAPER |
| 1288 | && windowType != WindowManager.LayoutParams.TYPE_BOOT_PROGRESS |
| 1289 | && windowType != WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY |
| 1290 | && windowType != WindowManager.LayoutParams.TYPE_DRAG |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1291 | && windowType != WindowManager.LayoutParams.TYPE_INPUT_CONSUMER |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1292 | && windowType != WindowManager.LayoutParams.TYPE_POINTER |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1293 | && windowType != WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY |
| 1294 | && windowType != WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY |
| 1295 | && windowType != WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY |
| 1296 | && windowType != WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION); |
| 1297 | } |
| 1298 | |
| 1299 | private void populateVisibleWindowsOnScreenLocked(SparseArray<WindowState> outWindows) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame^] | 1300 | final DisplayContent dc = mWindowManagerService.getDefaultDisplayContentLocked(); |
| 1301 | final ReadOnlyWindowList windowList = dc.getReadOnlyWindowList(); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1302 | final int windowCount = windowList.size(); |
| 1303 | for (int i = 0; i < windowCount; i++) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame^] | 1304 | final WindowState windowState = windowList.get(i); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1305 | if (windowState.isVisibleLw()) { |
| 1306 | outWindows.put(windowState.mLayer, windowState); |
| 1307 | } |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | private class MyHandler extends Handler { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1312 | public static final int MESSAGE_COMPUTE_CHANGED_WINDOWS = 1; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1313 | |
| 1314 | public MyHandler(Looper looper) { |
| 1315 | super(looper, null, false); |
| 1316 | } |
| 1317 | |
| 1318 | @Override |
| 1319 | @SuppressWarnings("unchecked") |
| 1320 | public void handleMessage(Message message) { |
| 1321 | switch (message.what) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 1322 | case MESSAGE_COMPUTE_CHANGED_WINDOWS: { |
| 1323 | computeChangedWindows(); |
| 1324 | } break; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1325 | } |
| 1326 | } |
| 1327 | } |
| 1328 | } |
| 1329 | } |