6161import android .util .TypedValue ;
6262import android .view .View .MeasureSpec ;
6363import android .view .accessibility .AccessibilityEvent ;
64+ import android .view .accessibility .AccessibilityInteractionClient ;
6465import android .view .accessibility .AccessibilityManager ;
6566import android .view .accessibility .AccessibilityManager .AccessibilityStateChangeListener ;
6667import 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