This patch works around Android's limitations on reflection. With it embedded
platform views that use virtual node hierarchy trees should be accessible on all
Android versions to date.
The workarounds in this PR are brittle. Ideally the methods would be made public
in Android instead so we wouldn't need to employ tactics like these to work
around the missing methods.
`AccessibilityNodeInfo#getChildId` is blocked from any type of reflection
access, but the underlying private member that the getter accesses,
`mChildNodeIds`, can still be reflected on. On Android versions where we can't
access the getter, this patch falls back on reflectively accessing the field
instead. Unfortunately this field is a
[`LongArray`](https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/util/LongArray.java),
a utility data class private to Android. So in this case we're reflecting to
both access the member and actually read data from it, since we need to use
reflection to call `LongArray.get(index)`.
`AccessibilityNodeInfo#getParent()` doesn't have any lucky available underlying
members. However, `AccessibilityNodeInfo` itself is `Parcelable`, and
`mParentNodeId` is one of the pieces of data that's written to a parcel via
`AccessibilityNodeInfo#writeToParcel`. So the fallback for that is to write the
node to a parcel and then read the parcel for the ID in question. This will
break if the implementation details of `AccessibilityNodeInfo#writeToParcel`
ever change. The details have already changed enough in the past to require two
sets of logic for reading from the parcel.
Since this class implements equals() and hashCode() it should either be
final or handle subclasses in equals(); given this is unlikely to be
subclassed, making it final is the simpler option.
The AccessibilityViewEmbedder was not delegating a11y events coming virtual nodes(of the embedded view) that were not previously traversed by the a11y framework.
It turns out the a11y framework might leave parts of the tree untraversed in some circumstances, changed the behavior to create an originId<-->flutterId mapping on the fly when an event is delegated from a not previously traversed node.
Fixesflutter/flutter#30010.
Delegate a11y events and action to/from embedded Android platfrom views.
This handles delegation of:
* AccessibilityNodeProvider#performAction
* ViewGroup#requestSendAccessibilityEvent
* View#onHoverEvent
Additionally updates the currently input accessibility focused node state that is
tracked by the a11y bridge when an embedded view's node is focused.
This PR mirrors virtual a11y tree of embedded platform views in the Flutter
a11y tree.
Non virtual hierarchies are not currently supported.
Only works on Android versions earlier than Android P as it relies on
reflection access to hidden system APIs which cannot be done starting
Android P.
A11y is not yet working as we also need to delegate a11y events from the
platform view to the FlutterView. This will be done in a following PR to
keep the change size a little saner.