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