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