Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 android.view; |
| 18 | |
Jackal Guo | ecd09bb | 2019-03-20 17:43:19 +0800 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
Phil Weaver | 193520e | 2016-12-13 09:39:06 -0800 | [diff] [blame] | 20 | import static android.view.accessibility.AccessibilityNodeInfo.ACTION_ARGUMENT_ACCESSIBLE_CLICKABLE_SPAN; |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 21 | import static android.view.accessibility.AccessibilityNodeInfo.EXTRA_DATA_REQUESTED_KEY; |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 22 | import static android.view.accessibility.AccessibilityNodeInfo.EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY; |
Phil Weaver | 193520e | 2016-12-13 09:39:06 -0800 | [diff] [blame] | 23 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 24 | import android.graphics.Point; |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 25 | import android.graphics.Rect; |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 26 | import android.graphics.RectF; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 27 | import android.graphics.Region; |
Nirmal Patel | 386a824 | 2015-06-02 18:11:32 -0700 | [diff] [blame] | 28 | import android.os.Binder; |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 29 | import android.os.Bundle; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 30 | import android.os.Handler; |
| 31 | import android.os.Looper; |
| 32 | import android.os.Message; |
Phil Weaver | 193520e | 2016-12-13 09:39:06 -0800 | [diff] [blame] | 33 | import android.os.Parcelable; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 34 | import android.os.Process; |
| 35 | import android.os.RemoteException; |
Jackal Guo | ac2b62e | 2018-08-22 18:28:46 +0800 | [diff] [blame] | 36 | import android.os.SystemClock; |
Phil Weaver | 193520e | 2016-12-13 09:39:06 -0800 | [diff] [blame] | 37 | import android.text.style.AccessibilityClickableSpan; |
| 38 | import android.text.style.ClickableSpan; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 39 | import android.util.LongSparseArray; |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 40 | import android.util.Slog; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 41 | import android.view.View.AttachInfo; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 42 | import android.view.accessibility.AccessibilityInteractionClient; |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 43 | import android.view.accessibility.AccessibilityManager; |
Qasid Ahmad Sadiq | 834787a | 2019-01-18 00:01:54 -0800 | [diff] [blame] | 44 | import android.view.accessibility.AccessibilityNodeIdManager; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 45 | import android.view.accessibility.AccessibilityNodeInfo; |
Rhed Jao | 23813d9 | 2018-12-18 21:30:52 +0800 | [diff] [blame] | 46 | import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 47 | import android.view.accessibility.AccessibilityNodeProvider; |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 48 | import android.view.accessibility.AccessibilityRequestPreparer; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 49 | import android.view.accessibility.IAccessibilityInteractionConnectionCallback; |
| 50 | |
Phil Weaver | 193520e | 2016-12-13 09:39:06 -0800 | [diff] [blame] | 51 | import com.android.internal.R; |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 52 | import com.android.internal.annotations.GuardedBy; |
Rhed Jao | 23813d9 | 2018-12-18 21:30:52 +0800 | [diff] [blame] | 53 | import com.android.internal.annotations.VisibleForTesting; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 54 | import com.android.internal.os.SomeArgs; |
| 55 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 56 | import java.util.ArrayList; |
| 57 | import java.util.HashMap; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 58 | import java.util.HashSet; |
| 59 | import java.util.LinkedList; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 60 | import java.util.List; |
| 61 | import java.util.Map; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 62 | import java.util.Queue; |
Paul Duffin | ca4964c | 2017-02-07 15:04:10 +0000 | [diff] [blame] | 63 | import java.util.function.Predicate; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * Class for managing accessibility interactions initiated from the system |
| 67 | * and targeting the view hierarchy. A *ClientThread method is to be |
| 68 | * called from the interaction connection ViewAncestor gives the system to |
| 69 | * talk to it and a corresponding *UiThread method that is executed on the |
| 70 | * UI thread. |
Rhed Jao | 23813d9 | 2018-12-18 21:30:52 +0800 | [diff] [blame] | 71 | * |
| 72 | * @hide |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 73 | */ |
Rhed Jao | 23813d9 | 2018-12-18 21:30:52 +0800 | [diff] [blame] | 74 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 75 | public final class AccessibilityInteractionController { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 76 | |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 77 | private static final String LOG_TAG = "AccessibilityInteractionController"; |
| 78 | |
| 79 | // Debugging flag |
Svetoslav | aaa1142 | 2014-03-28 13:31:13 -0700 | [diff] [blame] | 80 | private static final boolean ENFORCE_NODE_TREE_CONSISTENT = false; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 81 | |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 82 | // Constants for readability |
| 83 | private static final boolean IGNORE_REQUEST_PREPARERS = true; |
| 84 | private static final boolean CONSIDER_REQUEST_PREPARERS = false; |
| 85 | |
| 86 | // If an app holds off accessibility for longer than this, the hold-off is canceled to prevent |
| 87 | // accessibility from hanging |
| 88 | private static final long REQUEST_PREPARER_TIMEOUT_MS = 500; |
| 89 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 90 | private final ArrayList<AccessibilityNodeInfo> mTempAccessibilityNodeInfoList = |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 91 | new ArrayList<AccessibilityNodeInfo>(); |
| 92 | |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 93 | private final Object mLock = new Object(); |
| 94 | |
Rhed Jao | 23813d9 | 2018-12-18 21:30:52 +0800 | [diff] [blame] | 95 | private final PrivateHandler mHandler; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 96 | |
| 97 | private final ViewRootImpl mViewRootImpl; |
| 98 | |
| 99 | private final AccessibilityNodePrefetcher mPrefetcher; |
| 100 | |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 101 | private final long mMyLooperThreadId; |
| 102 | |
| 103 | private final int mMyProcessId; |
| 104 | |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 105 | private final AccessibilityManager mA11yManager; |
| 106 | |
Svetoslav Ganov | 30ac645 | 2012-06-01 09:10:25 -0700 | [diff] [blame] | 107 | private final ArrayList<View> mTempArrayList = new ArrayList<View>(); |
| 108 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 109 | private final Point mTempPoint = new Point(); |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 110 | private final Rect mTempRect = new Rect(); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 111 | private final Rect mTempRect1 = new Rect(); |
| 112 | private final Rect mTempRect2 = new Rect(); |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 113 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 114 | private AddNodeInfosForViewId mAddNodeInfosForViewId; |
| 115 | |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 116 | @GuardedBy("mLock") |
| 117 | private int mNumActiveRequestPreparers; |
| 118 | @GuardedBy("mLock") |
| 119 | private List<MessageHolder> mMessagesWaitingForRequestPreparer; |
| 120 | @GuardedBy("mLock") |
| 121 | private int mActiveRequestPreparerId; |
| 122 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 123 | public AccessibilityInteractionController(ViewRootImpl viewRootImpl) { |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 124 | Looper looper = viewRootImpl.mHandler.getLooper(); |
| 125 | mMyLooperThreadId = looper.getThread().getId(); |
| 126 | mMyProcessId = Process.myPid(); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 127 | mHandler = new PrivateHandler(looper); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 128 | mViewRootImpl = viewRootImpl; |
| 129 | mPrefetcher = new AccessibilityNodePrefetcher(); |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 130 | mA11yManager = mViewRootImpl.mContext.getSystemService(AccessibilityManager.class); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 133 | private void scheduleMessage(Message message, int interrogatingPid, long interrogatingTid, |
| 134 | boolean ignoreRequestPreparers) { |
| 135 | if (ignoreRequestPreparers |
| 136 | || !holdOffMessageIfNeeded(message, interrogatingPid, interrogatingTid)) { |
| 137 | // If the interrogation is performed by the same thread as the main UI |
| 138 | // thread in this process, set the message as a static reference so |
| 139 | // after this call completes the same thread but in the interrogating |
| 140 | // client can handle the message to generate the result. |
Rhed Jao | 23813d9 | 2018-12-18 21:30:52 +0800 | [diff] [blame] | 141 | if (interrogatingPid == mMyProcessId && interrogatingTid == mMyLooperThreadId |
| 142 | && mHandler.hasAccessibilityCallback(message)) { |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 143 | AccessibilityInteractionClient.getInstanceForThread( |
| 144 | interrogatingTid).setSameThreadMessage(message); |
| 145 | } else { |
Rhed Jao | 23813d9 | 2018-12-18 21:30:52 +0800 | [diff] [blame] | 146 | // For messages without callback of interrogating client, just handle the |
| 147 | // message immediately if this is UI thread. |
| 148 | if (!mHandler.hasAccessibilityCallback(message) |
| 149 | && Thread.currentThread().getId() == mMyLooperThreadId) { |
| 150 | mHandler.handleMessage(message); |
| 151 | } else { |
| 152 | mHandler.sendMessage(message); |
| 153 | } |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 154 | } |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 158 | private boolean isShown(View view) { |
Qasid Ahmad Sadiq | 834787a | 2019-01-18 00:01:54 -0800 | [diff] [blame] | 159 | return (view != null) && (view.getWindowVisibility() == View.VISIBLE && view.isShown()); |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 162 | public void findAccessibilityNodeInfoByAccessibilityIdClientThread( |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 163 | long accessibilityNodeId, Region interactiveRegion, int interactionId, |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 164 | IAccessibilityInteractionConnectionCallback callback, int flags, int interrogatingPid, |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 165 | long interrogatingTid, MagnificationSpec spec, Bundle arguments) { |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 166 | final Message message = mHandler.obtainMessage(); |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 167 | message.what = PrivateHandler.MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_ACCESSIBILITY_ID; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 168 | message.arg1 = flags; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 169 | |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 170 | final SomeArgs args = SomeArgs.obtain(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 171 | args.argi1 = AccessibilityNodeInfo.getAccessibilityViewId(accessibilityNodeId); |
| 172 | args.argi2 = AccessibilityNodeInfo.getVirtualDescendantId(accessibilityNodeId); |
| 173 | args.argi3 = interactionId; |
| 174 | args.arg1 = callback; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 175 | args.arg2 = spec; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 176 | args.arg3 = interactiveRegion; |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 177 | args.arg4 = arguments; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 178 | message.obj = args; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 179 | |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 180 | scheduleMessage(message, interrogatingPid, interrogatingTid, CONSIDER_REQUEST_PREPARERS); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Check if this message needs to be held off while the app prepares to meet either this |
| 185 | * request, or a request ahead of it. |
| 186 | * |
| 187 | * @param originalMessage The message to be processed |
| 188 | * @param callingPid The calling process id |
| 189 | * @param callingTid The calling thread id |
| 190 | * |
| 191 | * @return {@code true} if the message is held off and will be processed later, {@code false} if |
| 192 | * the message should be posted. |
| 193 | */ |
| 194 | private boolean holdOffMessageIfNeeded( |
| 195 | Message originalMessage, int callingPid, long callingTid) { |
| 196 | synchronized (mLock) { |
| 197 | // If a request is already pending, queue this request for when it's finished |
| 198 | if (mNumActiveRequestPreparers != 0) { |
| 199 | queueMessageToHandleOncePrepared(originalMessage, callingPid, callingTid); |
| 200 | return true; |
| 201 | } |
| 202 | |
| 203 | // Currently the only message that can hold things off is findByA11yId with extra data. |
| 204 | if (originalMessage.what |
| 205 | != PrivateHandler.MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_ACCESSIBILITY_ID) { |
| 206 | return false; |
| 207 | } |
| 208 | SomeArgs originalMessageArgs = (SomeArgs) originalMessage.obj; |
| 209 | Bundle requestArguments = (Bundle) originalMessageArgs.arg4; |
| 210 | if (requestArguments == null) { |
| 211 | return false; |
| 212 | } |
| 213 | |
| 214 | // If nothing it registered for this view, nothing to do |
| 215 | int accessibilityViewId = originalMessageArgs.argi1; |
| 216 | final List<AccessibilityRequestPreparer> preparers = |
| 217 | mA11yManager.getRequestPreparersForAccessibilityId(accessibilityViewId); |
| 218 | if (preparers == null) { |
| 219 | return false; |
| 220 | } |
| 221 | |
| 222 | // If the bundle doesn't request the extra data, nothing to do |
| 223 | final String extraDataKey = requestArguments.getString(EXTRA_DATA_REQUESTED_KEY); |
| 224 | if (extraDataKey == null) { |
| 225 | return false; |
| 226 | } |
| 227 | |
| 228 | // Send the request to the AccessibilityRequestPreparers on the UI thread |
| 229 | mNumActiveRequestPreparers = preparers.size(); |
| 230 | for (int i = 0; i < preparers.size(); i++) { |
| 231 | final Message requestPreparerMessage = mHandler.obtainMessage( |
| 232 | PrivateHandler.MSG_PREPARE_FOR_EXTRA_DATA_REQUEST); |
| 233 | final SomeArgs requestPreparerArgs = SomeArgs.obtain(); |
| 234 | // virtualDescendentId |
| 235 | requestPreparerArgs.argi1 = |
| 236 | (originalMessageArgs.argi2 == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) |
| 237 | ? AccessibilityNodeProvider.HOST_VIEW_ID : originalMessageArgs.argi2; |
| 238 | requestPreparerArgs.arg1 = preparers.get(i); |
| 239 | requestPreparerArgs.arg2 = extraDataKey; |
| 240 | requestPreparerArgs.arg3 = requestArguments; |
| 241 | Message preparationFinishedMessage = mHandler.obtainMessage( |
| 242 | PrivateHandler.MSG_APP_PREPARATION_FINISHED); |
| 243 | preparationFinishedMessage.arg1 = ++mActiveRequestPreparerId; |
| 244 | requestPreparerArgs.arg4 = preparationFinishedMessage; |
| 245 | |
| 246 | requestPreparerMessage.obj = requestPreparerArgs; |
| 247 | scheduleMessage(requestPreparerMessage, callingPid, callingTid, |
| 248 | IGNORE_REQUEST_PREPARERS); |
| 249 | mHandler.obtainMessage(PrivateHandler.MSG_APP_PREPARATION_TIMEOUT); |
| 250 | mHandler.sendEmptyMessageDelayed(PrivateHandler.MSG_APP_PREPARATION_TIMEOUT, |
| 251 | REQUEST_PREPARER_TIMEOUT_MS); |
| 252 | } |
| 253 | |
| 254 | // Set the initial request aside |
| 255 | queueMessageToHandleOncePrepared(originalMessage, callingPid, callingTid); |
| 256 | return true; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | private void prepareForExtraDataRequestUiThread(Message message) { |
| 261 | SomeArgs args = (SomeArgs) message.obj; |
| 262 | final int virtualDescendantId = args.argi1; |
| 263 | final AccessibilityRequestPreparer preparer = (AccessibilityRequestPreparer) args.arg1; |
| 264 | final String extraDataKey = (String) args.arg2; |
| 265 | final Bundle requestArguments = (Bundle) args.arg3; |
| 266 | final Message preparationFinishedMessage = (Message) args.arg4; |
| 267 | |
| 268 | preparer.onPrepareExtraData(virtualDescendantId, extraDataKey, |
| 269 | requestArguments, preparationFinishedMessage); |
| 270 | } |
| 271 | |
| 272 | private void queueMessageToHandleOncePrepared(Message message, int interrogatingPid, |
| 273 | long interrogatingTid) { |
| 274 | if (mMessagesWaitingForRequestPreparer == null) { |
| 275 | mMessagesWaitingForRequestPreparer = new ArrayList<>(1); |
| 276 | } |
| 277 | MessageHolder messageHolder = |
| 278 | new MessageHolder(message, interrogatingPid, interrogatingTid); |
| 279 | mMessagesWaitingForRequestPreparer.add(messageHolder); |
| 280 | } |
| 281 | |
| 282 | private void requestPreparerDoneUiThread(Message message) { |
| 283 | synchronized (mLock) { |
| 284 | if (message.arg1 != mActiveRequestPreparerId) { |
| 285 | Slog.e(LOG_TAG, "Surprising AccessibilityRequestPreparer callback (likely late)"); |
| 286 | return; |
| 287 | } |
| 288 | mNumActiveRequestPreparers--; |
| 289 | if (mNumActiveRequestPreparers <= 0) { |
| 290 | mHandler.removeMessages(PrivateHandler.MSG_APP_PREPARATION_TIMEOUT); |
| 291 | scheduleAllMessagesWaitingForRequestPreparerLocked(); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | private void requestPreparerTimeoutUiThread() { |
| 297 | synchronized (mLock) { |
| 298 | Slog.e(LOG_TAG, "AccessibilityRequestPreparer timed out"); |
| 299 | scheduleAllMessagesWaitingForRequestPreparerLocked(); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | @GuardedBy("mLock") |
| 304 | private void scheduleAllMessagesWaitingForRequestPreparerLocked() { |
| 305 | int numMessages = mMessagesWaitingForRequestPreparer.size(); |
| 306 | for (int i = 0; i < numMessages; i++) { |
| 307 | MessageHolder request = mMessagesWaitingForRequestPreparer.get(i); |
| 308 | scheduleMessage(request.mMessage, request.mInterrogatingPid, |
| 309 | request.mInterrogatingTid, |
| 310 | (i == 0) /* the app is ready for the first request */); |
| 311 | } |
| 312 | mMessagesWaitingForRequestPreparer.clear(); |
| 313 | mNumActiveRequestPreparers = 0; // Just to be safe - should be unnecessary |
| 314 | mActiveRequestPreparerId = -1; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | private void findAccessibilityNodeInfoByAccessibilityIdUiThread(Message message) { |
| 318 | final int flags = message.arg1; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 319 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 320 | SomeArgs args = (SomeArgs) message.obj; |
| 321 | final int accessibilityViewId = args.argi1; |
| 322 | final int virtualDescendantId = args.argi2; |
| 323 | final int interactionId = args.argi3; |
| 324 | final IAccessibilityInteractionConnectionCallback callback = |
| 325 | (IAccessibilityInteractionConnectionCallback) args.arg1; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 326 | final MagnificationSpec spec = (MagnificationSpec) args.arg2; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 327 | final Region interactiveRegion = (Region) args.arg3; |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 328 | final Bundle arguments = (Bundle) args.arg4; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 329 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 330 | args.recycle(); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 331 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 332 | List<AccessibilityNodeInfo> infos = mTempAccessibilityNodeInfoList; |
| 333 | infos.clear(); |
| 334 | try { |
| 335 | if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) { |
| 336 | return; |
| 337 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 338 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags; |
Qasid Ahmad Sadiq | 834787a | 2019-01-18 00:01:54 -0800 | [diff] [blame] | 339 | final View root = findViewByAccessibilityId(accessibilityViewId); |
Rhed Jao | 4b87f31 | 2019-02-13 17:45:02 +0800 | [diff] [blame] | 340 | if (root != null && isShown(root)) { |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 341 | mPrefetcher.prefetchAccessibilityNodeInfos( |
| 342 | root, virtualDescendantId, flags, infos, arguments); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 343 | } |
| 344 | } finally { |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 345 | updateInfosForViewportAndReturnFindNodeResult( |
| 346 | infos, callback, interactionId, spec, interactiveRegion); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 350 | public void findAccessibilityNodeInfosByViewIdClientThread(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 351 | String viewId, Region interactiveRegion, int interactionId, |
| 352 | IAccessibilityInteractionConnectionCallback callback, int flags, int interrogatingPid, |
| 353 | long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 354 | Message message = mHandler.obtainMessage(); |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 355 | message.what = PrivateHandler.MSG_FIND_ACCESSIBILITY_NODE_INFOS_BY_VIEW_ID; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 356 | message.arg1 = flags; |
| 357 | message.arg2 = AccessibilityNodeInfo.getAccessibilityViewId(accessibilityNodeId); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 358 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 359 | SomeArgs args = SomeArgs.obtain(); |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 360 | args.argi1 = interactionId; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 361 | args.arg1 = callback; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 362 | args.arg2 = spec; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 363 | args.arg3 = viewId; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 364 | args.arg4 = interactiveRegion; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 365 | message.obj = args; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 366 | |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 367 | scheduleMessage(message, interrogatingPid, interrogatingTid, CONSIDER_REQUEST_PREPARERS); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 370 | private void findAccessibilityNodeInfosByViewIdUiThread(Message message) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 371 | final int flags = message.arg1; |
| 372 | final int accessibilityViewId = message.arg2; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 373 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 374 | SomeArgs args = (SomeArgs) message.obj; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 375 | final int interactionId = args.argi1; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 376 | final IAccessibilityInteractionConnectionCallback callback = |
| 377 | (IAccessibilityInteractionConnectionCallback) args.arg1; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 378 | final MagnificationSpec spec = (MagnificationSpec) args.arg2; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 379 | final String viewId = (String) args.arg3; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 380 | final Region interactiveRegion = (Region) args.arg4; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 381 | args.recycle(); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 382 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 383 | final List<AccessibilityNodeInfo> infos = mTempAccessibilityNodeInfoList; |
| 384 | infos.clear(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 385 | try { |
| 386 | if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) { |
| 387 | return; |
| 388 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 389 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags; |
Qasid Ahmad Sadiq | 834787a | 2019-01-18 00:01:54 -0800 | [diff] [blame] | 390 | final View root = findViewByAccessibilityId(accessibilityViewId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 391 | if (root != null) { |
Svetoslav | a33243e | 2013-02-11 15:43:46 -0800 | [diff] [blame] | 392 | final int resolvedViewId = root.getContext().getResources() |
| 393 | .getIdentifier(viewId, null, null); |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 394 | if (resolvedViewId <= 0) { |
| 395 | return; |
| 396 | } |
| 397 | if (mAddNodeInfosForViewId == null) { |
| 398 | mAddNodeInfosForViewId = new AddNodeInfosForViewId(); |
| 399 | } |
| 400 | mAddNodeInfosForViewId.init(resolvedViewId, infos); |
| 401 | root.findViewByPredicate(mAddNodeInfosForViewId); |
| 402 | mAddNodeInfosForViewId.reset(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 403 | } |
| 404 | } finally { |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 405 | updateInfosForViewportAndReturnFindNodeResult( |
| 406 | infos, callback, interactionId, spec, interactiveRegion); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
| 410 | public void findAccessibilityNodeInfosByTextClientThread(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 411 | String text, Region interactiveRegion, int interactionId, |
| 412 | IAccessibilityInteractionConnectionCallback callback, int flags, int interrogatingPid, |
| 413 | long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 414 | Message message = mHandler.obtainMessage(); |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 415 | message.what = PrivateHandler.MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_TEXT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 416 | message.arg1 = flags; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 417 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 418 | SomeArgs args = SomeArgs.obtain(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 419 | args.arg1 = text; |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 420 | args.arg2 = callback; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 421 | args.arg3 = spec; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 422 | args.argi1 = AccessibilityNodeInfo.getAccessibilityViewId(accessibilityNodeId); |
| 423 | args.argi2 = AccessibilityNodeInfo.getVirtualDescendantId(accessibilityNodeId); |
| 424 | args.argi3 = interactionId; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 425 | args.arg4 = interactiveRegion; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 426 | message.obj = args; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 427 | |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 428 | scheduleMessage(message, interrogatingPid, interrogatingTid, CONSIDER_REQUEST_PREPARERS); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | private void findAccessibilityNodeInfosByTextUiThread(Message message) { |
| 432 | final int flags = message.arg1; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 433 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 434 | SomeArgs args = (SomeArgs) message.obj; |
| 435 | final String text = (String) args.arg1; |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 436 | final IAccessibilityInteractionConnectionCallback callback = |
| 437 | (IAccessibilityInteractionConnectionCallback) args.arg2; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 438 | final MagnificationSpec spec = (MagnificationSpec) args.arg3; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 439 | final int accessibilityViewId = args.argi1; |
| 440 | final int virtualDescendantId = args.argi2; |
| 441 | final int interactionId = args.argi3; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 442 | final Region interactiveRegion = (Region) args.arg4; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 443 | args.recycle(); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 444 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 445 | List<AccessibilityNodeInfo> infos = null; |
| 446 | try { |
| 447 | if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) { |
| 448 | return; |
| 449 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 450 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags; |
Qasid Ahmad Sadiq | 834787a | 2019-01-18 00:01:54 -0800 | [diff] [blame] | 451 | final View root = findViewByAccessibilityId(accessibilityViewId); |
Rhed Jao | 4b87f31 | 2019-02-13 17:45:02 +0800 | [diff] [blame] | 452 | if (root != null && isShown(root)) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 453 | AccessibilityNodeProvider provider = root.getAccessibilityNodeProvider(); |
| 454 | if (provider != null) { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 455 | infos = provider.findAccessibilityNodeInfosByText(text, |
| 456 | virtualDescendantId); |
| 457 | } else if (virtualDescendantId == AccessibilityNodeProvider.HOST_VIEW_ID) { |
Svetoslav Ganov | 30ac645 | 2012-06-01 09:10:25 -0700 | [diff] [blame] | 458 | ArrayList<View> foundViews = mTempArrayList; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 459 | foundViews.clear(); |
| 460 | root.findViewsWithText(foundViews, text, View.FIND_VIEWS_WITH_TEXT |
| 461 | | View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION |
| 462 | | View.FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS); |
| 463 | if (!foundViews.isEmpty()) { |
| 464 | infos = mTempAccessibilityNodeInfoList; |
| 465 | infos.clear(); |
| 466 | final int viewCount = foundViews.size(); |
| 467 | for (int i = 0; i < viewCount; i++) { |
| 468 | View foundView = foundViews.get(i); |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 469 | if (isShown(foundView)) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 470 | provider = foundView.getAccessibilityNodeProvider(); |
| 471 | if (provider != null) { |
| 472 | List<AccessibilityNodeInfo> infosFromProvider = |
| 473 | provider.findAccessibilityNodeInfosByText(text, |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 474 | AccessibilityNodeProvider.HOST_VIEW_ID); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 475 | if (infosFromProvider != null) { |
| 476 | infos.addAll(infosFromProvider); |
| 477 | } |
| 478 | } else { |
| 479 | infos.add(foundView.createAccessibilityNodeInfo()); |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | } finally { |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 487 | updateInfosForViewportAndReturnFindNodeResult( |
| 488 | infos, callback, interactionId, spec, interactiveRegion); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 492 | public void findFocusClientThread(long accessibilityNodeId, int focusType, |
| 493 | Region interactiveRegion, int interactionId, |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 494 | IAccessibilityInteractionConnectionCallback callback, int flags, int interrogatingPid, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 495 | long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 496 | Message message = mHandler.obtainMessage(); |
| 497 | message.what = PrivateHandler.MSG_FIND_FOCUS; |
| 498 | message.arg1 = flags; |
| 499 | message.arg2 = focusType; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 500 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 501 | SomeArgs args = SomeArgs.obtain(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 502 | args.argi1 = interactionId; |
| 503 | args.argi2 = AccessibilityNodeInfo.getAccessibilityViewId(accessibilityNodeId); |
| 504 | args.argi3 = AccessibilityNodeInfo.getVirtualDescendantId(accessibilityNodeId); |
| 505 | args.arg1 = callback; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 506 | args.arg2 = spec; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 507 | args.arg3 = interactiveRegion; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 508 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 509 | message.obj = args; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 510 | |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 511 | scheduleMessage(message, interrogatingPid, interrogatingTid, CONSIDER_REQUEST_PREPARERS); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | private void findFocusUiThread(Message message) { |
| 515 | final int flags = message.arg1; |
| 516 | final int focusType = message.arg2; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 517 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 518 | SomeArgs args = (SomeArgs) message.obj; |
| 519 | final int interactionId = args.argi1; |
| 520 | final int accessibilityViewId = args.argi2; |
| 521 | final int virtualDescendantId = args.argi3; |
| 522 | final IAccessibilityInteractionConnectionCallback callback = |
| 523 | (IAccessibilityInteractionConnectionCallback) args.arg1; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 524 | final MagnificationSpec spec = (MagnificationSpec) args.arg2; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 525 | final Region interactiveRegion = (Region) args.arg3; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 526 | args.recycle(); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 527 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 528 | AccessibilityNodeInfo focused = null; |
| 529 | try { |
| 530 | if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) { |
| 531 | return; |
| 532 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 533 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags; |
Qasid Ahmad Sadiq | 834787a | 2019-01-18 00:01:54 -0800 | [diff] [blame] | 534 | final View root = findViewByAccessibilityId(accessibilityViewId); |
Rhed Jao | 4b87f31 | 2019-02-13 17:45:02 +0800 | [diff] [blame] | 535 | if (root != null && isShown(root)) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 536 | switch (focusType) { |
| 537 | case AccessibilityNodeInfo.FOCUS_ACCESSIBILITY: { |
| 538 | View host = mViewRootImpl.mAccessibilityFocusedHost; |
| 539 | // If there is no accessibility focus host or it is not a descendant |
| 540 | // of the root from which to start the search, then the search failed. |
| 541 | if (host == null || !ViewRootImpl.isViewDescendantOf(host, root)) { |
| 542 | break; |
| 543 | } |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 544 | // The focused view not shown, we failed. |
| 545 | if (!isShown(host)) { |
| 546 | break; |
| 547 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 548 | // If the host has a provider ask this provider to search for the |
| 549 | // focus instead fetching all provider nodes to do the search here. |
| 550 | AccessibilityNodeProvider provider = host.getAccessibilityNodeProvider(); |
| 551 | if (provider != null) { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 552 | if (mViewRootImpl.mAccessibilityFocusedVirtualView != null) { |
| 553 | focused = AccessibilityNodeInfo.obtain( |
| 554 | mViewRootImpl.mAccessibilityFocusedVirtualView); |
| 555 | } |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 556 | } else if (virtualDescendantId == AccessibilityNodeProvider.HOST_VIEW_ID) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 557 | focused = host.createAccessibilityNodeInfo(); |
| 558 | } |
| 559 | } break; |
| 560 | case AccessibilityNodeInfo.FOCUS_INPUT: { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 561 | View target = root.findFocus(); |
Qasid Ahmad Sadiq | 834787a | 2019-01-18 00:01:54 -0800 | [diff] [blame] | 562 | if (!isShown(target)) { |
Alan Viverette | 2e1e081 | 2013-09-30 13:45:55 -0700 | [diff] [blame] | 563 | break; |
| 564 | } |
| 565 | AccessibilityNodeProvider provider = target.getAccessibilityNodeProvider(); |
| 566 | if (provider != null) { |
| 567 | focused = provider.findFocus(focusType); |
| 568 | } |
| 569 | if (focused == null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 570 | focused = target.createAccessibilityNodeInfo(); |
| 571 | } |
| 572 | } break; |
| 573 | default: |
| 574 | throw new IllegalArgumentException("Unknown focus type: " + focusType); |
| 575 | } |
| 576 | } |
| 577 | } finally { |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 578 | updateInfoForViewportAndReturnFindNodeResult( |
| 579 | focused, callback, interactionId, spec, interactiveRegion); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 583 | public void focusSearchClientThread(long accessibilityNodeId, int direction, |
| 584 | Region interactiveRegion, int interactionId, |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 585 | IAccessibilityInteractionConnectionCallback callback, int flags, int interrogatingPid, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 586 | long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 587 | Message message = mHandler.obtainMessage(); |
| 588 | message.what = PrivateHandler.MSG_FOCUS_SEARCH; |
| 589 | message.arg1 = flags; |
| 590 | message.arg2 = AccessibilityNodeInfo.getAccessibilityViewId(accessibilityNodeId); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 591 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 592 | SomeArgs args = SomeArgs.obtain(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 593 | args.argi2 = direction; |
| 594 | args.argi3 = interactionId; |
| 595 | args.arg1 = callback; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 596 | args.arg2 = spec; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 597 | args.arg3 = interactiveRegion; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 598 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 599 | message.obj = args; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 600 | |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 601 | scheduleMessage(message, interrogatingPid, interrogatingTid, CONSIDER_REQUEST_PREPARERS); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | private void focusSearchUiThread(Message message) { |
| 605 | final int flags = message.arg1; |
| 606 | final int accessibilityViewId = message.arg2; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 607 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 608 | SomeArgs args = (SomeArgs) message.obj; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 609 | final int direction = args.argi2; |
| 610 | final int interactionId = args.argi3; |
| 611 | final IAccessibilityInteractionConnectionCallback callback = |
| 612 | (IAccessibilityInteractionConnectionCallback) args.arg1; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 613 | final MagnificationSpec spec = (MagnificationSpec) args.arg2; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 614 | final Region interactiveRegion = (Region) args.arg3; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 615 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 616 | args.recycle(); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 617 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 618 | AccessibilityNodeInfo next = null; |
| 619 | try { |
| 620 | if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) { |
| 621 | return; |
| 622 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 623 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags; |
Qasid Ahmad Sadiq | 834787a | 2019-01-18 00:01:54 -0800 | [diff] [blame] | 624 | final View root = findViewByAccessibilityId(accessibilityViewId); |
Rhed Jao | 4b87f31 | 2019-02-13 17:45:02 +0800 | [diff] [blame] | 625 | if (root != null && isShown(root)) { |
Svetoslav Ganov | 27e2da7 | 2012-07-02 18:12:00 -0700 | [diff] [blame] | 626 | View nextView = root.focusSearch(direction); |
| 627 | if (nextView != null) { |
| 628 | next = nextView.createAccessibilityNodeInfo(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | } finally { |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 632 | updateInfoForViewportAndReturnFindNodeResult( |
| 633 | next, callback, interactionId, spec, interactiveRegion); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | |
| 637 | public void performAccessibilityActionClientThread(long accessibilityNodeId, int action, |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 638 | Bundle arguments, int interactionId, |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 639 | IAccessibilityInteractionConnectionCallback callback, int flags, int interrogatingPid, |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 640 | long interrogatingTid) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 641 | Message message = mHandler.obtainMessage(); |
| 642 | message.what = PrivateHandler.MSG_PERFORM_ACCESSIBILITY_ACTION; |
| 643 | message.arg1 = flags; |
| 644 | message.arg2 = AccessibilityNodeInfo.getAccessibilityViewId(accessibilityNodeId); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 645 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 646 | SomeArgs args = SomeArgs.obtain(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 647 | args.argi1 = AccessibilityNodeInfo.getVirtualDescendantId(accessibilityNodeId); |
| 648 | args.argi2 = action; |
| 649 | args.argi3 = interactionId; |
| 650 | args.arg1 = callback; |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 651 | args.arg2 = arguments; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 652 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 653 | message.obj = args; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 654 | |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 655 | scheduleMessage(message, interrogatingPid, interrogatingTid, CONSIDER_REQUEST_PREPARERS); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 656 | } |
| 657 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 658 | private void performAccessibilityActionUiThread(Message message) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 659 | final int flags = message.arg1; |
| 660 | final int accessibilityViewId = message.arg2; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 661 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 662 | SomeArgs args = (SomeArgs) message.obj; |
| 663 | final int virtualDescendantId = args.argi1; |
| 664 | final int action = args.argi2; |
| 665 | final int interactionId = args.argi3; |
| 666 | final IAccessibilityInteractionConnectionCallback callback = |
| 667 | (IAccessibilityInteractionConnectionCallback) args.arg1; |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 668 | Bundle arguments = (Bundle) args.arg2; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 669 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 670 | args.recycle(); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 671 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 672 | boolean succeeded = false; |
| 673 | try { |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 674 | if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null || |
| 675 | mViewRootImpl.mStopped || mViewRootImpl.mPausedForTransition) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 676 | return; |
| 677 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 678 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags; |
Qasid Ahmad Sadiq | 834787a | 2019-01-18 00:01:54 -0800 | [diff] [blame] | 679 | final View target = findViewByAccessibilityId(accessibilityViewId); |
Rhed Jao | 4b87f31 | 2019-02-13 17:45:02 +0800 | [diff] [blame] | 680 | if (target != null && isShown(target)) { |
Phil Weaver | 193520e | 2016-12-13 09:39:06 -0800 | [diff] [blame] | 681 | if (action == R.id.accessibilityActionClickOnClickableSpan) { |
| 682 | // Handle this hidden action separately |
| 683 | succeeded = handleClickableSpanActionUiThread( |
| 684 | target, virtualDescendantId, arguments); |
| 685 | } else { |
| 686 | AccessibilityNodeProvider provider = target.getAccessibilityNodeProvider(); |
| 687 | if (provider != null) { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 688 | succeeded = provider.performAction(virtualDescendantId, action, |
| 689 | arguments); |
| 690 | } else if (virtualDescendantId == AccessibilityNodeProvider.HOST_VIEW_ID) { |
Phil Weaver | 193520e | 2016-12-13 09:39:06 -0800 | [diff] [blame] | 691 | succeeded = target.performAccessibilityAction(action, arguments); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 692 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 693 | } |
| 694 | } |
| 695 | } finally { |
| 696 | try { |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 697 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = 0; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 698 | callback.setPerformAccessibilityActionResult(succeeded, interactionId); |
| 699 | } catch (RemoteException re) { |
| 700 | /* ignore - the other side will time out */ |
| 701 | } |
| 702 | } |
| 703 | } |
| 704 | |
Rhed Jao | 23813d9 | 2018-12-18 21:30:52 +0800 | [diff] [blame] | 705 | /** |
| 706 | * Finds the accessibility focused node in the root, and clears the accessibility focus. |
| 707 | */ |
| 708 | public void clearAccessibilityFocusClientThread() { |
| 709 | final Message message = mHandler.obtainMessage(); |
| 710 | message.what = PrivateHandler.MSG_CLEAR_ACCESSIBILITY_FOCUS; |
| 711 | |
| 712 | // Don't care about pid and tid because there's no interrogating client for this message. |
| 713 | scheduleMessage(message, 0, 0, CONSIDER_REQUEST_PREPARERS); |
| 714 | } |
| 715 | |
| 716 | private void clearAccessibilityFocusUiThread() { |
| 717 | if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) { |
| 718 | return; |
| 719 | } |
| 720 | try { |
| 721 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = |
| 722 | AccessibilityNodeInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS; |
| 723 | final View root = mViewRootImpl.mView; |
| 724 | if (root != null && isShown(root)) { |
| 725 | final View host = mViewRootImpl.mAccessibilityFocusedHost; |
| 726 | // If there is no accessibility focus host or it is not a descendant |
| 727 | // of the root from which to start the search, then the search failed. |
| 728 | if (host == null || !ViewRootImpl.isViewDescendantOf(host, root)) { |
| 729 | return; |
| 730 | } |
| 731 | final AccessibilityNodeProvider provider = host.getAccessibilityNodeProvider(); |
| 732 | final AccessibilityNodeInfo focusNode = |
| 733 | mViewRootImpl.mAccessibilityFocusedVirtualView; |
| 734 | if (provider != null && focusNode != null) { |
| 735 | final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 736 | focusNode.getSourceNodeId()); |
| 737 | provider.performAction(virtualNodeId, |
| 738 | AccessibilityAction.ACTION_CLEAR_ACCESSIBILITY_FOCUS.getId(), |
| 739 | null); |
| 740 | } else { |
| 741 | host.performAccessibilityAction( |
| 742 | AccessibilityAction.ACTION_CLEAR_ACCESSIBILITY_FOCUS.getId(), |
| 743 | null); |
| 744 | } |
| 745 | } |
| 746 | } finally { |
| 747 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = 0; |
| 748 | } |
| 749 | } |
| 750 | |
Jackal Guo | 8bcc0a9 | 2019-04-16 15:26:00 +0800 | [diff] [blame] | 751 | /** |
| 752 | * Notify outside touch event to the target window. |
| 753 | */ |
| 754 | public void notifyOutsideTouchClientThread() { |
| 755 | final Message message = mHandler.obtainMessage(); |
| 756 | message.what = PrivateHandler.MSG_NOTIFY_OUTSIDE_TOUCH; |
| 757 | |
| 758 | // Don't care about pid and tid because there's no interrogating client for this message. |
| 759 | scheduleMessage(message, 0, 0, CONSIDER_REQUEST_PREPARERS); |
| 760 | } |
| 761 | |
| 762 | private void notifyOutsideTouchUiThread() { |
| 763 | if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null |
| 764 | || mViewRootImpl.mStopped || mViewRootImpl.mPausedForTransition) { |
| 765 | return; |
| 766 | } |
| 767 | final View root = mViewRootImpl.mView; |
| 768 | if (root != null && isShown(root)) { |
| 769 | // trigger ACTION_OUTSIDE to notify windows |
| 770 | final long now = SystemClock.uptimeMillis(); |
| 771 | final MotionEvent event = MotionEvent.obtain(now, now, MotionEvent.ACTION_OUTSIDE, |
| 772 | 0, 0, 0); |
| 773 | event.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 774 | mViewRootImpl.dispatchInputEvent(event); |
| 775 | } |
| 776 | } |
| 777 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 778 | private View findViewByAccessibilityId(int accessibilityId) { |
Qasid Ahmad Sadiq | 834787a | 2019-01-18 00:01:54 -0800 | [diff] [blame] | 779 | if (accessibilityId == AccessibilityNodeInfo.ROOT_ITEM_ID) { |
| 780 | return mViewRootImpl.mView; |
| 781 | } else { |
Rhed Jao | 4b87f31 | 2019-02-13 17:45:02 +0800 | [diff] [blame] | 782 | return AccessibilityNodeIdManager.getInstance().findView(accessibilityId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 783 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 784 | } |
| 785 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 786 | private void applyAppScaleAndMagnificationSpecIfNeeded(List<AccessibilityNodeInfo> infos, |
| 787 | MagnificationSpec spec) { |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 788 | if (infos == null) { |
| 789 | return; |
| 790 | } |
| 791 | final float applicationScale = mViewRootImpl.mAttachInfo.mApplicationScale; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 792 | if (shouldApplyAppScaleAndMagnificationSpec(applicationScale, spec)) { |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 793 | final int infoCount = infos.size(); |
| 794 | for (int i = 0; i < infoCount; i++) { |
| 795 | AccessibilityNodeInfo info = infos.get(i); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 796 | applyAppScaleAndMagnificationSpecIfNeeded(info, spec); |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 797 | } |
| 798 | } |
| 799 | } |
| 800 | |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 801 | private void adjustIsVisibleToUserIfNeeded(List<AccessibilityNodeInfo> infos, |
| 802 | Region interactiveRegion) { |
| 803 | if (interactiveRegion == null || infos == null) { |
| 804 | return; |
| 805 | } |
| 806 | final int infoCount = infos.size(); |
| 807 | for (int i = 0; i < infoCount; i++) { |
| 808 | AccessibilityNodeInfo info = infos.get(i); |
| 809 | adjustIsVisibleToUserIfNeeded(info, interactiveRegion); |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | private void adjustIsVisibleToUserIfNeeded(AccessibilityNodeInfo info, |
| 814 | Region interactiveRegion) { |
| 815 | if (interactiveRegion == null || info == null) { |
| 816 | return; |
| 817 | } |
| 818 | Rect boundsInScreen = mTempRect; |
| 819 | info.getBoundsInScreen(boundsInScreen); |
Jackal Guo | ecd09bb | 2019-03-20 17:43:19 +0800 | [diff] [blame] | 820 | if (interactiveRegion.quickReject(boundsInScreen) && !shouldBypassAdjustIsVisible()) { |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 821 | info.setVisibleToUser(false); |
| 822 | } |
| 823 | } |
| 824 | |
Jackal Guo | ecd09bb | 2019-03-20 17:43:19 +0800 | [diff] [blame] | 825 | private boolean shouldBypassAdjustIsVisible() { |
| 826 | final int windowType = mViewRootImpl.mOrigWindowType; |
| 827 | if (windowType == TYPE_INPUT_METHOD) { |
| 828 | return true; |
| 829 | } |
| 830 | return false; |
| 831 | } |
| 832 | |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 833 | private void adjustBoundsInScreenIfNeeded(List<AccessibilityNodeInfo> infos) { |
| 834 | if (infos == null || shouldBypassAdjustBoundsInScreen()) { |
| 835 | return; |
| 836 | } |
| 837 | final int infoCount = infos.size(); |
| 838 | for (int i = 0; i < infoCount; i++) { |
| 839 | final AccessibilityNodeInfo info = infos.get(i); |
| 840 | adjustBoundsInScreenIfNeeded(info); |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | private void adjustBoundsInScreenIfNeeded(AccessibilityNodeInfo info) { |
| 845 | if (info == null || shouldBypassAdjustBoundsInScreen()) { |
| 846 | return; |
| 847 | } |
| 848 | final Rect boundsInScreen = mTempRect; |
| 849 | info.getBoundsInScreen(boundsInScreen); |
| 850 | boundsInScreen.offset(mViewRootImpl.mAttachInfo.mLocationInParentDisplay.x, |
| 851 | mViewRootImpl.mAttachInfo.mLocationInParentDisplay.y); |
| 852 | info.setBoundsInScreen(boundsInScreen); |
| 853 | } |
| 854 | |
| 855 | private boolean shouldBypassAdjustBoundsInScreen() { |
| 856 | return mViewRootImpl.mAttachInfo.mLocationInParentDisplay.equals(0, 0); |
| 857 | } |
| 858 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 859 | private void applyAppScaleAndMagnificationSpecIfNeeded(AccessibilityNodeInfo info, |
| 860 | MagnificationSpec spec) { |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 861 | if (info == null) { |
| 862 | return; |
| 863 | } |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 864 | |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 865 | final float applicationScale = mViewRootImpl.mAttachInfo.mApplicationScale; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 866 | if (!shouldApplyAppScaleAndMagnificationSpec(applicationScale, spec)) { |
| 867 | return; |
| 868 | } |
| 869 | |
| 870 | Rect boundsInParent = mTempRect; |
| 871 | Rect boundsInScreen = mTempRect1; |
| 872 | |
| 873 | info.getBoundsInParent(boundsInParent); |
| 874 | info.getBoundsInScreen(boundsInScreen); |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 875 | if (applicationScale != 1.0f) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 876 | boundsInParent.scale(applicationScale); |
| 877 | boundsInScreen.scale(applicationScale); |
| 878 | } |
| 879 | if (spec != null) { |
| 880 | boundsInParent.scale(spec.scale); |
| 881 | // boundsInParent must not be offset. |
| 882 | boundsInScreen.scale(spec.scale); |
| 883 | boundsInScreen.offset((int) spec.offsetX, (int) spec.offsetY); |
| 884 | } |
| 885 | info.setBoundsInParent(boundsInParent); |
| 886 | info.setBoundsInScreen(boundsInScreen); |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 887 | |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 888 | // Scale text locations if they are present |
| 889 | if (info.hasExtras()) { |
| 890 | Bundle extras = info.getExtras(); |
| 891 | Parcelable[] textLocations = |
| 892 | extras.getParcelableArray(EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY); |
| 893 | if (textLocations != null) { |
| 894 | for (int i = 0; i < textLocations.length; i++) { |
| 895 | // Unchecked cast - an app that puts other objects in this bundle with this |
| 896 | // key will crash. |
| 897 | RectF textLocation = ((RectF) textLocations[i]); |
| 898 | textLocation.scale(applicationScale); |
| 899 | if (spec != null) { |
| 900 | textLocation.scale(spec.scale); |
| 901 | textLocation.offset(spec.offsetX, spec.offsetY); |
| 902 | } |
| 903 | } |
| 904 | } |
| 905 | } |
| 906 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 907 | if (spec != null) { |
| 908 | AttachInfo attachInfo = mViewRootImpl.mAttachInfo; |
| 909 | if (attachInfo.mDisplay == null) { |
| 910 | return; |
| 911 | } |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 912 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 913 | final float scale = attachInfo.mApplicationScale * spec.scale; |
| 914 | |
| 915 | Rect visibleWinFrame = mTempRect1; |
| 916 | visibleWinFrame.left = (int) (attachInfo.mWindowLeft * scale + spec.offsetX); |
| 917 | visibleWinFrame.top = (int) (attachInfo.mWindowTop * scale + spec.offsetY); |
| 918 | visibleWinFrame.right = (int) (visibleWinFrame.left + mViewRootImpl.mWidth * scale); |
| 919 | visibleWinFrame.bottom = (int) (visibleWinFrame.top + mViewRootImpl.mHeight * scale); |
| 920 | |
| 921 | attachInfo.mDisplay.getRealSize(mTempPoint); |
| 922 | final int displayWidth = mTempPoint.x; |
| 923 | final int displayHeight = mTempPoint.y; |
| 924 | |
| 925 | Rect visibleDisplayFrame = mTempRect2; |
| 926 | visibleDisplayFrame.set(0, 0, displayWidth, displayHeight); |
| 927 | |
Doris Liu | 9607fbe | 2015-05-28 17:17:28 -0700 | [diff] [blame] | 928 | if (!visibleWinFrame.intersect(visibleDisplayFrame)) { |
| 929 | // If there's no intersection with display, set visibleWinFrame empty. |
| 930 | visibleDisplayFrame.setEmpty(); |
| 931 | } |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 932 | |
| 933 | if (!visibleWinFrame.intersects(boundsInScreen.left, boundsInScreen.top, |
| 934 | boundsInScreen.right, boundsInScreen.bottom)) { |
| 935 | info.setVisibleToUser(false); |
| 936 | } |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 940 | private boolean shouldApplyAppScaleAndMagnificationSpec(float appScale, |
| 941 | MagnificationSpec spec) { |
| 942 | return (appScale != 1.0f || (spec != null && !spec.isNop())); |
| 943 | } |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 944 | |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 945 | private void updateInfosForViewportAndReturnFindNodeResult(List<AccessibilityNodeInfo> infos, |
| 946 | IAccessibilityInteractionConnectionCallback callback, int interactionId, |
| 947 | MagnificationSpec spec, Region interactiveRegion) { |
| 948 | try { |
| 949 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = 0; |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 950 | adjustBoundsInScreenIfNeeded(infos); |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 951 | applyAppScaleAndMagnificationSpecIfNeeded(infos, spec); |
| 952 | adjustIsVisibleToUserIfNeeded(infos, interactiveRegion); |
| 953 | callback.setFindAccessibilityNodeInfosResult(infos, interactionId); |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 954 | if (infos != null) { |
| 955 | infos.clear(); |
| 956 | } |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 957 | } catch (RemoteException re) { |
| 958 | /* ignore - the other side will time out */ |
| 959 | } finally { |
| 960 | recycleMagnificationSpecAndRegionIfNeeded(spec, interactiveRegion); |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | private void updateInfoForViewportAndReturnFindNodeResult(AccessibilityNodeInfo info, |
| 965 | IAccessibilityInteractionConnectionCallback callback, int interactionId, |
| 966 | MagnificationSpec spec, Region interactiveRegion) { |
| 967 | try { |
| 968 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = 0; |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 969 | adjustBoundsInScreenIfNeeded(info); |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 970 | applyAppScaleAndMagnificationSpecIfNeeded(info, spec); |
| 971 | adjustIsVisibleToUserIfNeeded(info, interactiveRegion); |
| 972 | callback.setFindAccessibilityNodeInfoResult(info, interactionId); |
| 973 | } catch (RemoteException re) { |
| 974 | /* ignore - the other side will time out */ |
| 975 | } finally { |
| 976 | recycleMagnificationSpecAndRegionIfNeeded(spec, interactiveRegion); |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | private void recycleMagnificationSpecAndRegionIfNeeded(MagnificationSpec spec, Region region) { |
| 981 | if (android.os.Process.myPid() != Binder.getCallingPid()) { |
| 982 | // Specs are cached in the system process and obtained from a pool when read from |
| 983 | // a parcel, so only recycle the spec if called from another process. |
| 984 | if (spec != null) { |
| 985 | spec.recycle(); |
| 986 | } |
| 987 | } else { |
| 988 | // Regions are obtained in the system process and instantiated when read from |
| 989 | // a parcel, so only recycle the region if caled from the same process. |
| 990 | if (region != null) { |
| 991 | region.recycle(); |
| 992 | } |
| 993 | } |
| 994 | } |
| 995 | |
Phil Weaver | 193520e | 2016-12-13 09:39:06 -0800 | [diff] [blame] | 996 | private boolean handleClickableSpanActionUiThread( |
| 997 | View view, int virtualDescendantId, Bundle arguments) { |
| 998 | Parcelable span = arguments.getParcelable(ACTION_ARGUMENT_ACCESSIBLE_CLICKABLE_SPAN); |
| 999 | if (!(span instanceof AccessibilityClickableSpan)) { |
| 1000 | return false; |
| 1001 | } |
| 1002 | |
| 1003 | // Find the original ClickableSpan if it's still on the screen |
| 1004 | AccessibilityNodeInfo infoWithSpan = null; |
| 1005 | AccessibilityNodeProvider provider = view.getAccessibilityNodeProvider(); |
| 1006 | if (provider != null) { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 1007 | infoWithSpan = provider.createAccessibilityNodeInfo(virtualDescendantId); |
| 1008 | } else if (virtualDescendantId == AccessibilityNodeProvider.HOST_VIEW_ID) { |
Phil Weaver | 193520e | 2016-12-13 09:39:06 -0800 | [diff] [blame] | 1009 | infoWithSpan = view.createAccessibilityNodeInfo(); |
| 1010 | } |
| 1011 | if (infoWithSpan == null) { |
| 1012 | return false; |
| 1013 | } |
| 1014 | |
| 1015 | // Click on the corresponding span |
| 1016 | ClickableSpan clickableSpan = ((AccessibilityClickableSpan) span).findClickableSpan( |
| 1017 | infoWithSpan.getOriginalText()); |
| 1018 | if (clickableSpan != null) { |
| 1019 | clickableSpan.onClick(view); |
| 1020 | return true; |
| 1021 | } |
| 1022 | return false; |
| 1023 | } |
| 1024 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1025 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1026 | * This class encapsulates a prefetching strategy for the accessibility APIs for |
| 1027 | * querying window content. It is responsible to prefetch a batch of |
| 1028 | * AccessibilityNodeInfos in addition to the one for a requested node. |
| 1029 | */ |
| 1030 | private class AccessibilityNodePrefetcher { |
| 1031 | |
| 1032 | private static final int MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE = 50; |
| 1033 | |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 1034 | private final ArrayList<View> mTempViewList = new ArrayList<View>(); |
| 1035 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1036 | public void prefetchAccessibilityNodeInfos(View view, int virtualViewId, int fetchFlags, |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 1037 | List<AccessibilityNodeInfo> outInfos, Bundle arguments) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1038 | AccessibilityNodeProvider provider = view.getAccessibilityNodeProvider(); |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 1039 | // Determine if we'll be populating extra data |
| 1040 | final String extraDataRequested = (arguments == null) ? null |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 1041 | : arguments.getString(EXTRA_DATA_REQUESTED_KEY); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1042 | if (provider == null) { |
| 1043 | AccessibilityNodeInfo root = view.createAccessibilityNodeInfo(); |
| 1044 | if (root != null) { |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 1045 | if (extraDataRequested != null) { |
| 1046 | view.addExtraDataToAccessibilityNodeInfo( |
| 1047 | root, extraDataRequested, arguments); |
| 1048 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1049 | outInfos.add(root); |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1050 | if ((fetchFlags & AccessibilityNodeInfo.FLAG_PREFETCH_PREDECESSORS) != 0) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1051 | prefetchPredecessorsOfRealNode(view, outInfos); |
| 1052 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1053 | if ((fetchFlags & AccessibilityNodeInfo.FLAG_PREFETCH_SIBLINGS) != 0) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1054 | prefetchSiblingsOfRealNode(view, outInfos); |
| 1055 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1056 | if ((fetchFlags & AccessibilityNodeInfo.FLAG_PREFETCH_DESCENDANTS) != 0) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1057 | prefetchDescendantsOfRealNode(view, outInfos); |
| 1058 | } |
| 1059 | } |
| 1060 | } else { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 1061 | final AccessibilityNodeInfo root = |
| 1062 | provider.createAccessibilityNodeInfo(virtualViewId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1063 | if (root != null) { |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 1064 | if (extraDataRequested != null) { |
| 1065 | provider.addExtraDataToAccessibilityNodeInfo( |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 1066 | virtualViewId, root, extraDataRequested, arguments); |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 1067 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1068 | outInfos.add(root); |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1069 | if ((fetchFlags & AccessibilityNodeInfo.FLAG_PREFETCH_PREDECESSORS) != 0) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1070 | prefetchPredecessorsOfVirtualNode(root, view, provider, outInfos); |
| 1071 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1072 | if ((fetchFlags & AccessibilityNodeInfo.FLAG_PREFETCH_SIBLINGS) != 0) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1073 | prefetchSiblingsOfVirtualNode(root, view, provider, outInfos); |
| 1074 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1075 | if ((fetchFlags & AccessibilityNodeInfo.FLAG_PREFETCH_DESCENDANTS) != 0) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1076 | prefetchDescendantsOfVirtualNode(root, provider, outInfos); |
| 1077 | } |
| 1078 | } |
| 1079 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1080 | if (ENFORCE_NODE_TREE_CONSISTENT) { |
| 1081 | enforceNodeTreeConsistent(outInfos); |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | private void enforceNodeTreeConsistent(List<AccessibilityNodeInfo> nodes) { |
| 1086 | LongSparseArray<AccessibilityNodeInfo> nodeMap = |
| 1087 | new LongSparseArray<AccessibilityNodeInfo>(); |
| 1088 | final int nodeCount = nodes.size(); |
| 1089 | for (int i = 0; i < nodeCount; i++) { |
| 1090 | AccessibilityNodeInfo node = nodes.get(i); |
| 1091 | nodeMap.put(node.getSourceNodeId(), node); |
| 1092 | } |
| 1093 | |
| 1094 | // If the nodes are a tree it does not matter from |
| 1095 | // which node we start to search for the root. |
| 1096 | AccessibilityNodeInfo root = nodeMap.valueAt(0); |
| 1097 | AccessibilityNodeInfo parent = root; |
| 1098 | while (parent != null) { |
| 1099 | root = parent; |
| 1100 | parent = nodeMap.get(parent.getParentNodeId()); |
| 1101 | } |
| 1102 | |
| 1103 | // Traverse the tree and do some checks. |
| 1104 | AccessibilityNodeInfo accessFocus = null; |
| 1105 | AccessibilityNodeInfo inputFocus = null; |
| 1106 | HashSet<AccessibilityNodeInfo> seen = new HashSet<AccessibilityNodeInfo>(); |
| 1107 | Queue<AccessibilityNodeInfo> fringe = new LinkedList<AccessibilityNodeInfo>(); |
| 1108 | fringe.add(root); |
| 1109 | |
| 1110 | while (!fringe.isEmpty()) { |
| 1111 | AccessibilityNodeInfo current = fringe.poll(); |
| 1112 | |
| 1113 | // Check for duplicates |
| 1114 | if (!seen.add(current)) { |
| 1115 | throw new IllegalStateException("Duplicate node: " |
| 1116 | + current + " in window:" |
| 1117 | + mViewRootImpl.mAttachInfo.mAccessibilityWindowId); |
| 1118 | } |
| 1119 | |
| 1120 | // Check for one accessibility focus. |
| 1121 | if (current.isAccessibilityFocused()) { |
| 1122 | if (accessFocus != null) { |
| 1123 | throw new IllegalStateException("Duplicate accessibility focus:" |
| 1124 | + current |
| 1125 | + " in window:" + mViewRootImpl.mAttachInfo.mAccessibilityWindowId); |
| 1126 | } else { |
| 1127 | accessFocus = current; |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | // Check for one input focus. |
| 1132 | if (current.isFocused()) { |
| 1133 | if (inputFocus != null) { |
| 1134 | throw new IllegalStateException("Duplicate input focus: " |
| 1135 | + current + " in window:" |
| 1136 | + mViewRootImpl.mAttachInfo.mAccessibilityWindowId); |
| 1137 | } else { |
| 1138 | inputFocus = current; |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | final int childCount = current.getChildCount(); |
| 1143 | for (int j = 0; j < childCount; j++) { |
| 1144 | final long childId = current.getChildId(j); |
| 1145 | final AccessibilityNodeInfo child = nodeMap.get(childId); |
| 1146 | if (child != null) { |
| 1147 | fringe.add(child); |
| 1148 | } |
| 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | // Check for disconnected nodes. |
| 1153 | for (int j = nodeMap.size() - 1; j >= 0; j--) { |
| 1154 | AccessibilityNodeInfo info = nodeMap.valueAt(j); |
| 1155 | if (!seen.contains(info)) { |
| 1156 | throw new IllegalStateException("Disconnected node: " + info); |
| 1157 | } |
| 1158 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | private void prefetchPredecessorsOfRealNode(View view, |
| 1162 | List<AccessibilityNodeInfo> outInfos) { |
| 1163 | ViewParent parent = view.getParentForAccessibility(); |
| 1164 | while (parent instanceof View |
| 1165 | && outInfos.size() < MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 1166 | View parentView = (View) parent; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1167 | AccessibilityNodeInfo info = parentView.createAccessibilityNodeInfo(); |
| 1168 | if (info != null) { |
| 1169 | outInfos.add(info); |
| 1170 | } |
| 1171 | parent = parent.getParentForAccessibility(); |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | private void prefetchSiblingsOfRealNode(View current, |
| 1176 | List<AccessibilityNodeInfo> outInfos) { |
| 1177 | ViewParent parent = current.getParentForAccessibility(); |
| 1178 | if (parent instanceof ViewGroup) { |
| 1179 | ViewGroup parentGroup = (ViewGroup) parent; |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 1180 | ArrayList<View> children = mTempViewList; |
| 1181 | children.clear(); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1182 | try { |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 1183 | parentGroup.addChildrenForAccessibility(children); |
| 1184 | final int childCount = children.size(); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1185 | for (int i = 0; i < childCount; i++) { |
| 1186 | if (outInfos.size() >= MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 1187 | return; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1188 | } |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 1189 | View child = children.get(i); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1190 | if (child.getAccessibilityViewId() != current.getAccessibilityViewId() |
Qasid Ahmad Sadiq | 834787a | 2019-01-18 00:01:54 -0800 | [diff] [blame] | 1191 | && isShown(child)) { |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1192 | AccessibilityNodeInfo info = null; |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 1193 | AccessibilityNodeProvider provider = |
| 1194 | child.getAccessibilityNodeProvider(); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1195 | if (provider == null) { |
| 1196 | info = child.createAccessibilityNodeInfo(); |
| 1197 | } else { |
| 1198 | info = provider.createAccessibilityNodeInfo( |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1199 | AccessibilityNodeProvider.HOST_VIEW_ID); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1200 | } |
| 1201 | if (info != null) { |
| 1202 | outInfos.add(info); |
| 1203 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1204 | } |
| 1205 | } |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1206 | } finally { |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 1207 | children.clear(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1208 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | private void prefetchDescendantsOfRealNode(View root, |
| 1213 | List<AccessibilityNodeInfo> outInfos) { |
| 1214 | if (!(root instanceof ViewGroup)) { |
| 1215 | return; |
| 1216 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1217 | HashMap<View, AccessibilityNodeInfo> addedChildren = |
| 1218 | new HashMap<View, AccessibilityNodeInfo>(); |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 1219 | ArrayList<View> children = mTempViewList; |
| 1220 | children.clear(); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1221 | try { |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 1222 | root.addChildrenForAccessibility(children); |
| 1223 | final int childCount = children.size(); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1224 | for (int i = 0; i < childCount; i++) { |
| 1225 | if (outInfos.size() >= MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 1226 | return; |
| 1227 | } |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 1228 | View child = children.get(i); |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 1229 | if (isShown(child)) { |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1230 | AccessibilityNodeProvider provider = child.getAccessibilityNodeProvider(); |
| 1231 | if (provider == null) { |
| 1232 | AccessibilityNodeInfo info = child.createAccessibilityNodeInfo(); |
| 1233 | if (info != null) { |
| 1234 | outInfos.add(info); |
| 1235 | addedChildren.put(child, null); |
| 1236 | } |
| 1237 | } else { |
| 1238 | AccessibilityNodeInfo info = provider.createAccessibilityNodeInfo( |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1239 | AccessibilityNodeProvider.HOST_VIEW_ID); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1240 | if (info != null) { |
| 1241 | outInfos.add(info); |
| 1242 | addedChildren.put(child, info); |
| 1243 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1244 | } |
| 1245 | } |
| 1246 | } |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1247 | } finally { |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 1248 | children.clear(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1249 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1250 | if (outInfos.size() < MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 1251 | for (Map.Entry<View, AccessibilityNodeInfo> entry : addedChildren.entrySet()) { |
| 1252 | View addedChild = entry.getKey(); |
| 1253 | AccessibilityNodeInfo virtualRoot = entry.getValue(); |
| 1254 | if (virtualRoot == null) { |
| 1255 | prefetchDescendantsOfRealNode(addedChild, outInfos); |
| 1256 | } else { |
| 1257 | AccessibilityNodeProvider provider = |
| 1258 | addedChild.getAccessibilityNodeProvider(); |
| 1259 | prefetchDescendantsOfVirtualNode(virtualRoot, provider, outInfos); |
| 1260 | } |
| 1261 | } |
| 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | private void prefetchPredecessorsOfVirtualNode(AccessibilityNodeInfo root, |
| 1266 | View providerHost, AccessibilityNodeProvider provider, |
| 1267 | List<AccessibilityNodeInfo> outInfos) { |
Svet Ganov | 75e5816 | 2016-02-19 16:29:24 -0800 | [diff] [blame] | 1268 | final int initialResultSize = outInfos.size(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1269 | long parentNodeId = root.getParentNodeId(); |
| 1270 | int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId(parentNodeId); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1271 | while (accessibilityViewId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1272 | if (outInfos.size() >= MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 1273 | return; |
| 1274 | } |
| 1275 | final int virtualDescendantId = |
| 1276 | AccessibilityNodeInfo.getVirtualDescendantId(parentNodeId); |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 1277 | if (virtualDescendantId != AccessibilityNodeProvider.HOST_VIEW_ID |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1278 | || accessibilityViewId == providerHost.getAccessibilityViewId()) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1279 | final AccessibilityNodeInfo parent; |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 1280 | parent = provider.createAccessibilityNodeInfo(virtualDescendantId); |
Alan Viverette | 84feea11 | 2014-11-04 15:59:55 -0800 | [diff] [blame] | 1281 | if (parent == null) { |
Svet Ganov | 75e5816 | 2016-02-19 16:29:24 -0800 | [diff] [blame] | 1282 | // Going up the parent relation we found a null predecessor, |
| 1283 | // so remove these disconnected nodes form the result. |
| 1284 | final int currentResultSize = outInfos.size(); |
| 1285 | for (int i = currentResultSize - 1; i >= initialResultSize; i--) { |
| 1286 | outInfos.remove(i); |
| 1287 | } |
Alan Viverette | 84feea11 | 2014-11-04 15:59:55 -0800 | [diff] [blame] | 1288 | // Couldn't obtain the parent, which means we have a |
| 1289 | // disconnected sub-tree. Abort prefetch immediately. |
| 1290 | return; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1291 | } |
Alan Viverette | 84feea11 | 2014-11-04 15:59:55 -0800 | [diff] [blame] | 1292 | outInfos.add(parent); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1293 | parentNodeId = parent.getParentNodeId(); |
| 1294 | accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 1295 | parentNodeId); |
| 1296 | } else { |
| 1297 | prefetchPredecessorsOfRealNode(providerHost, outInfos); |
| 1298 | return; |
| 1299 | } |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | private void prefetchSiblingsOfVirtualNode(AccessibilityNodeInfo current, View providerHost, |
| 1304 | AccessibilityNodeProvider provider, List<AccessibilityNodeInfo> outInfos) { |
| 1305 | final long parentNodeId = current.getParentNodeId(); |
| 1306 | final int parentAccessibilityViewId = |
| 1307 | AccessibilityNodeInfo.getAccessibilityViewId(parentNodeId); |
| 1308 | final int parentVirtualDescendantId = |
| 1309 | AccessibilityNodeInfo.getVirtualDescendantId(parentNodeId); |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 1310 | if (parentVirtualDescendantId != AccessibilityNodeProvider.HOST_VIEW_ID |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1311 | || parentAccessibilityViewId == providerHost.getAccessibilityViewId()) { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 1312 | final AccessibilityNodeInfo parent = |
| 1313 | provider.createAccessibilityNodeInfo(parentVirtualDescendantId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1314 | if (parent != null) { |
Alan Viverette | f0aed09 | 2013-11-06 15:33:03 -0800 | [diff] [blame] | 1315 | final int childCount = parent.getChildCount(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1316 | for (int i = 0; i < childCount; i++) { |
| 1317 | if (outInfos.size() >= MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 1318 | return; |
| 1319 | } |
Alan Viverette | f0aed09 | 2013-11-06 15:33:03 -0800 | [diff] [blame] | 1320 | final long childNodeId = parent.getChildId(i); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1321 | if (childNodeId != current.getSourceNodeId()) { |
| 1322 | final int childVirtualDescendantId = |
| 1323 | AccessibilityNodeInfo.getVirtualDescendantId(childNodeId); |
| 1324 | AccessibilityNodeInfo child = provider.createAccessibilityNodeInfo( |
| 1325 | childVirtualDescendantId); |
| 1326 | if (child != null) { |
| 1327 | outInfos.add(child); |
| 1328 | } |
| 1329 | } |
| 1330 | } |
| 1331 | } |
| 1332 | } else { |
| 1333 | prefetchSiblingsOfRealNode(providerHost, outInfos); |
| 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | private void prefetchDescendantsOfVirtualNode(AccessibilityNodeInfo root, |
| 1338 | AccessibilityNodeProvider provider, List<AccessibilityNodeInfo> outInfos) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1339 | final int initialOutInfosSize = outInfos.size(); |
Alan Viverette | f0aed09 | 2013-11-06 15:33:03 -0800 | [diff] [blame] | 1340 | final int childCount = root.getChildCount(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1341 | for (int i = 0; i < childCount; i++) { |
| 1342 | if (outInfos.size() >= MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 1343 | return; |
| 1344 | } |
Alan Viverette | f0aed09 | 2013-11-06 15:33:03 -0800 | [diff] [blame] | 1345 | final long childNodeId = root.getChildId(i); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1346 | AccessibilityNodeInfo child = provider.createAccessibilityNodeInfo( |
| 1347 | AccessibilityNodeInfo.getVirtualDescendantId(childNodeId)); |
| 1348 | if (child != null) { |
| 1349 | outInfos.add(child); |
| 1350 | } |
| 1351 | } |
| 1352 | if (outInfos.size() < MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 1353 | final int addedChildCount = outInfos.size() - initialOutInfosSize; |
| 1354 | for (int i = 0; i < addedChildCount; i++) { |
| 1355 | AccessibilityNodeInfo child = outInfos.get(initialOutInfosSize + i); |
| 1356 | prefetchDescendantsOfVirtualNode(child, provider, outInfos); |
| 1357 | } |
| 1358 | } |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | private class PrivateHandler extends Handler { |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 1363 | private static final int MSG_PERFORM_ACCESSIBILITY_ACTION = 1; |
| 1364 | private static final int MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_ACCESSIBILITY_ID = 2; |
| 1365 | private static final int MSG_FIND_ACCESSIBILITY_NODE_INFOS_BY_VIEW_ID = 3; |
| 1366 | private static final int MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_TEXT = 4; |
| 1367 | private static final int MSG_FIND_FOCUS = 5; |
| 1368 | private static final int MSG_FOCUS_SEARCH = 6; |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 1369 | private static final int MSG_PREPARE_FOR_EXTRA_DATA_REQUEST = 7; |
| 1370 | private static final int MSG_APP_PREPARATION_FINISHED = 8; |
| 1371 | private static final int MSG_APP_PREPARATION_TIMEOUT = 9; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1372 | |
Rhed Jao | 23813d9 | 2018-12-18 21:30:52 +0800 | [diff] [blame] | 1373 | // Uses FIRST_NO_ACCESSIBILITY_CALLBACK_MSG for messages that don't need to call back |
| 1374 | // results to interrogating client. |
| 1375 | private static final int FIRST_NO_ACCESSIBILITY_CALLBACK_MSG = 100; |
| 1376 | private static final int MSG_CLEAR_ACCESSIBILITY_FOCUS = |
| 1377 | FIRST_NO_ACCESSIBILITY_CALLBACK_MSG + 1; |
Jackal Guo | 8bcc0a9 | 2019-04-16 15:26:00 +0800 | [diff] [blame] | 1378 | private static final int MSG_NOTIFY_OUTSIDE_TOUCH = |
| 1379 | FIRST_NO_ACCESSIBILITY_CALLBACK_MSG + 2; |
Rhed Jao | 23813d9 | 2018-12-18 21:30:52 +0800 | [diff] [blame] | 1380 | |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 1381 | public PrivateHandler(Looper looper) { |
| 1382 | super(looper); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | @Override |
| 1386 | public String getMessageName(Message message) { |
| 1387 | final int type = message.what; |
| 1388 | switch (type) { |
| 1389 | case MSG_PERFORM_ACCESSIBILITY_ACTION: |
| 1390 | return "MSG_PERFORM_ACCESSIBILITY_ACTION"; |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 1391 | case MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_ACCESSIBILITY_ID: |
| 1392 | return "MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_ACCESSIBILITY_ID"; |
| 1393 | case MSG_FIND_ACCESSIBILITY_NODE_INFOS_BY_VIEW_ID: |
| 1394 | return "MSG_FIND_ACCESSIBILITY_NODE_INFOS_BY_VIEW_ID"; |
| 1395 | case MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_TEXT: |
| 1396 | return "MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_TEXT"; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1397 | case MSG_FIND_FOCUS: |
| 1398 | return "MSG_FIND_FOCUS"; |
| 1399 | case MSG_FOCUS_SEARCH: |
| 1400 | return "MSG_FOCUS_SEARCH"; |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 1401 | case MSG_PREPARE_FOR_EXTRA_DATA_REQUEST: |
| 1402 | return "MSG_PREPARE_FOR_EXTRA_DATA_REQUEST"; |
| 1403 | case MSG_APP_PREPARATION_FINISHED: |
| 1404 | return "MSG_APP_PREPARATION_FINISHED"; |
| 1405 | case MSG_APP_PREPARATION_TIMEOUT: |
| 1406 | return "MSG_APP_PREPARATION_TIMEOUT"; |
Rhed Jao | 23813d9 | 2018-12-18 21:30:52 +0800 | [diff] [blame] | 1407 | case MSG_CLEAR_ACCESSIBILITY_FOCUS: |
| 1408 | return "MSG_CLEAR_ACCESSIBILITY_FOCUS"; |
Jackal Guo | 8bcc0a9 | 2019-04-16 15:26:00 +0800 | [diff] [blame] | 1409 | case MSG_NOTIFY_OUTSIDE_TOUCH: |
| 1410 | return "MSG_NOTIFY_OUTSIDE_TOUCH"; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1411 | default: |
| 1412 | throw new IllegalArgumentException("Unknown message type: " + type); |
| 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | @Override |
| 1417 | public void handleMessage(Message message) { |
| 1418 | final int type = message.what; |
| 1419 | switch (type) { |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 1420 | case MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_ACCESSIBILITY_ID: { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1421 | findAccessibilityNodeInfoByAccessibilityIdUiThread(message); |
| 1422 | } break; |
| 1423 | case MSG_PERFORM_ACCESSIBILITY_ACTION: { |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1424 | performAccessibilityActionUiThread(message); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1425 | } break; |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 1426 | case MSG_FIND_ACCESSIBILITY_NODE_INFOS_BY_VIEW_ID: { |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1427 | findAccessibilityNodeInfosByViewIdUiThread(message); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1428 | } break; |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 1429 | case MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_TEXT: { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1430 | findAccessibilityNodeInfosByTextUiThread(message); |
| 1431 | } break; |
| 1432 | case MSG_FIND_FOCUS: { |
| 1433 | findFocusUiThread(message); |
| 1434 | } break; |
| 1435 | case MSG_FOCUS_SEARCH: { |
| 1436 | focusSearchUiThread(message); |
| 1437 | } break; |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 1438 | case MSG_PREPARE_FOR_EXTRA_DATA_REQUEST: { |
| 1439 | prepareForExtraDataRequestUiThread(message); |
| 1440 | } break; |
| 1441 | case MSG_APP_PREPARATION_FINISHED: { |
| 1442 | requestPreparerDoneUiThread(message); |
| 1443 | } break; |
| 1444 | case MSG_APP_PREPARATION_TIMEOUT: { |
| 1445 | requestPreparerTimeoutUiThread(); |
| 1446 | } break; |
Rhed Jao | 23813d9 | 2018-12-18 21:30:52 +0800 | [diff] [blame] | 1447 | case MSG_CLEAR_ACCESSIBILITY_FOCUS: { |
| 1448 | clearAccessibilityFocusUiThread(); |
| 1449 | } break; |
Jackal Guo | 8bcc0a9 | 2019-04-16 15:26:00 +0800 | [diff] [blame] | 1450 | case MSG_NOTIFY_OUTSIDE_TOUCH: { |
| 1451 | notifyOutsideTouchUiThread(); |
| 1452 | } break; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1453 | default: |
| 1454 | throw new IllegalArgumentException("Unknown message type: " + type); |
| 1455 | } |
| 1456 | } |
Rhed Jao | 23813d9 | 2018-12-18 21:30:52 +0800 | [diff] [blame] | 1457 | |
| 1458 | boolean hasAccessibilityCallback(Message message) { |
| 1459 | return message.what < FIRST_NO_ACCESSIBILITY_CALLBACK_MSG ? true : false; |
| 1460 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1461 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1462 | |
| 1463 | private final class AddNodeInfosForViewId implements Predicate<View> { |
| 1464 | private int mViewId = View.NO_ID; |
| 1465 | private List<AccessibilityNodeInfo> mInfos; |
| 1466 | |
| 1467 | public void init(int viewId, List<AccessibilityNodeInfo> infos) { |
| 1468 | mViewId = viewId; |
| 1469 | mInfos = infos; |
| 1470 | } |
| 1471 | |
| 1472 | public void reset() { |
| 1473 | mViewId = View.NO_ID; |
| 1474 | mInfos = null; |
| 1475 | } |
| 1476 | |
| 1477 | @Override |
Paul Duffin | ca4964c | 2017-02-07 15:04:10 +0000 | [diff] [blame] | 1478 | public boolean test(View view) { |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1479 | if (view.getId() == mViewId && isShown(view)) { |
| 1480 | mInfos.add(view.createAccessibilityNodeInfo()); |
| 1481 | } |
| 1482 | return false; |
| 1483 | } |
| 1484 | } |
Phil Weaver | 08cccc1 | 2017-02-28 09:55:31 -0800 | [diff] [blame] | 1485 | |
| 1486 | private static final class MessageHolder { |
| 1487 | final Message mMessage; |
| 1488 | final int mInterrogatingPid; |
| 1489 | final long mInterrogatingTid; |
| 1490 | |
| 1491 | MessageHolder(Message message, int interrogatingPid, long interrogatingTid) { |
| 1492 | mMessage = message; |
| 1493 | mInterrogatingPid = interrogatingPid; |
| 1494 | mInterrogatingTid = interrogatingTid; |
| 1495 | } |
| 1496 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1497 | } |