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 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 19 | import android.graphics.Point; |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 20 | import android.graphics.Rect; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 21 | import android.graphics.Region; |
Nirmal Patel | 386a824 | 2015-06-02 18:11:32 -0700 | [diff] [blame] | 22 | import android.os.Binder; |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 23 | import android.os.Bundle; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 24 | import android.os.Handler; |
| 25 | import android.os.Looper; |
| 26 | import android.os.Message; |
| 27 | import android.os.Process; |
| 28 | import android.os.RemoteException; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 29 | import android.util.LongSparseArray; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 30 | import android.view.View.AttachInfo; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 31 | import android.view.accessibility.AccessibilityInteractionClient; |
| 32 | import android.view.accessibility.AccessibilityNodeInfo; |
| 33 | import android.view.accessibility.AccessibilityNodeProvider; |
| 34 | import android.view.accessibility.IAccessibilityInteractionConnectionCallback; |
| 35 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 36 | import com.android.internal.os.SomeArgs; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 37 | import com.android.internal.util.Predicate; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 38 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 39 | import java.util.ArrayList; |
| 40 | import java.util.HashMap; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 41 | import java.util.HashSet; |
| 42 | import java.util.LinkedList; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 43 | import java.util.List; |
| 44 | import java.util.Map; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 45 | import java.util.Queue; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * Class for managing accessibility interactions initiated from the system |
| 49 | * and targeting the view hierarchy. A *ClientThread method is to be |
| 50 | * called from the interaction connection ViewAncestor gives the system to |
| 51 | * talk to it and a corresponding *UiThread method that is executed on the |
| 52 | * UI thread. |
| 53 | */ |
| 54 | final class AccessibilityInteractionController { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 55 | |
Svetoslav | aaa1142 | 2014-03-28 13:31:13 -0700 | [diff] [blame] | 56 | private static final boolean ENFORCE_NODE_TREE_CONSISTENT = false; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 57 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 58 | private final ArrayList<AccessibilityNodeInfo> mTempAccessibilityNodeInfoList = |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 59 | new ArrayList<AccessibilityNodeInfo>(); |
| 60 | |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 61 | private final Handler mHandler; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 62 | |
| 63 | private final ViewRootImpl mViewRootImpl; |
| 64 | |
| 65 | private final AccessibilityNodePrefetcher mPrefetcher; |
| 66 | |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 67 | private final long mMyLooperThreadId; |
| 68 | |
| 69 | private final int mMyProcessId; |
| 70 | |
Svetoslav Ganov | 30ac645 | 2012-06-01 09:10:25 -0700 | [diff] [blame] | 71 | private final ArrayList<View> mTempArrayList = new ArrayList<View>(); |
| 72 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 73 | private final Point mTempPoint = new Point(); |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 74 | private final Rect mTempRect = new Rect(); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 75 | private final Rect mTempRect1 = new Rect(); |
| 76 | private final Rect mTempRect2 = new Rect(); |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 77 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 78 | private AddNodeInfosForViewId mAddNodeInfosForViewId; |
| 79 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 80 | public AccessibilityInteractionController(ViewRootImpl viewRootImpl) { |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 81 | Looper looper = viewRootImpl.mHandler.getLooper(); |
| 82 | mMyLooperThreadId = looper.getThread().getId(); |
| 83 | mMyProcessId = Process.myPid(); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 84 | mHandler = new PrivateHandler(looper); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 85 | mViewRootImpl = viewRootImpl; |
| 86 | mPrefetcher = new AccessibilityNodePrefetcher(); |
| 87 | } |
| 88 | |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 89 | private boolean isShown(View view) { |
| 90 | // The first two checks are made also made by isShown() which |
| 91 | // however traverses the tree up to the parent to catch that. |
| 92 | // Therefore, we do some fail fast check to minimize the up |
| 93 | // tree traversal. |
| 94 | return (view.mAttachInfo != null |
| 95 | && view.mAttachInfo.mWindowVisibility == View.VISIBLE |
| 96 | && view.isShown()); |
| 97 | } |
| 98 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 99 | public void findAccessibilityNodeInfoByAccessibilityIdClientThread( |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 100 | long accessibilityNodeId, Region interactiveRegion, int interactionId, |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 101 | IAccessibilityInteractionConnectionCallback callback, int flags, int interrogatingPid, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 102 | long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 103 | Message message = mHandler.obtainMessage(); |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 104 | message.what = PrivateHandler.MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_ACCESSIBILITY_ID; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 105 | message.arg1 = flags; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 106 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 107 | SomeArgs args = SomeArgs.obtain(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 108 | args.argi1 = AccessibilityNodeInfo.getAccessibilityViewId(accessibilityNodeId); |
| 109 | args.argi2 = AccessibilityNodeInfo.getVirtualDescendantId(accessibilityNodeId); |
| 110 | args.argi3 = interactionId; |
| 111 | args.arg1 = callback; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 112 | args.arg2 = spec; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 113 | args.arg3 = interactiveRegion; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 114 | message.obj = args; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 115 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 116 | // If the interrogation is performed by the same thread as the main UI |
| 117 | // thread in this process, set the message as a static reference so |
| 118 | // after this call completes the same thread but in the interrogating |
| 119 | // client can handle the message to generate the result. |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 120 | if (interrogatingPid == mMyProcessId && interrogatingTid == mMyLooperThreadId) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 121 | AccessibilityInteractionClient.getInstanceForThread( |
| 122 | interrogatingTid).setSameThreadMessage(message); |
| 123 | } else { |
| 124 | mHandler.sendMessage(message); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | private void findAccessibilityNodeInfoByAccessibilityIdUiThread(Message message) { |
| 129 | final int flags = message.arg1; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 130 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 131 | SomeArgs args = (SomeArgs) message.obj; |
| 132 | final int accessibilityViewId = args.argi1; |
| 133 | final int virtualDescendantId = args.argi2; |
| 134 | final int interactionId = args.argi3; |
| 135 | final IAccessibilityInteractionConnectionCallback callback = |
| 136 | (IAccessibilityInteractionConnectionCallback) args.arg1; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 137 | final MagnificationSpec spec = (MagnificationSpec) args.arg2; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 138 | final Region interactiveRegion = (Region) args.arg3; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 139 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 140 | args.recycle(); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 141 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 142 | List<AccessibilityNodeInfo> infos = mTempAccessibilityNodeInfoList; |
| 143 | infos.clear(); |
| 144 | try { |
| 145 | if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) { |
| 146 | return; |
| 147 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 148 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 149 | View root = null; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 150 | if (accessibilityViewId == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 151 | root = mViewRootImpl.mView; |
| 152 | } else { |
| 153 | root = findViewByAccessibilityId(accessibilityViewId); |
| 154 | } |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 155 | if (root != null && isShown(root)) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 156 | mPrefetcher.prefetchAccessibilityNodeInfos(root, virtualDescendantId, flags, infos); |
| 157 | } |
| 158 | } finally { |
| 159 | try { |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 160 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = 0; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 161 | applyAppScaleAndMagnificationSpecIfNeeded(infos, spec); |
Nirmal Patel | 386a824 | 2015-06-02 18:11:32 -0700 | [diff] [blame] | 162 | // Recycle if called from another process. Specs are cached in the |
| 163 | // system process and obtained from a pool when read from parcel. |
| 164 | if (spec != null && android.os.Process.myPid() != Binder.getCallingPid()) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 165 | spec.recycle(); |
| 166 | } |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 167 | adjustIsVisibleToUserIfNeeded(infos, interactiveRegion); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 168 | callback.setFindAccessibilityNodeInfosResult(infos, interactionId); |
| 169 | infos.clear(); |
| 170 | } catch (RemoteException re) { |
| 171 | /* ignore - the other side will time out */ |
| 172 | } |
Nirmal Patel | 386a824 | 2015-06-02 18:11:32 -0700 | [diff] [blame] | 173 | |
| 174 | // Recycle if called from the same process. Regions are obtained in |
| 175 | // the system process and instantiated when read from parcel. |
| 176 | if (interactiveRegion != null && android.os.Process.myPid() == Binder.getCallingPid()) { |
| 177 | interactiveRegion.recycle(); |
| 178 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 182 | public void findAccessibilityNodeInfosByViewIdClientThread(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 183 | String viewId, Region interactiveRegion, int interactionId, |
| 184 | IAccessibilityInteractionConnectionCallback callback, int flags, int interrogatingPid, |
| 185 | long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 186 | Message message = mHandler.obtainMessage(); |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 187 | message.what = PrivateHandler.MSG_FIND_ACCESSIBILITY_NODE_INFOS_BY_VIEW_ID; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 188 | message.arg1 = flags; |
| 189 | message.arg2 = AccessibilityNodeInfo.getAccessibilityViewId(accessibilityNodeId); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 190 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 191 | SomeArgs args = SomeArgs.obtain(); |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 192 | args.argi1 = interactionId; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 193 | args.arg1 = callback; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 194 | args.arg2 = spec; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 195 | args.arg3 = viewId; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 196 | args.arg4 = interactiveRegion; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 197 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 198 | message.obj = args; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 199 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 200 | // If the interrogation is performed by the same thread as the main UI |
| 201 | // thread in this process, set the message as a static reference so |
| 202 | // after this call completes the same thread but in the interrogating |
| 203 | // client can handle the message to generate the result. |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 204 | if (interrogatingPid == mMyProcessId && interrogatingTid == mMyLooperThreadId) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 205 | AccessibilityInteractionClient.getInstanceForThread( |
| 206 | interrogatingTid).setSameThreadMessage(message); |
| 207 | } else { |
| 208 | mHandler.sendMessage(message); |
| 209 | } |
| 210 | } |
| 211 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 212 | private void findAccessibilityNodeInfosByViewIdUiThread(Message message) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 213 | final int flags = message.arg1; |
| 214 | final int accessibilityViewId = message.arg2; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 215 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 216 | SomeArgs args = (SomeArgs) message.obj; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 217 | final int interactionId = args.argi1; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 218 | final IAccessibilityInteractionConnectionCallback callback = |
| 219 | (IAccessibilityInteractionConnectionCallback) args.arg1; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 220 | final MagnificationSpec spec = (MagnificationSpec) args.arg2; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 221 | final String viewId = (String) args.arg3; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 222 | final Region interactiveRegion = (Region) args.arg4; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 223 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 224 | args.recycle(); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 225 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 226 | final List<AccessibilityNodeInfo> infos = mTempAccessibilityNodeInfoList; |
| 227 | infos.clear(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 228 | try { |
| 229 | if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) { |
| 230 | return; |
| 231 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 232 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 233 | View root = null; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 234 | if (accessibilityViewId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 235 | root = findViewByAccessibilityId(accessibilityViewId); |
| 236 | } else { |
| 237 | root = mViewRootImpl.mView; |
| 238 | } |
| 239 | if (root != null) { |
Svetoslav | a33243e | 2013-02-11 15:43:46 -0800 | [diff] [blame] | 240 | final int resolvedViewId = root.getContext().getResources() |
| 241 | .getIdentifier(viewId, null, null); |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 242 | if (resolvedViewId <= 0) { |
| 243 | return; |
| 244 | } |
| 245 | if (mAddNodeInfosForViewId == null) { |
| 246 | mAddNodeInfosForViewId = new AddNodeInfosForViewId(); |
| 247 | } |
| 248 | mAddNodeInfosForViewId.init(resolvedViewId, infos); |
| 249 | root.findViewByPredicate(mAddNodeInfosForViewId); |
| 250 | mAddNodeInfosForViewId.reset(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 251 | } |
| 252 | } finally { |
| 253 | try { |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 254 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = 0; |
| 255 | applyAppScaleAndMagnificationSpecIfNeeded(infos, spec); |
Nirmal Patel | 386a824 | 2015-06-02 18:11:32 -0700 | [diff] [blame] | 256 | // Recycle if called from another process. Specs are cached in the |
| 257 | // system process and obtained from a pool when read from parcel. |
| 258 | if (spec != null && android.os.Process.myPid() != Binder.getCallingPid()) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 259 | spec.recycle(); |
| 260 | } |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 261 | adjustIsVisibleToUserIfNeeded(infos, interactiveRegion); |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 262 | callback.setFindAccessibilityNodeInfosResult(infos, interactionId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 263 | } catch (RemoteException re) { |
| 264 | /* ignore - the other side will time out */ |
| 265 | } |
Nirmal Patel | 386a824 | 2015-06-02 18:11:32 -0700 | [diff] [blame] | 266 | |
| 267 | // Recycle if called from the same process. Regions are obtained in |
| 268 | // the system process and instantiated when read from parcel. |
| 269 | if (interactiveRegion != null && android.os.Process.myPid() == Binder.getCallingPid()) { |
| 270 | interactiveRegion.recycle(); |
| 271 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | |
| 275 | public void findAccessibilityNodeInfosByTextClientThread(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 276 | String text, Region interactiveRegion, int interactionId, |
| 277 | IAccessibilityInteractionConnectionCallback callback, int flags, int interrogatingPid, |
| 278 | long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 279 | Message message = mHandler.obtainMessage(); |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 280 | message.what = PrivateHandler.MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_TEXT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 281 | message.arg1 = flags; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 282 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 283 | SomeArgs args = SomeArgs.obtain(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 284 | args.arg1 = text; |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 285 | args.arg2 = callback; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 286 | args.arg3 = spec; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 287 | args.argi1 = AccessibilityNodeInfo.getAccessibilityViewId(accessibilityNodeId); |
| 288 | args.argi2 = AccessibilityNodeInfo.getVirtualDescendantId(accessibilityNodeId); |
| 289 | args.argi3 = interactionId; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 290 | args.arg4 = interactiveRegion; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 291 | message.obj = args; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 292 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 293 | // If the interrogation is performed by the same thread as the main UI |
| 294 | // thread in this process, set the message as a static reference so |
| 295 | // after this call completes the same thread but in the interrogating |
| 296 | // client can handle the message to generate the result. |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 297 | if (interrogatingPid == mMyProcessId && interrogatingTid == mMyLooperThreadId) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 298 | AccessibilityInteractionClient.getInstanceForThread( |
| 299 | interrogatingTid).setSameThreadMessage(message); |
| 300 | } else { |
| 301 | mHandler.sendMessage(message); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | private void findAccessibilityNodeInfosByTextUiThread(Message message) { |
| 306 | final int flags = message.arg1; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 307 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 308 | SomeArgs args = (SomeArgs) message.obj; |
| 309 | final String text = (String) args.arg1; |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 310 | final IAccessibilityInteractionConnectionCallback callback = |
| 311 | (IAccessibilityInteractionConnectionCallback) args.arg2; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 312 | final MagnificationSpec spec = (MagnificationSpec) args.arg3; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 313 | final int accessibilityViewId = args.argi1; |
| 314 | final int virtualDescendantId = args.argi2; |
| 315 | final int interactionId = args.argi3; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 316 | final Region interactiveRegion = (Region) args.arg4; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 317 | args.recycle(); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 318 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 319 | List<AccessibilityNodeInfo> infos = null; |
| 320 | try { |
| 321 | if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) { |
| 322 | return; |
| 323 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 324 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 325 | View root = null; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 326 | if (accessibilityViewId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 327 | root = findViewByAccessibilityId(accessibilityViewId); |
| 328 | } else { |
| 329 | root = mViewRootImpl.mView; |
| 330 | } |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 331 | if (root != null && isShown(root)) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 332 | AccessibilityNodeProvider provider = root.getAccessibilityNodeProvider(); |
| 333 | if (provider != null) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 334 | if (virtualDescendantId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
| 335 | infos = provider.findAccessibilityNodeInfosByText(text, |
| 336 | virtualDescendantId); |
| 337 | } else { |
| 338 | infos = provider.findAccessibilityNodeInfosByText(text, |
| 339 | AccessibilityNodeProvider.HOST_VIEW_ID); |
| 340 | } |
| 341 | } else if (virtualDescendantId == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
Svetoslav Ganov | 30ac645 | 2012-06-01 09:10:25 -0700 | [diff] [blame] | 342 | ArrayList<View> foundViews = mTempArrayList; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 343 | foundViews.clear(); |
| 344 | root.findViewsWithText(foundViews, text, View.FIND_VIEWS_WITH_TEXT |
| 345 | | View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION |
| 346 | | View.FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS); |
| 347 | if (!foundViews.isEmpty()) { |
| 348 | infos = mTempAccessibilityNodeInfoList; |
| 349 | infos.clear(); |
| 350 | final int viewCount = foundViews.size(); |
| 351 | for (int i = 0; i < viewCount; i++) { |
| 352 | View foundView = foundViews.get(i); |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 353 | if (isShown(foundView)) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 354 | provider = foundView.getAccessibilityNodeProvider(); |
| 355 | if (provider != null) { |
| 356 | List<AccessibilityNodeInfo> infosFromProvider = |
| 357 | provider.findAccessibilityNodeInfosByText(text, |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 358 | AccessibilityNodeProvider.HOST_VIEW_ID); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 359 | if (infosFromProvider != null) { |
| 360 | infos.addAll(infosFromProvider); |
| 361 | } |
| 362 | } else { |
| 363 | infos.add(foundView.createAccessibilityNodeInfo()); |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | } finally { |
| 371 | try { |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 372 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = 0; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 373 | applyAppScaleAndMagnificationSpecIfNeeded(infos, spec); |
Nirmal Patel | 386a824 | 2015-06-02 18:11:32 -0700 | [diff] [blame] | 374 | // Recycle if called from another process. Specs are cached in the |
| 375 | // system process and obtained from a pool when read from parcel. |
| 376 | if (spec != null && android.os.Process.myPid() != Binder.getCallingPid()) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 377 | spec.recycle(); |
| 378 | } |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 379 | adjustIsVisibleToUserIfNeeded(infos, interactiveRegion); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 380 | callback.setFindAccessibilityNodeInfosResult(infos, interactionId); |
| 381 | } catch (RemoteException re) { |
| 382 | /* ignore - the other side will time out */ |
| 383 | } |
Nirmal Patel | 386a824 | 2015-06-02 18:11:32 -0700 | [diff] [blame] | 384 | |
| 385 | // Recycle if called from the same process. Regions are obtained in |
| 386 | // the system process and instantiated when read from parcel. |
| 387 | if (interactiveRegion != null && android.os.Process.myPid() == Binder.getCallingPid()) { |
| 388 | interactiveRegion.recycle(); |
| 389 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 393 | public void findFocusClientThread(long accessibilityNodeId, int focusType, |
| 394 | Region interactiveRegion, int interactionId, |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 395 | IAccessibilityInteractionConnectionCallback callback, int flags, int interogatingPid, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 396 | long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 397 | Message message = mHandler.obtainMessage(); |
| 398 | message.what = PrivateHandler.MSG_FIND_FOCUS; |
| 399 | message.arg1 = flags; |
| 400 | message.arg2 = focusType; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 401 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 402 | SomeArgs args = SomeArgs.obtain(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 403 | args.argi1 = interactionId; |
| 404 | args.argi2 = AccessibilityNodeInfo.getAccessibilityViewId(accessibilityNodeId); |
| 405 | args.argi3 = AccessibilityNodeInfo.getVirtualDescendantId(accessibilityNodeId); |
| 406 | args.arg1 = callback; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 407 | args.arg2 = spec; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 408 | args.arg3 = interactiveRegion; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 409 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 410 | message.obj = args; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 411 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 412 | // If the interrogation is performed by the same thread as the main UI |
| 413 | // thread in this process, set the message as a static reference so |
| 414 | // after this call completes the same thread but in the interrogating |
| 415 | // client can handle the message to generate the result. |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 416 | if (interogatingPid == mMyProcessId && interrogatingTid == mMyLooperThreadId) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 417 | AccessibilityInteractionClient.getInstanceForThread( |
| 418 | interrogatingTid).setSameThreadMessage(message); |
| 419 | } else { |
| 420 | mHandler.sendMessage(message); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | private void findFocusUiThread(Message message) { |
| 425 | final int flags = message.arg1; |
| 426 | final int focusType = message.arg2; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 427 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 428 | SomeArgs args = (SomeArgs) message.obj; |
| 429 | final int interactionId = args.argi1; |
| 430 | final int accessibilityViewId = args.argi2; |
| 431 | final int virtualDescendantId = args.argi3; |
| 432 | final IAccessibilityInteractionConnectionCallback callback = |
| 433 | (IAccessibilityInteractionConnectionCallback) args.arg1; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 434 | final MagnificationSpec spec = (MagnificationSpec) args.arg2; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 435 | final Region interactiveRegion = (Region) args.arg3; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 436 | args.recycle(); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 437 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 438 | AccessibilityNodeInfo focused = null; |
| 439 | try { |
| 440 | if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) { |
| 441 | return; |
| 442 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 443 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 444 | View root = null; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 445 | if (accessibilityViewId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 446 | root = findViewByAccessibilityId(accessibilityViewId); |
| 447 | } else { |
| 448 | root = mViewRootImpl.mView; |
| 449 | } |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 450 | if (root != null && isShown(root)) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 451 | switch (focusType) { |
| 452 | case AccessibilityNodeInfo.FOCUS_ACCESSIBILITY: { |
| 453 | View host = mViewRootImpl.mAccessibilityFocusedHost; |
| 454 | // If there is no accessibility focus host or it is not a descendant |
| 455 | // of the root from which to start the search, then the search failed. |
| 456 | if (host == null || !ViewRootImpl.isViewDescendantOf(host, root)) { |
| 457 | break; |
| 458 | } |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 459 | // The focused view not shown, we failed. |
| 460 | if (!isShown(host)) { |
| 461 | break; |
| 462 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 463 | // If the host has a provider ask this provider to search for the |
| 464 | // focus instead fetching all provider nodes to do the search here. |
| 465 | AccessibilityNodeProvider provider = host.getAccessibilityNodeProvider(); |
| 466 | if (provider != null) { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 467 | if (mViewRootImpl.mAccessibilityFocusedVirtualView != null) { |
| 468 | focused = AccessibilityNodeInfo.obtain( |
| 469 | mViewRootImpl.mAccessibilityFocusedVirtualView); |
| 470 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 471 | } else if (virtualDescendantId == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 472 | focused = host.createAccessibilityNodeInfo(); |
| 473 | } |
| 474 | } break; |
| 475 | case AccessibilityNodeInfo.FOCUS_INPUT: { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 476 | View target = root.findFocus(); |
Alan Viverette | 2e1e081 | 2013-09-30 13:45:55 -0700 | [diff] [blame] | 477 | if (target == null || !isShown(target)) { |
| 478 | break; |
| 479 | } |
| 480 | AccessibilityNodeProvider provider = target.getAccessibilityNodeProvider(); |
| 481 | if (provider != null) { |
| 482 | focused = provider.findFocus(focusType); |
| 483 | } |
| 484 | if (focused == null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 485 | focused = target.createAccessibilityNodeInfo(); |
| 486 | } |
| 487 | } break; |
| 488 | default: |
| 489 | throw new IllegalArgumentException("Unknown focus type: " + focusType); |
| 490 | } |
| 491 | } |
| 492 | } finally { |
| 493 | try { |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 494 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = 0; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 495 | applyAppScaleAndMagnificationSpecIfNeeded(focused, spec); |
Nirmal Patel | 386a824 | 2015-06-02 18:11:32 -0700 | [diff] [blame] | 496 | // Recycle if called from another process. Specs are cached in the |
| 497 | // system process and obtained from a pool when read from parcel. |
| 498 | if (spec != null && android.os.Process.myPid() != Binder.getCallingPid()) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 499 | spec.recycle(); |
| 500 | } |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 501 | adjustIsVisibleToUserIfNeeded(focused, interactiveRegion); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 502 | callback.setFindAccessibilityNodeInfoResult(focused, interactionId); |
| 503 | } catch (RemoteException re) { |
| 504 | /* ignore - the other side will time out */ |
| 505 | } |
Nirmal Patel | 386a824 | 2015-06-02 18:11:32 -0700 | [diff] [blame] | 506 | |
| 507 | // Recycle if called from the same process. Regions are obtained in |
| 508 | // the system process and instantiated when read from parcel. |
| 509 | if (interactiveRegion != null && android.os.Process.myPid() == Binder.getCallingPid()) { |
| 510 | interactiveRegion.recycle(); |
| 511 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 515 | public void focusSearchClientThread(long accessibilityNodeId, int direction, |
| 516 | Region interactiveRegion, int interactionId, |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 517 | IAccessibilityInteractionConnectionCallback callback, int flags, int interogatingPid, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 518 | long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 519 | Message message = mHandler.obtainMessage(); |
| 520 | message.what = PrivateHandler.MSG_FOCUS_SEARCH; |
| 521 | message.arg1 = flags; |
| 522 | message.arg2 = AccessibilityNodeInfo.getAccessibilityViewId(accessibilityNodeId); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 523 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 524 | SomeArgs args = SomeArgs.obtain(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 525 | args.argi2 = direction; |
| 526 | args.argi3 = interactionId; |
| 527 | args.arg1 = callback; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 528 | args.arg2 = spec; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 529 | args.arg3 = interactiveRegion; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 530 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 531 | message.obj = args; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 532 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 533 | // If the interrogation is performed by the same thread as the main UI |
| 534 | // thread in this process, set the message as a static reference so |
| 535 | // after this call completes the same thread but in the interrogating |
| 536 | // client can handle the message to generate the result. |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 537 | if (interogatingPid == mMyProcessId && interrogatingTid == mMyLooperThreadId) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 538 | AccessibilityInteractionClient.getInstanceForThread( |
| 539 | interrogatingTid).setSameThreadMessage(message); |
| 540 | } else { |
| 541 | mHandler.sendMessage(message); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | private void focusSearchUiThread(Message message) { |
| 546 | final int flags = message.arg1; |
| 547 | final int accessibilityViewId = message.arg2; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 548 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 549 | SomeArgs args = (SomeArgs) message.obj; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 550 | final int direction = args.argi2; |
| 551 | final int interactionId = args.argi3; |
| 552 | final IAccessibilityInteractionConnectionCallback callback = |
| 553 | (IAccessibilityInteractionConnectionCallback) args.arg1; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 554 | final MagnificationSpec spec = (MagnificationSpec) args.arg2; |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 555 | final Region interactiveRegion = (Region) args.arg3; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 556 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 557 | args.recycle(); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 558 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 559 | AccessibilityNodeInfo next = null; |
| 560 | try { |
| 561 | if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) { |
| 562 | return; |
| 563 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 564 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 565 | View root = null; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 566 | if (accessibilityViewId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 567 | root = findViewByAccessibilityId(accessibilityViewId); |
| 568 | } else { |
| 569 | root = mViewRootImpl.mView; |
| 570 | } |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 571 | if (root != null && isShown(root)) { |
Svetoslav Ganov | 27e2da7 | 2012-07-02 18:12:00 -0700 | [diff] [blame] | 572 | View nextView = root.focusSearch(direction); |
| 573 | if (nextView != null) { |
| 574 | next = nextView.createAccessibilityNodeInfo(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 575 | } |
| 576 | } |
| 577 | } finally { |
| 578 | try { |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 579 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = 0; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 580 | applyAppScaleAndMagnificationSpecIfNeeded(next, spec); |
Nirmal Patel | 386a824 | 2015-06-02 18:11:32 -0700 | [diff] [blame] | 581 | // Recycle if called from another process. Specs are cached in the |
| 582 | // system process and obtained from a pool when read from parcel. |
| 583 | if (spec != null && android.os.Process.myPid() != Binder.getCallingPid()) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 584 | spec.recycle(); |
| 585 | } |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 586 | adjustIsVisibleToUserIfNeeded(next, interactiveRegion); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 587 | callback.setFindAccessibilityNodeInfoResult(next, interactionId); |
| 588 | } catch (RemoteException re) { |
| 589 | /* ignore - the other side will time out */ |
| 590 | } |
Nirmal Patel | 386a824 | 2015-06-02 18:11:32 -0700 | [diff] [blame] | 591 | |
| 592 | // Recycle if called from the same process. Regions are obtained in |
| 593 | // the system process and instantiated when read from parcel. |
| 594 | if (interactiveRegion != null && android.os.Process.myPid() == Binder.getCallingPid()) { |
| 595 | interactiveRegion.recycle(); |
| 596 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
| 600 | public void performAccessibilityActionClientThread(long accessibilityNodeId, int action, |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 601 | Bundle arguments, int interactionId, |
| 602 | IAccessibilityInteractionConnectionCallback callback, int flags, int interogatingPid, |
| 603 | long interrogatingTid) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 604 | Message message = mHandler.obtainMessage(); |
| 605 | message.what = PrivateHandler.MSG_PERFORM_ACCESSIBILITY_ACTION; |
| 606 | message.arg1 = flags; |
| 607 | message.arg2 = AccessibilityNodeInfo.getAccessibilityViewId(accessibilityNodeId); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 608 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 609 | SomeArgs args = SomeArgs.obtain(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 610 | args.argi1 = AccessibilityNodeInfo.getVirtualDescendantId(accessibilityNodeId); |
| 611 | args.argi2 = action; |
| 612 | args.argi3 = interactionId; |
| 613 | args.arg1 = callback; |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 614 | args.arg2 = arguments; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 615 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 616 | message.obj = args; |
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 | // If the interrogation is performed by the same thread as the main UI |
| 619 | // thread in this process, set the message as a static reference so |
| 620 | // after this call completes the same thread but in the interrogating |
| 621 | // client can handle the message to generate the result. |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 622 | if (interogatingPid == mMyProcessId && interrogatingTid == mMyLooperThreadId) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 623 | AccessibilityInteractionClient.getInstanceForThread( |
| 624 | interrogatingTid).setSameThreadMessage(message); |
| 625 | } else { |
| 626 | mHandler.sendMessage(message); |
| 627 | } |
| 628 | } |
| 629 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 630 | private void performAccessibilityActionUiThread(Message message) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 631 | final int flags = message.arg1; |
| 632 | final int accessibilityViewId = message.arg2; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 633 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 634 | SomeArgs args = (SomeArgs) message.obj; |
| 635 | final int virtualDescendantId = args.argi1; |
| 636 | final int action = args.argi2; |
| 637 | final int interactionId = args.argi3; |
| 638 | final IAccessibilityInteractionConnectionCallback callback = |
| 639 | (IAccessibilityInteractionConnectionCallback) args.arg1; |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 640 | Bundle arguments = (Bundle) args.arg2; |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 641 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 642 | args.recycle(); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 643 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 644 | boolean succeeded = false; |
| 645 | try { |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 646 | if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null || |
| 647 | mViewRootImpl.mStopped || mViewRootImpl.mPausedForTransition) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 648 | return; |
| 649 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 650 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 651 | View target = null; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 652 | if (accessibilityViewId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 653 | target = findViewByAccessibilityId(accessibilityViewId); |
| 654 | } else { |
| 655 | target = mViewRootImpl.mView; |
| 656 | } |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 657 | if (target != null && isShown(target)) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 658 | AccessibilityNodeProvider provider = target.getAccessibilityNodeProvider(); |
| 659 | if (provider != null) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 660 | if (virtualDescendantId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
| 661 | succeeded = provider.performAction(virtualDescendantId, action, |
| 662 | arguments); |
| 663 | } else { |
| 664 | succeeded = provider.performAction(AccessibilityNodeProvider.HOST_VIEW_ID, |
| 665 | action, arguments); |
| 666 | } |
| 667 | } else if (virtualDescendantId == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 668 | succeeded = target.performAccessibilityAction(action, arguments); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | } finally { |
| 672 | try { |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 673 | mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = 0; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 674 | callback.setPerformAccessibilityActionResult(succeeded, interactionId); |
| 675 | } catch (RemoteException re) { |
| 676 | /* ignore - the other side will time out */ |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | private View findViewByAccessibilityId(int accessibilityId) { |
| 682 | View root = mViewRootImpl.mView; |
| 683 | if (root == null) { |
| 684 | return null; |
| 685 | } |
| 686 | View foundView = root.findViewByAccessibilityId(accessibilityId); |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 687 | if (foundView != null && !isShown(foundView)) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 688 | return null; |
| 689 | } |
| 690 | return foundView; |
| 691 | } |
| 692 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 693 | private void applyAppScaleAndMagnificationSpecIfNeeded(List<AccessibilityNodeInfo> infos, |
| 694 | MagnificationSpec spec) { |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 695 | if (infos == null) { |
| 696 | return; |
| 697 | } |
| 698 | final float applicationScale = mViewRootImpl.mAttachInfo.mApplicationScale; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 699 | if (shouldApplyAppScaleAndMagnificationSpec(applicationScale, spec)) { |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 700 | final int infoCount = infos.size(); |
| 701 | for (int i = 0; i < infoCount; i++) { |
| 702 | AccessibilityNodeInfo info = infos.get(i); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 703 | applyAppScaleAndMagnificationSpecIfNeeded(info, spec); |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | } |
| 707 | |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 708 | private void adjustIsVisibleToUserIfNeeded(List<AccessibilityNodeInfo> infos, |
| 709 | Region interactiveRegion) { |
| 710 | if (interactiveRegion == null || infos == null) { |
| 711 | return; |
| 712 | } |
| 713 | final int infoCount = infos.size(); |
| 714 | for (int i = 0; i < infoCount; i++) { |
| 715 | AccessibilityNodeInfo info = infos.get(i); |
| 716 | adjustIsVisibleToUserIfNeeded(info, interactiveRegion); |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | private void adjustIsVisibleToUserIfNeeded(AccessibilityNodeInfo info, |
| 721 | Region interactiveRegion) { |
| 722 | if (interactiveRegion == null || info == null) { |
| 723 | return; |
| 724 | } |
| 725 | Rect boundsInScreen = mTempRect; |
| 726 | info.getBoundsInScreen(boundsInScreen); |
| 727 | if (interactiveRegion.quickReject(boundsInScreen)) { |
| 728 | info.setVisibleToUser(false); |
| 729 | } |
| 730 | } |
| 731 | |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 732 | private void applyAppScaleAndMagnificationSpecIfNeeded(Point point, |
| 733 | MagnificationSpec spec) { |
| 734 | final float applicationScale = mViewRootImpl.mAttachInfo.mApplicationScale; |
| 735 | if (!shouldApplyAppScaleAndMagnificationSpec(applicationScale, spec)) { |
| 736 | return; |
| 737 | } |
| 738 | |
| 739 | if (applicationScale != 1.0f) { |
| 740 | point.x *= applicationScale; |
| 741 | point.y *= applicationScale; |
| 742 | } |
| 743 | |
| 744 | if (spec != null) { |
| 745 | point.x *= spec.scale; |
| 746 | point.y *= spec.scale; |
| 747 | point.x += (int) spec.offsetX; |
| 748 | point.y += (int) spec.offsetY; |
| 749 | } |
| 750 | } |
| 751 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 752 | private void applyAppScaleAndMagnificationSpecIfNeeded(AccessibilityNodeInfo info, |
| 753 | MagnificationSpec spec) { |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 754 | if (info == null) { |
| 755 | return; |
| 756 | } |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 757 | |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 758 | final float applicationScale = mViewRootImpl.mAttachInfo.mApplicationScale; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 759 | if (!shouldApplyAppScaleAndMagnificationSpec(applicationScale, spec)) { |
| 760 | return; |
| 761 | } |
| 762 | |
| 763 | Rect boundsInParent = mTempRect; |
| 764 | Rect boundsInScreen = mTempRect1; |
| 765 | |
| 766 | info.getBoundsInParent(boundsInParent); |
| 767 | info.getBoundsInScreen(boundsInScreen); |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 768 | if (applicationScale != 1.0f) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 769 | boundsInParent.scale(applicationScale); |
| 770 | boundsInScreen.scale(applicationScale); |
| 771 | } |
| 772 | if (spec != null) { |
| 773 | boundsInParent.scale(spec.scale); |
| 774 | // boundsInParent must not be offset. |
| 775 | boundsInScreen.scale(spec.scale); |
| 776 | boundsInScreen.offset((int) spec.offsetX, (int) spec.offsetY); |
| 777 | } |
| 778 | info.setBoundsInParent(boundsInParent); |
| 779 | info.setBoundsInScreen(boundsInScreen); |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 780 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 781 | if (spec != null) { |
| 782 | AttachInfo attachInfo = mViewRootImpl.mAttachInfo; |
| 783 | if (attachInfo.mDisplay == null) { |
| 784 | return; |
| 785 | } |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 786 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 787 | final float scale = attachInfo.mApplicationScale * spec.scale; |
| 788 | |
| 789 | Rect visibleWinFrame = mTempRect1; |
| 790 | visibleWinFrame.left = (int) (attachInfo.mWindowLeft * scale + spec.offsetX); |
| 791 | visibleWinFrame.top = (int) (attachInfo.mWindowTop * scale + spec.offsetY); |
| 792 | visibleWinFrame.right = (int) (visibleWinFrame.left + mViewRootImpl.mWidth * scale); |
| 793 | visibleWinFrame.bottom = (int) (visibleWinFrame.top + mViewRootImpl.mHeight * scale); |
| 794 | |
| 795 | attachInfo.mDisplay.getRealSize(mTempPoint); |
| 796 | final int displayWidth = mTempPoint.x; |
| 797 | final int displayHeight = mTempPoint.y; |
| 798 | |
| 799 | Rect visibleDisplayFrame = mTempRect2; |
| 800 | visibleDisplayFrame.set(0, 0, displayWidth, displayHeight); |
| 801 | |
Doris Liu | 9607fbe | 2015-05-28 17:17:28 -0700 | [diff] [blame] | 802 | if (!visibleWinFrame.intersect(visibleDisplayFrame)) { |
| 803 | // If there's no intersection with display, set visibleWinFrame empty. |
| 804 | visibleDisplayFrame.setEmpty(); |
| 805 | } |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 806 | |
| 807 | if (!visibleWinFrame.intersects(boundsInScreen.left, boundsInScreen.top, |
| 808 | boundsInScreen.right, boundsInScreen.bottom)) { |
| 809 | info.setVisibleToUser(false); |
| 810 | } |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 814 | private boolean shouldApplyAppScaleAndMagnificationSpec(float appScale, |
| 815 | MagnificationSpec spec) { |
| 816 | return (appScale != 1.0f || (spec != null && !spec.isNop())); |
| 817 | } |
Svetoslav Ganov | fd8d9c4 | 2012-07-09 18:16:55 -0700 | [diff] [blame] | 818 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 819 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 820 | * This class encapsulates a prefetching strategy for the accessibility APIs for |
| 821 | * querying window content. It is responsible to prefetch a batch of |
| 822 | * AccessibilityNodeInfos in addition to the one for a requested node. |
| 823 | */ |
| 824 | private class AccessibilityNodePrefetcher { |
| 825 | |
| 826 | private static final int MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE = 50; |
| 827 | |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 828 | private final ArrayList<View> mTempViewList = new ArrayList<View>(); |
| 829 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 830 | public void prefetchAccessibilityNodeInfos(View view, int virtualViewId, int fetchFlags, |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 831 | List<AccessibilityNodeInfo> outInfos) { |
| 832 | AccessibilityNodeProvider provider = view.getAccessibilityNodeProvider(); |
| 833 | if (provider == null) { |
| 834 | AccessibilityNodeInfo root = view.createAccessibilityNodeInfo(); |
| 835 | if (root != null) { |
| 836 | outInfos.add(root); |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 837 | if ((fetchFlags & AccessibilityNodeInfo.FLAG_PREFETCH_PREDECESSORS) != 0) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 838 | prefetchPredecessorsOfRealNode(view, outInfos); |
| 839 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 840 | if ((fetchFlags & AccessibilityNodeInfo.FLAG_PREFETCH_SIBLINGS) != 0) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 841 | prefetchSiblingsOfRealNode(view, outInfos); |
| 842 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 843 | if ((fetchFlags & AccessibilityNodeInfo.FLAG_PREFETCH_DESCENDANTS) != 0) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 844 | prefetchDescendantsOfRealNode(view, outInfos); |
| 845 | } |
| 846 | } |
| 847 | } else { |
Svetoslav | c569d35 | 2014-09-25 18:46:22 -0700 | [diff] [blame] | 848 | final AccessibilityNodeInfo root; |
| 849 | if (virtualViewId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
| 850 | root = provider.createAccessibilityNodeInfo(virtualViewId); |
| 851 | } else { |
| 852 | root = provider.createAccessibilityNodeInfo( |
| 853 | AccessibilityNodeProvider.HOST_VIEW_ID); |
| 854 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 855 | if (root != null) { |
| 856 | outInfos.add(root); |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 857 | if ((fetchFlags & AccessibilityNodeInfo.FLAG_PREFETCH_PREDECESSORS) != 0) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 858 | prefetchPredecessorsOfVirtualNode(root, view, provider, outInfos); |
| 859 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 860 | if ((fetchFlags & AccessibilityNodeInfo.FLAG_PREFETCH_SIBLINGS) != 0) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 861 | prefetchSiblingsOfVirtualNode(root, view, provider, outInfos); |
| 862 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 863 | if ((fetchFlags & AccessibilityNodeInfo.FLAG_PREFETCH_DESCENDANTS) != 0) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 864 | prefetchDescendantsOfVirtualNode(root, provider, outInfos); |
| 865 | } |
| 866 | } |
| 867 | } |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 868 | if (ENFORCE_NODE_TREE_CONSISTENT) { |
| 869 | enforceNodeTreeConsistent(outInfos); |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | private void enforceNodeTreeConsistent(List<AccessibilityNodeInfo> nodes) { |
| 874 | LongSparseArray<AccessibilityNodeInfo> nodeMap = |
| 875 | new LongSparseArray<AccessibilityNodeInfo>(); |
| 876 | final int nodeCount = nodes.size(); |
| 877 | for (int i = 0; i < nodeCount; i++) { |
| 878 | AccessibilityNodeInfo node = nodes.get(i); |
| 879 | nodeMap.put(node.getSourceNodeId(), node); |
| 880 | } |
| 881 | |
| 882 | // If the nodes are a tree it does not matter from |
| 883 | // which node we start to search for the root. |
| 884 | AccessibilityNodeInfo root = nodeMap.valueAt(0); |
| 885 | AccessibilityNodeInfo parent = root; |
| 886 | while (parent != null) { |
| 887 | root = parent; |
| 888 | parent = nodeMap.get(parent.getParentNodeId()); |
| 889 | } |
| 890 | |
| 891 | // Traverse the tree and do some checks. |
| 892 | AccessibilityNodeInfo accessFocus = null; |
| 893 | AccessibilityNodeInfo inputFocus = null; |
| 894 | HashSet<AccessibilityNodeInfo> seen = new HashSet<AccessibilityNodeInfo>(); |
| 895 | Queue<AccessibilityNodeInfo> fringe = new LinkedList<AccessibilityNodeInfo>(); |
| 896 | fringe.add(root); |
| 897 | |
| 898 | while (!fringe.isEmpty()) { |
| 899 | AccessibilityNodeInfo current = fringe.poll(); |
| 900 | |
| 901 | // Check for duplicates |
| 902 | if (!seen.add(current)) { |
| 903 | throw new IllegalStateException("Duplicate node: " |
| 904 | + current + " in window:" |
| 905 | + mViewRootImpl.mAttachInfo.mAccessibilityWindowId); |
| 906 | } |
| 907 | |
| 908 | // Check for one accessibility focus. |
| 909 | if (current.isAccessibilityFocused()) { |
| 910 | if (accessFocus != null) { |
| 911 | throw new IllegalStateException("Duplicate accessibility focus:" |
| 912 | + current |
| 913 | + " in window:" + mViewRootImpl.mAttachInfo.mAccessibilityWindowId); |
| 914 | } else { |
| 915 | accessFocus = current; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | // Check for one input focus. |
| 920 | if (current.isFocused()) { |
| 921 | if (inputFocus != null) { |
| 922 | throw new IllegalStateException("Duplicate input focus: " |
| 923 | + current + " in window:" |
| 924 | + mViewRootImpl.mAttachInfo.mAccessibilityWindowId); |
| 925 | } else { |
| 926 | inputFocus = current; |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | final int childCount = current.getChildCount(); |
| 931 | for (int j = 0; j < childCount; j++) { |
| 932 | final long childId = current.getChildId(j); |
| 933 | final AccessibilityNodeInfo child = nodeMap.get(childId); |
| 934 | if (child != null) { |
| 935 | fringe.add(child); |
| 936 | } |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | // Check for disconnected nodes. |
| 941 | for (int j = nodeMap.size() - 1; j >= 0; j--) { |
| 942 | AccessibilityNodeInfo info = nodeMap.valueAt(j); |
| 943 | if (!seen.contains(info)) { |
| 944 | throw new IllegalStateException("Disconnected node: " + info); |
| 945 | } |
| 946 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | private void prefetchPredecessorsOfRealNode(View view, |
| 950 | List<AccessibilityNodeInfo> outInfos) { |
| 951 | ViewParent parent = view.getParentForAccessibility(); |
| 952 | while (parent instanceof View |
| 953 | && outInfos.size() < MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 954 | View parentView = (View) parent; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 955 | AccessibilityNodeInfo info = parentView.createAccessibilityNodeInfo(); |
| 956 | if (info != null) { |
| 957 | outInfos.add(info); |
| 958 | } |
| 959 | parent = parent.getParentForAccessibility(); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | private void prefetchSiblingsOfRealNode(View current, |
| 964 | List<AccessibilityNodeInfo> outInfos) { |
| 965 | ViewParent parent = current.getParentForAccessibility(); |
| 966 | if (parent instanceof ViewGroup) { |
| 967 | ViewGroup parentGroup = (ViewGroup) parent; |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 968 | ArrayList<View> children = mTempViewList; |
| 969 | children.clear(); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 970 | try { |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 971 | parentGroup.addChildrenForAccessibility(children); |
| 972 | final int childCount = children.size(); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 973 | for (int i = 0; i < childCount; i++) { |
| 974 | if (outInfos.size() >= MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 975 | return; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 976 | } |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 977 | View child = children.get(i); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 978 | if (child.getAccessibilityViewId() != current.getAccessibilityViewId() |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 979 | && isShown(child)) { |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 980 | AccessibilityNodeInfo info = null; |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 981 | AccessibilityNodeProvider provider = |
| 982 | child.getAccessibilityNodeProvider(); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 983 | if (provider == null) { |
| 984 | info = child.createAccessibilityNodeInfo(); |
| 985 | } else { |
| 986 | info = provider.createAccessibilityNodeInfo( |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 987 | AccessibilityNodeProvider.HOST_VIEW_ID); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 988 | } |
| 989 | if (info != null) { |
| 990 | outInfos.add(info); |
| 991 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 992 | } |
| 993 | } |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 994 | } finally { |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 995 | children.clear(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 996 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 997 | } |
| 998 | } |
| 999 | |
| 1000 | private void prefetchDescendantsOfRealNode(View root, |
| 1001 | List<AccessibilityNodeInfo> outInfos) { |
| 1002 | if (!(root instanceof ViewGroup)) { |
| 1003 | return; |
| 1004 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1005 | HashMap<View, AccessibilityNodeInfo> addedChildren = |
| 1006 | new HashMap<View, AccessibilityNodeInfo>(); |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 1007 | ArrayList<View> children = mTempViewList; |
| 1008 | children.clear(); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1009 | try { |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 1010 | root.addChildrenForAccessibility(children); |
| 1011 | final int childCount = children.size(); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1012 | for (int i = 0; i < childCount; i++) { |
| 1013 | if (outInfos.size() >= MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 1014 | return; |
| 1015 | } |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 1016 | View child = children.get(i); |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 1017 | if (isShown(child)) { |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1018 | AccessibilityNodeProvider provider = child.getAccessibilityNodeProvider(); |
| 1019 | if (provider == null) { |
| 1020 | AccessibilityNodeInfo info = child.createAccessibilityNodeInfo(); |
| 1021 | if (info != null) { |
| 1022 | outInfos.add(info); |
| 1023 | addedChildren.put(child, null); |
| 1024 | } |
| 1025 | } else { |
| 1026 | AccessibilityNodeInfo info = provider.createAccessibilityNodeInfo( |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1027 | AccessibilityNodeProvider.HOST_VIEW_ID); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1028 | if (info != null) { |
| 1029 | outInfos.add(info); |
| 1030 | addedChildren.put(child, info); |
| 1031 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1032 | } |
| 1033 | } |
| 1034 | } |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 1035 | } finally { |
Svetoslav Ganov | 4528b4e | 2012-05-15 18:24:10 -0700 | [diff] [blame] | 1036 | children.clear(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1037 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1038 | if (outInfos.size() < MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 1039 | for (Map.Entry<View, AccessibilityNodeInfo> entry : addedChildren.entrySet()) { |
| 1040 | View addedChild = entry.getKey(); |
| 1041 | AccessibilityNodeInfo virtualRoot = entry.getValue(); |
| 1042 | if (virtualRoot == null) { |
| 1043 | prefetchDescendantsOfRealNode(addedChild, outInfos); |
| 1044 | } else { |
| 1045 | AccessibilityNodeProvider provider = |
| 1046 | addedChild.getAccessibilityNodeProvider(); |
| 1047 | prefetchDescendantsOfVirtualNode(virtualRoot, provider, outInfos); |
| 1048 | } |
| 1049 | } |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | private void prefetchPredecessorsOfVirtualNode(AccessibilityNodeInfo root, |
| 1054 | View providerHost, AccessibilityNodeProvider provider, |
| 1055 | List<AccessibilityNodeInfo> outInfos) { |
Svet Ganov | 75e5816 | 2016-02-19 16:29:24 -0800 | [diff] [blame] | 1056 | final int initialResultSize = outInfos.size(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1057 | long parentNodeId = root.getParentNodeId(); |
| 1058 | int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId(parentNodeId); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1059 | while (accessibilityViewId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1060 | if (outInfos.size() >= MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 1061 | return; |
| 1062 | } |
| 1063 | final int virtualDescendantId = |
| 1064 | AccessibilityNodeInfo.getVirtualDescendantId(parentNodeId); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1065 | if (virtualDescendantId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1066 | || accessibilityViewId == providerHost.getAccessibilityViewId()) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1067 | final AccessibilityNodeInfo parent; |
| 1068 | if (virtualDescendantId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
Alan Viverette | 84feea11 | 2014-11-04 15:59:55 -0800 | [diff] [blame] | 1069 | parent = provider.createAccessibilityNodeInfo(virtualDescendantId); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1070 | } else { |
Alan Viverette | 84feea11 | 2014-11-04 15:59:55 -0800 | [diff] [blame] | 1071 | parent = provider.createAccessibilityNodeInfo( |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1072 | AccessibilityNodeProvider.HOST_VIEW_ID); |
| 1073 | } |
Alan Viverette | 84feea11 | 2014-11-04 15:59:55 -0800 | [diff] [blame] | 1074 | if (parent == null) { |
Svet Ganov | 75e5816 | 2016-02-19 16:29:24 -0800 | [diff] [blame] | 1075 | // Going up the parent relation we found a null predecessor, |
| 1076 | // so remove these disconnected nodes form the result. |
| 1077 | final int currentResultSize = outInfos.size(); |
| 1078 | for (int i = currentResultSize - 1; i >= initialResultSize; i--) { |
| 1079 | outInfos.remove(i); |
| 1080 | } |
Alan Viverette | 84feea11 | 2014-11-04 15:59:55 -0800 | [diff] [blame] | 1081 | // Couldn't obtain the parent, which means we have a |
| 1082 | // disconnected sub-tree. Abort prefetch immediately. |
| 1083 | return; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1084 | } |
Alan Viverette | 84feea11 | 2014-11-04 15:59:55 -0800 | [diff] [blame] | 1085 | outInfos.add(parent); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1086 | parentNodeId = parent.getParentNodeId(); |
| 1087 | accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 1088 | parentNodeId); |
| 1089 | } else { |
| 1090 | prefetchPredecessorsOfRealNode(providerHost, outInfos); |
| 1091 | return; |
| 1092 | } |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | private void prefetchSiblingsOfVirtualNode(AccessibilityNodeInfo current, View providerHost, |
| 1097 | AccessibilityNodeProvider provider, List<AccessibilityNodeInfo> outInfos) { |
| 1098 | final long parentNodeId = current.getParentNodeId(); |
| 1099 | final int parentAccessibilityViewId = |
| 1100 | AccessibilityNodeInfo.getAccessibilityViewId(parentNodeId); |
| 1101 | final int parentVirtualDescendantId = |
| 1102 | AccessibilityNodeInfo.getVirtualDescendantId(parentNodeId); |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1103 | if (parentVirtualDescendantId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1104 | || parentAccessibilityViewId == providerHost.getAccessibilityViewId()) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1105 | final AccessibilityNodeInfo parent; |
Svetoslav | ed2fdc6 | 2014-09-26 19:23:05 -0700 | [diff] [blame] | 1106 | if (parentVirtualDescendantId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1107 | parent = provider.createAccessibilityNodeInfo(parentVirtualDescendantId); |
| 1108 | } else { |
| 1109 | parent = provider.createAccessibilityNodeInfo( |
| 1110 | AccessibilityNodeProvider.HOST_VIEW_ID); |
| 1111 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1112 | if (parent != null) { |
Alan Viverette | f0aed09 | 2013-11-06 15:33:03 -0800 | [diff] [blame] | 1113 | final int childCount = parent.getChildCount(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1114 | for (int i = 0; i < childCount; i++) { |
| 1115 | if (outInfos.size() >= MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 1116 | return; |
| 1117 | } |
Alan Viverette | f0aed09 | 2013-11-06 15:33:03 -0800 | [diff] [blame] | 1118 | final long childNodeId = parent.getChildId(i); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1119 | if (childNodeId != current.getSourceNodeId()) { |
| 1120 | final int childVirtualDescendantId = |
| 1121 | AccessibilityNodeInfo.getVirtualDescendantId(childNodeId); |
| 1122 | AccessibilityNodeInfo child = provider.createAccessibilityNodeInfo( |
| 1123 | childVirtualDescendantId); |
| 1124 | if (child != null) { |
| 1125 | outInfos.add(child); |
| 1126 | } |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | } else { |
| 1131 | prefetchSiblingsOfRealNode(providerHost, outInfos); |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | private void prefetchDescendantsOfVirtualNode(AccessibilityNodeInfo root, |
| 1136 | AccessibilityNodeProvider provider, List<AccessibilityNodeInfo> outInfos) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1137 | final int initialOutInfosSize = outInfos.size(); |
Alan Viverette | f0aed09 | 2013-11-06 15:33:03 -0800 | [diff] [blame] | 1138 | final int childCount = root.getChildCount(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1139 | for (int i = 0; i < childCount; i++) { |
| 1140 | if (outInfos.size() >= MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 1141 | return; |
| 1142 | } |
Alan Viverette | f0aed09 | 2013-11-06 15:33:03 -0800 | [diff] [blame] | 1143 | final long childNodeId = root.getChildId(i); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1144 | AccessibilityNodeInfo child = provider.createAccessibilityNodeInfo( |
| 1145 | AccessibilityNodeInfo.getVirtualDescendantId(childNodeId)); |
| 1146 | if (child != null) { |
| 1147 | outInfos.add(child); |
| 1148 | } |
| 1149 | } |
| 1150 | if (outInfos.size() < MAX_ACCESSIBILITY_NODE_INFO_BATCH_SIZE) { |
| 1151 | final int addedChildCount = outInfos.size() - initialOutInfosSize; |
| 1152 | for (int i = 0; i < addedChildCount; i++) { |
| 1153 | AccessibilityNodeInfo child = outInfos.get(initialOutInfosSize + i); |
| 1154 | prefetchDescendantsOfVirtualNode(child, provider, outInfos); |
| 1155 | } |
| 1156 | } |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | private class PrivateHandler extends Handler { |
| 1161 | private final static int MSG_PERFORM_ACCESSIBILITY_ACTION = 1; |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 1162 | private final static int MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_ACCESSIBILITY_ID = 2; |
| 1163 | private final static int MSG_FIND_ACCESSIBILITY_NODE_INFOS_BY_VIEW_ID = 3; |
| 1164 | private final static int MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_TEXT = 4; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1165 | private final static int MSG_FIND_FOCUS = 5; |
| 1166 | private final static int MSG_FOCUS_SEARCH = 6; |
| 1167 | |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 1168 | public PrivateHandler(Looper looper) { |
| 1169 | super(looper); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | @Override |
| 1173 | public String getMessageName(Message message) { |
| 1174 | final int type = message.what; |
| 1175 | switch (type) { |
| 1176 | case MSG_PERFORM_ACCESSIBILITY_ACTION: |
| 1177 | return "MSG_PERFORM_ACCESSIBILITY_ACTION"; |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 1178 | case MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_ACCESSIBILITY_ID: |
| 1179 | return "MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_ACCESSIBILITY_ID"; |
| 1180 | case MSG_FIND_ACCESSIBILITY_NODE_INFOS_BY_VIEW_ID: |
| 1181 | return "MSG_FIND_ACCESSIBILITY_NODE_INFOS_BY_VIEW_ID"; |
| 1182 | case MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_TEXT: |
| 1183 | return "MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_TEXT"; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1184 | case MSG_FIND_FOCUS: |
| 1185 | return "MSG_FIND_FOCUS"; |
| 1186 | case MSG_FOCUS_SEARCH: |
| 1187 | return "MSG_FOCUS_SEARCH"; |
| 1188 | default: |
| 1189 | throw new IllegalArgumentException("Unknown message type: " + type); |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | @Override |
| 1194 | public void handleMessage(Message message) { |
| 1195 | final int type = message.what; |
| 1196 | switch (type) { |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 1197 | case MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_ACCESSIBILITY_ID: { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1198 | findAccessibilityNodeInfoByAccessibilityIdUiThread(message); |
| 1199 | } break; |
| 1200 | case MSG_PERFORM_ACCESSIBILITY_ACTION: { |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1201 | performAccessibilityActionUiThread(message); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1202 | } break; |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 1203 | case MSG_FIND_ACCESSIBILITY_NODE_INFOS_BY_VIEW_ID: { |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1204 | findAccessibilityNodeInfosByViewIdUiThread(message); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1205 | } break; |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 1206 | case MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_TEXT: { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1207 | findAccessibilityNodeInfosByTextUiThread(message); |
| 1208 | } break; |
| 1209 | case MSG_FIND_FOCUS: { |
| 1210 | findFocusUiThread(message); |
| 1211 | } break; |
| 1212 | case MSG_FOCUS_SEARCH: { |
| 1213 | focusSearchUiThread(message); |
| 1214 | } break; |
| 1215 | default: |
| 1216 | throw new IllegalArgumentException("Unknown message type: " + type); |
| 1217 | } |
| 1218 | } |
| 1219 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1220 | |
| 1221 | private final class AddNodeInfosForViewId implements Predicate<View> { |
| 1222 | private int mViewId = View.NO_ID; |
| 1223 | private List<AccessibilityNodeInfo> mInfos; |
| 1224 | |
| 1225 | public void init(int viewId, List<AccessibilityNodeInfo> infos) { |
| 1226 | mViewId = viewId; |
| 1227 | mInfos = infos; |
| 1228 | } |
| 1229 | |
| 1230 | public void reset() { |
| 1231 | mViewId = View.NO_ID; |
| 1232 | mInfos = null; |
| 1233 | } |
| 1234 | |
| 1235 | @Override |
| 1236 | public boolean apply(View view) { |
| 1237 | if (view.getId() == mViewId && isShown(view)) { |
| 1238 | mInfos.add(view.createAccessibilityNodeInfo()); |
| 1239 | } |
| 1240 | return false; |
| 1241 | } |
| 1242 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1243 | } |