Skip to content

Commit 12bde60

Browse files
sganovAndroid (Google) Code Review
authored andcommitted
Merge "Intra-process view hierarchy interrogation does not work."
2 parents 8799b4b + 8bd6961 commit 12bde60

File tree

11 files changed

+753
-316
lines changed

11 files changed

+753
-316
lines changed

core/java/android/accessibilityservice/IAccessibilityServiceConnection.aidl

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package android.accessibilityservice;
1818

1919
import android.accessibilityservice.AccessibilityServiceInfo;
2020
import android.view.accessibility.AccessibilityNodeInfo;
21+
import android.view.accessibility.IAccessibilityInteractionConnectionCallback;
2122

2223
/**
2324
* Interface given to an AccessibilitySerivce to talk to the AccessibilityManagerService.
@@ -30,84 +31,79 @@ interface IAccessibilityServiceConnection {
3031

3132
/**
3233
* Finds an {@link AccessibilityNodeInfo} by accessibility id.
33-
* <p>
34-
* <strong>
35-
* It is a client responsibility to recycle the received info by
36-
* calling {@link AccessibilityNodeInfo#recycle()} to avoid creating
37-
* of multiple instances.
38-
* </strong>
39-
* </p>
4034
*
4135
* @param accessibilityWindowId A unique window id.
4236
* @param accessibilityViewId A unique View accessibility id.
43-
* @return The node info.
37+
* @param interactionId The id of the interaction for matching with the callback result.
38+
* @param callback Callback which to receive the result.
39+
* @param threadId The id of the calling thread.
40+
* @return The current window scale, where zero means a failure.
4441
*/
45-
AccessibilityNodeInfo findAccessibilityNodeInfoByAccessibilityId(int accessibilityWindowId,
46-
int accessibilityViewId);
42+
float findAccessibilityNodeInfoByAccessibilityId(int accessibilityWindowId,
43+
int accessibilityViewId, int interactionId,
44+
IAccessibilityInteractionConnectionCallback callback, long threadId);
4745

4846
/**
4947
* Finds {@link AccessibilityNodeInfo}s by View text. The match is case
5048
* insensitive containment. The search is performed in the window whose
5149
* id is specified and starts from the View whose accessibility id is
5250
* specified.
53-
* <p>
54-
* <strong>
55-
* It is a client responsibility to recycle the received infos by
56-
* calling {@link AccessibilityNodeInfo#recycle()} to avoid creating
57-
* of multiple instances.
58-
* </strong>
59-
* </p>
6051
*
6152
* @param text The searched text.
62-
* @param accessibilityId The id of the view from which to start searching.
53+
* @param accessibilityWindowId A unique window id.
54+
* @param accessibilityViewId A unique View accessibility id from where to start the search.
6355
* Use {@link android.view.View#NO_ID} to start from the root.
64-
* @return A list of node info.
56+
* @param interactionId The id of the interaction for matching with the callback result.
57+
* @param callback Callback which to receive the result.
58+
* @param threadId The id of the calling thread.
59+
* @return The current window scale, where zero means a failure.
6560
*/
66-
List<AccessibilityNodeInfo> findAccessibilityNodeInfosByViewText(String text,
67-
int accessibilityWindowId, int accessibilityViewId);
61+
float findAccessibilityNodeInfosByViewText(String text, int accessibilityWindowId,
62+
int accessibilityViewId, int interractionId,
63+
IAccessibilityInteractionConnectionCallback callback, long threadId);
6864

6965
/**
7066
* Finds {@link AccessibilityNodeInfo}s by View text. The match is case
7167
* insensitive containment. The search is performed in the currently
7268
* active window and start from the root View in the window.
73-
* <p>
74-
* <strong>
75-
* It is a client responsibility to recycle the received infos by
76-
* calling {@link AccessibilityNodeInfo#recycle()} to avoid creating
77-
* of multiple instances.
78-
* </strong>
79-
* </p>
8069
*
8170
* @param text The searched text.
8271
* @param accessibilityId The id of the view from which to start searching.
8372
* Use {@link android.view.View#NO_ID} to start from the root.
84-
* @return A list of node info.
73+
* @param interactionId The id of the interaction for matching with the callback result.
74+
* @param callback Callback which to receive the result.
75+
* @param threadId The id of the calling thread.
76+
* @return The current window scale, where zero means a failure.
8577
*/
86-
List<AccessibilityNodeInfo> findAccessibilityNodeInfosByViewTextInActiveWindow(String text);
78+
float findAccessibilityNodeInfosByViewTextInActiveWindow(String text,
79+
int interactionId, IAccessibilityInteractionConnectionCallback callback,
80+
long threadId);
8781

8882
/**
8983
* Finds an {@link AccessibilityNodeInfo} by View id. The search is performed
90-
* in the currently active window and start from the root View in the window.
91-
* <p>
92-
* <strong>
93-
* It is a client responsibility to recycle the received info by
94-
* calling {@link AccessibilityNodeInfo#recycle()} to avoid creating
95-
* of multiple instances.
96-
* </strong>
97-
* </p>
84+
* in the currently active window and starts from the root View in the window.
9885
*
9986
* @param id The id of the node.
100-
* @return The node info.
87+
* @param interactionId The id of the interaction for matching with the callback result.
88+
* @param callback Callback which to receive the result.
89+
* @param threadId The id of the calling thread.
90+
* @return The current window scale, where zero means a failure.
10191
*/
102-
AccessibilityNodeInfo findAccessibilityNodeInfoByViewIdInActiveWindow(int viewId);
92+
float findAccessibilityNodeInfoByViewIdInActiveWindow(int viewId, int interactionId,
93+
IAccessibilityInteractionConnectionCallback callback, long threadId);
10394

10495
/**
10596
* Performs an accessibility action on an {@link AccessibilityNodeInfo}.
10697
*
10798
* @param accessibilityWindowId The id of the window.
108-
* @param accessibilityViewId The of a view in the .
99+
* @param accessibilityViewId A unique View accessibility id.
100+
* @param action The action to perform.
101+
* @param interactionId The id of the interaction for matching with the callback result.
102+
* @param callback Callback which to receive the result.
103+
* @param threadId The id of the calling thread.
109104
* @return Whether the action was performed.
110105
*/
111106
boolean performAccessibilityAction(int accessibilityWindowId, int accessibilityViewId,
112-
int action);
107+
int action, int interactionId, IAccessibilityInteractionConnectionCallback callback,
108+
long threadId);
113109
}

core/java/android/view/ViewRootImpl.java

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import android.util.TypedValue;
6262
import android.view.View.MeasureSpec;
6363
import android.view.accessibility.AccessibilityEvent;
64+
import android.view.accessibility.AccessibilityInteractionClient;
6465
import android.view.accessibility.AccessibilityManager;
6566
import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener;
6667
import android.view.accessibility.AccessibilityNodeInfo;
@@ -4362,37 +4363,42 @@ final class AccessibilityInteractionConnection
43624363
}
43634364

43644365
public void findAccessibilityNodeInfoByAccessibilityId(int accessibilityId,
4365-
int interactionId, IAccessibilityInteractionConnectionCallback callback) {
4366+
int interactionId, IAccessibilityInteractionConnectionCallback callback,
4367+
int interrogatingPid, long interrogatingTid) {
43664368
if (mViewAncestor.get() != null) {
43674369
getAccessibilityInteractionController()
43684370
.findAccessibilityNodeInfoByAccessibilityIdClientThread(accessibilityId,
4369-
interactionId, callback);
4371+
interactionId, callback, interrogatingPid, interrogatingTid);
43704372
}
43714373
}
43724374

43734375
public void performAccessibilityAction(int accessibilityId, int action,
4374-
int interactionId, IAccessibilityInteractionConnectionCallback callback) {
4376+
int interactionId, IAccessibilityInteractionConnectionCallback callback,
4377+
int interogatingPid, long interrogatingTid) {
43754378
if (mViewAncestor.get() != null) {
43764379
getAccessibilityInteractionController()
43774380
.performAccessibilityActionClientThread(accessibilityId, action, interactionId,
4378-
callback);
4381+
callback, interogatingPid, interrogatingTid);
43794382
}
43804383
}
43814384

43824385
public void findAccessibilityNodeInfoByViewId(int viewId,
4383-
int interactionId, IAccessibilityInteractionConnectionCallback callback) {
4386+
int interactionId, IAccessibilityInteractionConnectionCallback callback,
4387+
int interrogatingPid, long interrogatingTid) {
43844388
if (mViewAncestor.get() != null) {
43854389
getAccessibilityInteractionController()
4386-
.findAccessibilityNodeInfoByViewIdClientThread(viewId, interactionId, callback);
4390+
.findAccessibilityNodeInfoByViewIdClientThread(viewId, interactionId, callback,
4391+
interrogatingPid, interrogatingTid);
43874392
}
43884393
}
43894394

43904395
public void findAccessibilityNodeInfosByViewText(String text, int accessibilityId,
4391-
int interactionId, IAccessibilityInteractionConnectionCallback callback) {
4396+
int interactionId, IAccessibilityInteractionConnectionCallback callback,
4397+
int interrogatingPid, long interrogatingTid) {
43924398
if (mViewAncestor.get() != null) {
43934399
getAccessibilityInteractionController()
43944400
.findAccessibilityNodeInfosByViewTextClientThread(text, accessibilityId,
4395-
interactionId, callback);
4401+
interactionId, callback, interrogatingPid, interrogatingTid);
43964402
}
43974403
}
43984404
}
@@ -4468,13 +4474,24 @@ private void clear() {
44684474
}
44694475

44704476
public void findAccessibilityNodeInfoByAccessibilityIdClientThread(int accessibilityId,
4471-
int interactionId, IAccessibilityInteractionConnectionCallback callback) {
4477+
int interactionId, IAccessibilityInteractionConnectionCallback callback,
4478+
int interrogatingPid, long interrogatingTid) {
44724479
Message message = Message.obtain();
44734480
message.what = DO_FIND_ACCESSIBLITY_NODE_INFO_BY_ACCESSIBILITY_ID;
44744481
message.arg1 = accessibilityId;
44754482
message.arg2 = interactionId;
44764483
message.obj = callback;
4477-
sendMessage(message);
4484+
// If the interrogation is performed by the same thread as the main UI
4485+
// thread in this process, set the message as a static reference so
4486+
// after this call completes the same thread but in the interrogating
4487+
// client can handle the message to generate the result.
4488+
if (interrogatingPid == Process.myPid()
4489+
&& interrogatingTid == Looper.getMainLooper().getThread().getId()) {
4490+
message.setTarget(ViewRootImpl.this);
4491+
AccessibilityInteractionClient.getInstance().setSameThreadMessage(message);
4492+
} else {
4493+
sendMessage(message);
4494+
}
44784495
}
44794496

44804497
public void findAccessibilityNodeInfoByAccessibilityIdUiThread(Message message) {
@@ -4502,13 +4519,24 @@ public void findAccessibilityNodeInfoByAccessibilityIdUiThread(Message message)
45024519
}
45034520

45044521
public void findAccessibilityNodeInfoByViewIdClientThread(int viewId, int interactionId,
4505-
IAccessibilityInteractionConnectionCallback callback) {
4522+
IAccessibilityInteractionConnectionCallback callback, int interrogatingPid,
4523+
long interrogatingTid) {
45064524
Message message = Message.obtain();
45074525
message.what = DO_FIND_ACCESSIBLITY_NODE_INFO_BY_VIEW_ID;
45084526
message.arg1 = viewId;
45094527
message.arg2 = interactionId;
45104528
message.obj = callback;
4511-
sendMessage(message);
4529+
// If the interrogation is performed by the same thread as the main UI
4530+
// thread in this process, set the message as a static reference so
4531+
// after this call completes the same thread but in the interrogating
4532+
// client can handle the message to generate the result.
4533+
if (interrogatingPid == Process.myPid()
4534+
&& interrogatingTid == Looper.getMainLooper().getThread().getId()) {
4535+
message.setTarget(ViewRootImpl.this);
4536+
AccessibilityInteractionClient.getInstance().setSameThreadMessage(message);
4537+
} else {
4538+
sendMessage(message);
4539+
}
45124540
}
45134541

45144542
public void findAccessibilityNodeInfoByViewIdUiThread(Message message) {
@@ -4535,7 +4563,8 @@ public void findAccessibilityNodeInfoByViewIdUiThread(Message message) {
45354563

45364564
public void findAccessibilityNodeInfosByViewTextClientThread(String text,
45374565
int accessibilityViewId, int interactionId,
4538-
IAccessibilityInteractionConnectionCallback callback) {
4566+
IAccessibilityInteractionConnectionCallback callback, int interrogatingPid,
4567+
long interrogatingTid) {
45394568
Message message = Message.obtain();
45404569
message.what = DO_FIND_ACCESSIBLITY_NODE_INFO_BY_VIEW_TEXT;
45414570
SomeArgs args = mPool.acquire();
@@ -4544,7 +4573,17 @@ public void findAccessibilityNodeInfosByViewTextClientThread(String text,
45444573
args.argi2 = interactionId;
45454574
args.arg2 = callback;
45464575
message.obj = args;
4547-
sendMessage(message);
4576+
// If the interrogation is performed by the same thread as the main UI
4577+
// thread in this process, set the message as a static reference so
4578+
// after this call completes the same thread but in the interrogating
4579+
// client can handle the message to generate the result.
4580+
if (interrogatingPid == Process.myPid()
4581+
&& interrogatingTid == Looper.getMainLooper().getThread().getId()) {
4582+
message.setTarget(ViewRootImpl.this);
4583+
AccessibilityInteractionClient.getInstance().setSameThreadMessage(message);
4584+
} else {
4585+
sendMessage(message);
4586+
}
45484587
}
45494588

45504589
public void findAccessibilityNodeInfosByViewTextUiThread(Message message) {
@@ -4597,7 +4636,8 @@ public void findAccessibilityNodeInfosByViewTextUiThread(Message message) {
45974636
}
45984637

45994638
public void performAccessibilityActionClientThread(int accessibilityId, int action,
4600-
int interactionId, IAccessibilityInteractionConnectionCallback callback) {
4639+
int interactionId, IAccessibilityInteractionConnectionCallback callback,
4640+
int interogatingPid, long interrogatingTid) {
46014641
Message message = Message.obtain();
46024642
message.what = DO_PERFORM_ACCESSIBILITY_ACTION;
46034643
SomeArgs args = mPool.acquire();
@@ -4606,7 +4646,17 @@ public void performAccessibilityActionClientThread(int accessibilityId, int acti
46064646
args.argi3 = interactionId;
46074647
args.arg1 = callback;
46084648
message.obj = args;
4609-
sendMessage(message);
4649+
// If the interrogation is performed by the same thread as the main UI
4650+
// thread in this process, set the message as a static reference so
4651+
// after this call completes the same thread but in the interrogating
4652+
// client can handle the message to generate the result.
4653+
if (interogatingPid == Process.myPid()
4654+
&& interrogatingTid == Looper.getMainLooper().getThread().getId()) {
4655+
message.setTarget(ViewRootImpl.this);
4656+
AccessibilityInteractionClient.getInstance().setSameThreadMessage(message);
4657+
} else {
4658+
sendMessage(message);
4659+
}
46104660
}
46114661

46124662
public void perfromAccessibilityActionUiThread(Message message) {

0 commit comments

Comments
 (0)