X-SLAYER / flutter_accessibility_service

Flutter plugin for interacting with Accessibility Service in Android.
https://pub.dev/packages/flutter_accessibility_service
MIT License
33 stars 24 forks source link

ANR issues due to `getSubNodes` recursion depth #28

Open saurabhkumar8112 opened 6 months ago

saurabhkumar8112 commented 6 months ago

When iterating through the child nodes of a parent node, the method onAccessibilityEvent invokes getSubNodes, a recursive function. This recursion, influenced by the depth of the tree (treeDepth), has the potential to cause a stack overflow, leading to Application Not Responding (ANR) errors.

There are discussions on StackOverflow, of ANRs occurring when the accessibility service is used for navigating through AccessibilityNodeInfo.

To mitigate this issue, I propose to add a new parameter, maximumTreeDepth, which would serve as a threshold for the recursion depth. Once this threshold is reached, further traversal operations would be halted, and the method getNextTexts can return.

This approach allows users to balance the trade-off between performance aspects (such as minimizing ANRs and reducing battery consumption) and usability, by adjusting the maximumTreeDepth parameter according to the needs of their specific application.

Let me know what do you think about it, I can then raise a PR for the same!

X-SLAYER commented 6 months ago

yes that's what i though about it will be better if you can raise an PR about this so we could test that