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