Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4cbd3ac7 authored by Alan Viverette's avatar Alan Viverette
Browse files

Save and restore accessibility focus using decor view

Also avoids potential NPE when decor view is null or has no view root.

Bug: 23316836
Change-Id: Iccf75ddc0e4c769a234f5b80bc0707631c2719a2
parent d920ac6e
Loading
Loading
Loading
Loading
+18 −14
Original line number Diff line number Diff line
@@ -2028,7 +2028,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
        }

        // Save the accessibility focused view ID.
        final ViewRootImpl viewRootImpl = mContentParent.getViewRootImpl();
        if (mDecor != null) {
            final ViewRootImpl viewRootImpl = mDecor.getViewRootImpl();
            if (viewRootImpl != null) {
                final View accessFocusHost = viewRootImpl.getAccessibilityFocusedHost();
                if (accessFocusHost != null && accessFocusHost.getId() != View.NO_ID) {
                    outState.putInt(ACCESSIBILITY_FOCUSED_ID_TAG, accessFocusHost.getId());
@@ -2042,6 +2044,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
                        outState.putInt(ACCESSIBILITY_FOCUSED_VIRTUAL_ID_TAG, virtualNodeId);
                    }
                }
            }
        }

        // save the panels
        SparseArray<Parcelable> panelStates = new SparseArray<Parcelable>();
@@ -2112,8 +2116,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
    }

    private void tryRestoreAccessibilityFocus(int hostViewId, int virtualViewId) {
        if (hostViewId != View.NO_ID) {
            final View needsAccessFocus = mContentParent.findViewById(hostViewId);
        if (hostViewId != View.NO_ID && mDecor != null) {
            final View needsAccessFocus = mDecor.findViewById(hostViewId);
            if (needsAccessFocus != null) {
                if (!tryFocusingVirtualView(needsAccessFocus, virtualViewId)
                        && !needsAccessFocus.requestAccessibilityFocus()) {