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