Skip to content

Commit 6bc5e53

Browse files
committed
Inter process interrogation ocassionally gets stuck.
1. There was a bug that was not handling correctly the case for which the interrogator requests an accessibility node info and the message describing how to fetch the latter for the same process case was delivered after the code that checks whether the message is there in order to dispatch it is executed. Now the message handling is done correctly - the caller checks if the message is present and if so processes it, otherwise the caller sleeps and is interrupted if such a message arrives. bug:5138933 Change-Id: I4c2940b46c9a52a51c5ee48b83ca6811489765d6
1 parent 5e87525 commit 6bc5e53

1 file changed

Lines changed: 7 additions & 17 deletions

File tree

core/java/android/view/accessibility/AccessibilityInteractionClient.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public static AccessibilityInteractionClient getInstance() {
104104
public void setSameThreadMessage(Message message) {
105105
synchronized (mInstanceLock) {
106106
mSameThreadMessage = message;
107+
mInstanceLock.notifyAll();
107108
}
108109
}
109110

@@ -125,7 +126,6 @@ public AccessibilityNodeInfo findAccessibilityNodeInfoByAccessibilityId(
125126
Thread.currentThread().getId());
126127
// If the scale is zero the call has failed.
127128
if (windowScale > 0) {
128-
handleSameThreadMessageIfNeeded();
129129
AccessibilityNodeInfo info = getFindAccessibilityNodeInfoResultAndClear(
130130
interactionId);
131131
finalizeAccessibilityNodeInfo(info, connection, windowScale);
@@ -142,7 +142,7 @@ public AccessibilityNodeInfo findAccessibilityNodeInfoByAccessibilityId(
142142
* in the currently active window and starts from the root View in the window.
143143
*
144144
* @param connection A connection for interacting with the system.
145-
* @param id The id of the node.
145+
* @param viewId The id of the view.
146146
* @return An {@link AccessibilityNodeInfo} if found, null otherwise.
147147
*/
148148
public AccessibilityNodeInfo findAccessibilityNodeInfoByViewIdInActiveWindow(
@@ -153,7 +153,6 @@ public AccessibilityNodeInfo findAccessibilityNodeInfoByViewIdInActiveWindow(
153153
viewId, interactionId, this, Thread.currentThread().getId());
154154
// If the scale is zero the call has failed.
155155
if (windowScale > 0) {
156-
handleSameThreadMessageIfNeeded();
157156
AccessibilityNodeInfo info = getFindAccessibilityNodeInfoResultAndClear(
158157
interactionId);
159158
finalizeAccessibilityNodeInfo(info, connection, windowScale);
@@ -182,7 +181,6 @@ public List<AccessibilityNodeInfo> findAccessibilityNodeInfosByViewTextInActiveW
182181
text, interactionId, this, Thread.currentThread().getId());
183182
// If the scale is zero the call has failed.
184183
if (windowScale > 0) {
185-
handleSameThreadMessageIfNeeded();
186184
List<AccessibilityNodeInfo> infos = getFindAccessibilityNodeInfosResultAndClear(
187185
interactionId);
188186
finalizeAccessibilityNodeInfos(infos, connection, windowScale);
@@ -217,7 +215,6 @@ public List<AccessibilityNodeInfo> findAccessibilityNodeInfosByViewText(
217215
Thread.currentThread().getId());
218216
// If the scale is zero the call has failed.
219217
if (windowScale > 0) {
220-
handleSameThreadMessageIfNeeded();
221218
List<AccessibilityNodeInfo> infos = getFindAccessibilityNodeInfosResultAndClear(
222219
interactionId);
223220
finalizeAccessibilityNodeInfos(infos, connection, windowScale);
@@ -246,7 +243,6 @@ public boolean performAccessibilityAction(IAccessibilityServiceConnection connec
246243
accessibilityWindowId, accessibilityViewId, action, interactionId, this,
247244
Thread.currentThread().getId());
248245
if (success) {
249-
handleSameThreadMessageIfNeeded();
250246
return getPerformAccessibilityActionResult(interactionId);
251247
}
252248
} catch (RemoteException re) {
@@ -363,6 +359,11 @@ private boolean waitForResultTimedLocked(int interactionId) {
363359
final long startTimeMillis = SystemClock.uptimeMillis();
364360
while (true) {
365361
try {
362+
Message sameProcessMessage = getSameProcessMessageAndClear();
363+
if (sameProcessMessage != null) {
364+
sameProcessMessage.getTarget().handleMessage(sameProcessMessage);
365+
}
366+
366367
if (mInteractionId == interactionId) {
367368
return true;
368369
}
@@ -401,17 +402,6 @@ private void applyCompatibilityScaleIfNeeded(AccessibilityNodeInfo info, float s
401402
info.setBoundsInScreen(bounds);
402403
}
403404

404-
/**
405-
* Handles the message stored if the interacted and interacting
406-
* threads are the same otherwise this is a NOP.
407-
*/
408-
private void handleSameThreadMessageIfNeeded() {
409-
Message sameProcessMessage = getSameProcessMessageAndClear();
410-
if (sameProcessMessage != null) {
411-
sameProcessMessage.getTarget().handleMessage(sameProcessMessage);
412-
}
413-
}
414-
415405
/**
416406
* Finalize an {@link AccessibilityNodeInfo} before passing it to the client.
417407
*

0 commit comments

Comments
 (0)