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