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

Commit 1aa9da42 authored by Qasid Ahmad Sadiq's avatar Qasid Ahmad Sadiq
Browse files

Make mIdsToViews thread safe.

View calls like "attachedToWindow" and "detachedToWindow" can be called
off of the main thread, on "android.anim" this happens in the system
process for application splash screens.
Let's wrap it with a synchronized block.

Fix: 124110476
Test: The crash is a race condition, so the best I can do is make sure
it generally doesn't crash anything by trying out both normal and
virtual hierarchies in Talkback.

Change-Id: I19f972a97b5ac80917f8dd77ac79bf7e3d5e826c
parent 763ca762
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -45,16 +45,20 @@ public final class AccessibilityNodeIdManager {
     * @param id The accessibilityViewId of the view.
     */
    public void registerViewWithId(View view, int id) {
        synchronized (mIdsToViews) {
            mIdsToViews.append(id, view);
        }
    }

    /**
     * Unregister view, accessibility won't keep track of this view after this call.
     * @param id The id returned from registerView when the view as first associated.
     */
    public void unregisterViewWithId(int id) {
        synchronized (mIdsToViews) {
            mIdsToViews.remove(id);
        }
    }

    /**
     * Accessibility uses this to find the view in the hierarchy.
@@ -62,7 +66,10 @@ public final class AccessibilityNodeIdManager {
     * @return The view.
     */
    public View findView(int id) {
        final View view = mIdsToViews.get(id);
        View view = null;
        synchronized (mIdsToViews) {
            view = mIdsToViews.get(id);
        }
        return view != null && view.includeForAccessibility() ? view : null;
    }
}