4

i am getting ANR from reports

Broadcast of Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.google.android.apps.maps flg=0x4000010 cmp=xx.xx.xx/com.microsoft.aad.adal.ApplicationReceiver (has extras) }

Broadcast of Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.google.android.apps.translate flg=0x4000010 cmp=xx.xx.xx/com.microsoft.aad.adal.ApplicationReceiver (has extras) }

"main" prio=5 tid=1 TimedWaiting | group="main" sCount=1 dsCount=0 obj=0x7527b598 self=0xe9105400 | sysTid=29196 nice=0 cgrp=default sched=0/0 handle=0xebfd2534 | state=S schedstat=( 0 0 0 ) utm=1236 stm=469 core=2 HZ=100 | stack=0xff733000-0xff735000 stackSize=8MB
| held mutexes= at java.lang.Object.wait! (Native method) - waiting on <0x0fa0a2fe> (a java.lang.Object) at java.lang.Object.wait (Object.java:407) at android.view.accessibility.AccessibilityInteractionClient.waitForResultTimedLocked (AccessibilityInteractionClient.java:685) at android.view.accessibility.AccessibilityInteractionClient.getFindAccessibilityNodeInfosResultAndClear (AccessibilityInteractionClient.java:580) - locked <0x0fa0a2fe> (a java.lang.Object) at android.view.accessibility.AccessibilityInteractionClient.findAccessibilityNodeInfoByAccessibilityId (AccessibilityInteractionClient.java:292) at android.view.accessibility.AccessibilityNodeInfo.getChild (AccessibilityNodeInfo.java:851) at xxx.traverseNode (FooAccessibilityService.java:85) at xxx.traverseNode (FooAccessibilityService.java:86) at xxx.traverseNode (FooAccessibilityService.java:86) at xxx.traverseNode (FooAccessibilityService.java:86) at xxx.collectNodes (FooAccessibilityService.java:66) at xxx.onAccessibilityEvent (FooAccessibilityService.java:365) at android.accessibilityservice.AccessibilityService$2.onAccessibilityEvent (AccessibilityService.java:1449) at android.accessibilityservice.AccessibilityService$IAccessibilityServiceClientWrapper.executeMessage (AccessibilityService.java:1585) at com.android.internal.os.HandlerCaller$MyHandler.handleMessage (HandlerCaller.java:37) at android.os.Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:154) at android.app.ActivityThread.main (ActivityThread.java:6316) at java.lang.reflect.Method.invoke! (Native method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:872) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:762)

My code is

    ArrayList<AccessibilityNodeInfo> collectNodes(AccessibilityNodeInfo node) {

    ArrayList<AccessibilityNodeInfo> nodeInfoArrayList = new ArrayList<>();
    try {
        int childCount = node.getChildCount();
        for (int index = 0; index < childCount; index++) {
            AccessibilityNodeInfo childNode = node.getChild(index);


            traverseNode(childNode);
            if (childNodes != null && childNodes.size() > 0) {
                nodeInfoArrayList.addAll(childNodes);
                childNodes.clear();
            }
        }
    }
    catch (Exception e){
        e.printStackTrace();
    }
    return nodeInfoArrayList;
}

private void traverseNode(AccessibilityNodeInfo node) {
    try {
        AccessibilityNodeInfo edittextNode = null;
        if (null == node)
            return;

        final int count = node.getChildCount();
        if (count > 0) {
            for (int i = 0; i < count; i++) {
                AccessibilityNodeInfo childNode = node.getChild(i);
                if (childNode == null) {
                    node.recycle();
                    return;
                }
                else {
                    traverseNode(childNode);
                }
            }
        } else {

        }
    }
    catch (Exception error){
        error.printStackTrace();
    }
}

Any idea how to resolve this issue

Nikhil
  • 1,023
  • 17
  • 35
  • Reading your code, It looks like you might not be recycling every node. You only recycle them if a childNode comes back null, which might not always be the case. I wonder if that could be related to your problem. – Tyler Dec 19 '17 at 18:07
  • Reported, please star: https://issuetracker.google.com/issues/111445875 – ballzak Jul 14 '18 at 20:21
  • Did you have any update on this? I also experience same problem but not found any thing to solve it yet. – Harry T. Jul 21 '20 at 09:29

3 Answers3

2

If an app doesn't respond to the request for the AccessibilityNodeInfo, the request for it from the AccessibilityService will time out and return null. That timeout is set to 5s.

If you make repeated requests from the unresponsive app, you can end up with very long waits.

In the first part of the code shown, the loop will continue trying to traverse nodes even if that fails. That can lead to very long delays.

Phil Weaver
  • 738
  • 3
  • 7
  • Why would the AccessibilityNodeInfo.getChild() even have to wait for a "request", it's just a simple IPC/binder transfer. The doc for getChild() say nothing about calling it from a separate thread, seems odd since it's often called in an AccessibilityService.onAccessibilityEvent() callback. – ballzak Jul 20 '18 at 02:57
  • It's actually three IPCs. The first goes from the accessibility service to the system. The second is from the system to the app to request the AccessibilityNodeInfo be populated. The third is from the app to the accessibility service with the populated node(s). So an unresponsive app can cause getChild to have a long delay or a timeout. – Phil Weaver Jul 23 '18 at 18:20
  • I thought the system already got a private copy of the nodes, seems very inefficient that every accessibility service has to query the layout of the visible app separately. Anyhow, is this considered a bug that will be fixed, or should developers figure out another solution? – ballzak Jul 23 '18 at 20:12
  • Different services may actually need different hierarchies, for example they can request nodes that are "not important for accessibility". – Phil Weaver Jul 24 '18 at 22:14
  • The issue with unresponsive apps causing unresponsive services is pretty fundamental to how accessibility information is transported in Android. The system doesn't insulate services from unresponsive apps, so services need to do that themselves for now, for example by having separate threads for each window. Not ideal, I know. – Phil Weaver Jul 24 '18 at 22:19
  • 1
    The issue seems more prevalent since Android 8, as i report in the bug tracker. – ballzak Jul 25 '18 at 03:12
0

I got a very similar issue :

"main" prio=5 tid=1 TimedWaiting
  | group="main" sCount=1 dsCount=0 obj=0x74e352e8 self=0xb45f6a00
  | sysTid=1785 nice=0 cgrp=default sched=0/0 handle=0xb6efdde4
  | state=S schedstat=( 20808880338 15171670769 80754 ) utm=1292 stm=788 core=1 HZ=100
  | stack=0xbe022000-0xbe024000 stackSize=8MB
  | held mutexes=

  at java.lang.Object.wait! (Native method)
- waiting on <0x022019b2> (a java.lang.Object)

  at java.lang.Object.wait (Object.java:423)

  at android.view.accessibility.AccessibilityInteractionClient.waitForResultTimedLocked (AccessibilityInteractionClient.java:695)

  at android.view.accessibility.AccessibilityInteractionClient.getFindAccessibilityNodeInfosResultAndClear (AccessibilityInteractionClient.java:590)
- locked <0x022019b2> (a java.lang.Object)

  at android.view.accessibility.AccessibilityInteractionClient.findAccessibilityNodeInfosByViewId (AccessibilityInteractionClient.java:349)

  at android.view.accessibility.AccessibilityNodeInfo.findAccessibilityNodeInfosByViewId (AccessibilityNodeInfo.java:1374)

  at com.myApp.myFct (mySource.java:69)

This error is reported on Android 6, and 7.1, but mostly on android 7.0

UPDATE:

  • we don't have a lot of user on android 8 yet, but I also see the problem on android 8.
  • I still got no clue about how to fix that.
-4

I found issue, actually this is issue due to onedrive-sdk-android

As per onedrive i use below code

repository {
    jcenter()
}

dependency {
    // Include the sdk as a dependency
    compile ('com.onedrive.sdk:onedrive-sdk-android:1.3+') {
        transitive = false
    }

    // Include the gson dependency
    compile ('com.google.code.gson:gson:2.3.1')

    // Include supported authentication methods for your application
    compile ('com.microsoft.services.msa:msa-auth:0.8.+')
    compile ('com.microsoft.aad:adal:1.1.+')
}

and below line

compile ('com.microsoft.aad:adal:1.1.+')

create error which i found here, after change compile ('com.microsoft.aad:adal:1.1.+') to compile ('com.microsoft.aad:adal:1.13.1') resolved issue.

Nikhil
  • 1,023
  • 17
  • 35