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

Commit afd5fab3 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

AccessibilityNodeInfos node properly cached.

1. AccessibilityNodeInfo were not cloned when cached
   and obtained from the cache. This was causing a
   problem when the client calls #recycle() as he
   should since this results in wiping the data of
   the cached node info.

bug:6026952

Change-Id: I5807b09d95ef6f310327192ff91f036adf337e33
parent 42d840b9
Loading
Loading
Loading
Loading
+21 −13
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package android.view.accessibility;

import android.os.Process;
import android.util.Log;
import android.util.LongSparseArray;

@@ -81,14 +80,16 @@ public class AccessibilityNodeInfoCache {
    public AccessibilityNodeInfo get(long accessibilityNodeId) {
        if (ENABLED) {
            synchronized(mLock) {
                if (DEBUG) {
                AccessibilityNodeInfo info = mCacheImpl.get(accessibilityNodeId);
                    Log.i(LOG_TAG, "Process: " + Process.myPid() +
                            " get(" + accessibilityNodeId + ") = " + info);
                    return info;
                } else {
                    return mCacheImpl.get(accessibilityNodeId);
                if (info != null) {
                    // Return a copy since the client calls to AccessibilityNodeInfo#recycle()
                    // will wipe the data of the cached info.
                    info = AccessibilityNodeInfo.obtain(info);
                }
                if (DEBUG) {
                    Log.i(LOG_TAG, "get(" + accessibilityNodeId + ") = " + info);
                }
                return info;
            }
        } else {
            return null;
@@ -105,10 +106,12 @@ public class AccessibilityNodeInfoCache {
        if (ENABLED) {
            synchronized(mLock) {
                if (DEBUG) {
                    Log.i(LOG_TAG, "Process: " + Process.myPid()
                            + " put(" + accessibilityNodeId + ", " + info + ")");
                    Log.i(LOG_TAG, "put(" + accessibilityNodeId + ", " + info + ")");
                }
                mCacheImpl.put(accessibilityNodeId, info);
                // Cache a copy since the client calls to AccessibilityNodeInfo#recycle()
                // will wipe the data of the cached info.
                AccessibilityNodeInfo clone = AccessibilityNodeInfo.obtain(info);
                mCacheImpl.put(accessibilityNodeId, clone);
            }
        }
    }
@@ -138,8 +141,7 @@ public class AccessibilityNodeInfoCache {
        if (ENABLED) {
            synchronized(mLock) {
                if (DEBUG) {
                    Log.i(LOG_TAG,  "Process: " + Process.myPid()
                            + " remove(" + accessibilityNodeId + ")");
                    Log.i(LOG_TAG, "remove(" + accessibilityNodeId + ")");
                }
                mCacheImpl.remove(accessibilityNodeId);
            }
@@ -153,7 +155,13 @@ public class AccessibilityNodeInfoCache {
        if (ENABLED) {
            synchronized(mLock) {
                if (DEBUG) {
                    Log.i(LOG_TAG,  "Process: " + Process.myPid() + "clear()");
                    Log.i(LOG_TAG, "clear()");
                }
                // Recycle the nodes before clearing the cache.
                final int nodeCount = mCacheImpl.size();
                for (int i = 0; i < nodeCount; i++) {
                    AccessibilityNodeInfo info = mCacheImpl.valueAt(i);
                    info.recycle();
                }
                mCacheImpl.clear();
            }