diff options
| author | Alan Viverette <alanv@google.com> | 2015-05-19 11:32:08 -0700 |
|---|---|---|
| committer | Alan Viverette <alanv@google.com> | 2015-05-19 11:32:08 -0700 |
| commit | 25acc7e78c5d981da6565399df4fad7bced4de76 (patch) | |
| tree | f3d72758180b95e19d51f7a6cc8620e7f2076ee2 /core/java/android/view/ViewRootImpl.java | |
| parent | 0c4729a1e468e2b0783a4234e39677d8078473b3 (diff) | |
| download | frameworks_base-25acc7e78c5d981da6565399df4fad7bced4de76.zip frameworks_base-25acc7e78c5d981da6565399df4fad7bced4de76.tar.gz frameworks_base-25acc7e78c5d981da6565399df4fad7bced4de76.tar.bz2 | |
Handle error states when refreshing accessibility node
Bug: 21281869
Change-Id: Idce90f5e23b102b9c66f288906eedb5b6a5b098d
Diffstat (limited to 'core/java/android/view/ViewRootImpl.java')
| -rw-r--r-- | core/java/android/view/ViewRootImpl.java | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index b7d902c..b3e1a18 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -66,6 +66,7 @@ import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener; import android.view.accessibility.AccessibilityManager.HighTextContrastChangeListener; import android.view.accessibility.AccessibilityNodeInfo; +import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; import android.view.accessibility.AccessibilityNodeProvider; import android.view.accessibility.IAccessibilityInteractionConnection; import android.view.accessibility.IAccessibilityInteractionConnectionCallback; @@ -6349,16 +6350,18 @@ public final class ViewRootImpl implements ViewParent, * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} */ private void handleWindowContentChangedEvent(AccessibilityEvent event) { - // No virtual view focused, nothing to do here. - if (mAccessibilityFocusedHost == null || mAccessibilityFocusedVirtualView == null) { + final View focusedHost = mAccessibilityFocusedHost; + if (focusedHost == null || mAccessibilityFocusedVirtualView == null) { + // No virtual view focused, nothing to do here. return; } - // If we have a node but no provider, abort. - final AccessibilityNodeProvider provider = - mAccessibilityFocusedHost.getAccessibilityNodeProvider(); + final AccessibilityNodeProvider provider = focusedHost.getAccessibilityNodeProvider(); if (provider == null) { - // TODO: Should we clear the focused virtual view? + // Error state: virtual view with no provider. Clear focus. + mAccessibilityFocusedHost = null; + mAccessibilityFocusedVirtualView = null; + focusedHost.clearAccessibilityFocusNoCallbacks(); return; } @@ -6405,10 +6408,23 @@ public final class ViewRootImpl implements ViewParent, final Rect oldBounds = mTempRect; mAccessibilityFocusedVirtualView.getBoundsInScreen(oldBounds); mAccessibilityFocusedVirtualView = provider.createAccessibilityNodeInfo(focusedChildId); - final Rect newBounds = mAccessibilityFocusedVirtualView.getBoundsInScreen(); - if (!oldBounds.equals(newBounds)) { - oldBounds.union(newBounds); + if (mAccessibilityFocusedVirtualView == null) { + // Error state: The node no longer exists. Clear focus. + mAccessibilityFocusedHost = null; + focusedHost.clearAccessibilityFocusNoCallbacks(); + + // This will probably fail, but try to keep the provider's internal + // state consistent by clearing focus. + provider.performAction(focusedChildId, + AccessibilityAction.ACTION_CLEAR_ACCESSIBILITY_FOCUS.getId(), null); invalidateRectOnScreen(oldBounds); + } else { + // The node was refreshed, invalidate bounds if necessary. + final Rect newBounds = mAccessibilityFocusedVirtualView.getBoundsInScreen(); + if (!oldBounds.equals(newBounds)) { + oldBounds.union(newBounds); + invalidateRectOnScreen(oldBounds); + } } } |
