question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modal on android make app crash when any accessibility service is ON

See original GitHub issue

the Modal component throws an exception when the modal is opening with any accessibilty service is ON (like TalkBack) I have found the cause of the issue, and paste some related code. But I haven’t known how to solve the problem. Any helps will be great.

the stack trace:

java.lang.IllegalArgumentException:` parameter must be a descendant of this view
                    at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:5334)
                    at android.view.ViewGroup.offsetDescendantRectToMyCoords(ViewGroup.java:5263)
                    at android.view.ViewGroup$ViewLocationHolder.init(ViewGroup.java:7730)
                    at android.view.ViewGroup$ViewLocationHolder.obtain(ViewGroup.java:7664)
                    at android.view.ViewGroup$ChildListForAccessibility.init(ViewGroup.java:7599)
                    at android.view.ViewGroup$ChildListForAccessibility.obtain(ViewGroup.java:7567)
                    at android.view.ViewGroup.addChildrenForAccessibility(ViewGroup.java:1927)
                    at android.view.ViewGroup.addChildrenForAccessibility(ViewGroup.java:1936)
                    at android.view.ViewGroup.onInitializeAccessibilityNodeInfoInternal(ViewGroup.java:2978)
                    at android.view.View.onInitializeAccessibilityNodeInfo(View.java:6084)
                    at android.view.View.createAccessibilityNodeInfoInternal(View.java:6043)
                    at android.view.View.createAccessibilityNodeInfo(View.java:6028)
                    at android.view.accessibility.AccessibilityRecord.setSource(AccessibilityRecord.java:145)
                    at android.view.accessibility.AccessibilityRecord.setSource(AccessibilityRecord.java:119)
                    at android.view.View.onInitializeAccessibilityEventInternal(View.java:5980)
                    at android.view.View.onInitializeAccessibilityEvent(View.java:5968)
                    at android.view.View.sendAccessibilityEventUncheckedInternal(View.java:5833)
                    at android.view.View.sendAccessibilityEventUnchecked(View.java:5818)
                    at android.view.ViewRootImpl$SendWindowContentChangedAccessibilityEvent.run(ViewRootImpl.java:7154)
                    at android.os.Handler.handleCallback(Handler.java:739)
                    at android.os.Handler.dispatchMessage(Handler.java:95)
                    at android.os.Looper.loop(Looper.java:148)
                    at android.app.ActivityThread.main(ActivityThread.java:5417)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

related code: android.view.View:

    public void notifySubtreeAccessibilityStateChangedIfNeeded() {
        if (!AccessibilityManager.getInstance(mContext).isEnabled() || mAttachInfo == null) {
            return;
        }
       if ((mPrivateFlags2 & PFLAG2_SUBTREE_ACCESSIBILITY_STATE_CHANGED) == 0) {
            mPrivateFlags2 |= PFLAG2_SUBTREE_ACCESSIBILITY_STATE_CHANGED;
            if (mParent != null) {
                try {
                    mParent.notifySubtreeAccessibilityStateChanged(
                            this, this, AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE);
                } catch (AbstractMethodError e) {
                    Log.e(VIEW_LOG_TAG, mParent.getClass().getSimpleName() +
                            " does not fully implement ViewParent", e);
                }
            }
        }
    }

When no accessibility service is on, the method notifySubtreeAccessibilityStateChangedIfNeeded return immediately, but, when any accessibility is on, the method will do more things. The program will run into offsetRectBetweenParentAndChild method in ViewGroup, which throws the exception. android.view.ViewGroup:

void offsetRectBetweenParentAndChild(View descendant, Rect rect,
            boolean offsetFromChildToParent, boolean clipToBounds) {

        // already in the same coord system :)
        if (descendant == this) {
            return;
        }

        ViewParent theParent = descendant.mParent;

        // search and offset up to the parent
        while ((theParent != null)
                && (theParent instanceof View)
                && (theParent != this)) {

            if (offsetFromChildToParent) {
                rect.offset(descendant.mLeft - descendant.mScrollX,
                        descendant.mTop - descendant.mScrollY);
                if (clipToBounds) {
                    View p = (View) theParent;
                    boolean intersected = rect.intersect(0, 0, p.mRight - p.mLeft,
                            p.mBottom - p.mTop);
                    if (!intersected) {
                        rect.setEmpty();
                    }
                }
            } else {
                if (clipToBounds) {
                    View p = (View) theParent;
                    boolean intersected = rect.intersect(0, 0, p.mRight - p.mLeft,
                            p.mBottom - p.mTop);
                    if (!intersected) {
                        rect.setEmpty();
                    }
                }
                rect.offset(descendant.mScrollX - descendant.mLeft,
                        descendant.mScrollY - descendant.mTop);
            }

            descendant = (View) theParent;
            theParent = descendant.mParent;
        }

        // now that we are up to this view, need to offset one more time
        // to get into our coordinate space
        if (theParent == this) {
            if (offsetFromChildToParent) {
                rect.offset(descendant.mLeft - descendant.mScrollX,
                        descendant.mTop - descendant.mScrollY);
            } else {
                rect.offset(descendant.mScrollX - descendant.mLeft,
                        descendant.mScrollY - descendant.mTop);
            }
        } else {
            throw new IllegalArgumentException("parameter must be a descendant of this view");
        }
    }

In the method, it walks through the view hierarchy from the descendant with the while loop, until it reaches the GroupView instance. But when it comes the Modal component, the loop quit with theParent is an instance of ViewRootImpl, and the condition as last of the method fails, so the method throws the exception.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

0reactions
satya164commented, May 25, 2016

Closing this since it has been fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AccessibilityService | Android Developers
All accessibility services are notified of all events they have requested, regardless of their ... which is used to answer/hang up calls and...
Read more >
Accessibility Service crashes and cannot restart - Stack Overflow
1. If I try to deinstall the app and recompile again, · 2. If I deinstall the app, reboot the phone, and recompile...
Read more >
Service Introduction-Crash - Huawei Developer Platform
The Crash service provides real-time reports, revealing any crash of your app on any device. In addition, the Crash service can intelligently aggregate ......
Read more >
AccessibilityService.java - android Git repositories
<p>For more information about creating AccessibilityServices, read the ... All accessibility services are notified of all events they have requested, ...
Read more >
Accessibility - React Native
Both Android and iOS provide APIs for integrating apps with assistive technologies like the bundled screen readers VoiceOver (iOS) and TalkBack ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found