OSDN Git Service

AccessibilityNodeInfo incorrectly cloned.
authorSvetoslav Ganov <svetoslavganov@google.com>
Mon, 9 Sep 2013 20:36:43 +0000 (13:36 -0700)
committerThe Android Automerger <android-build@android.com>
Mon, 9 Sep 2013 23:01:12 +0000 (16:01 -0700)
The code that creates a clone of an AccessibilityNodeInfo was not cloning
the extension objects (CollectionInfo, CollectionItemInfo, and RangeInfo)
and as a result if the original accessibility node info is recycled the
extension objects of the clone are also recycled and now if one tries to
recycle the clone gets an exception that the extension objects are already
recycled. Fun!

bug:10642952

Change-Id: I84192466bff0e865de04b79079e6ceecdffb37a6

core/java/android/view/accessibility/AccessibilityNodeInfo.java

index ba63421..c61516b 100644 (file)
@@ -2279,9 +2279,12 @@ public class AccessibilityNodeInfo implements Parcelable {
         if (other.mExtras != null && !other.mExtras.isEmpty()) {
             getExtras().putAll(other.mExtras);
         }
-        mRangeInfo = other.mRangeInfo;
-        mCollectionInfo = other.mCollectionInfo;
-        mCollectionItemInfo = other.mCollectionItemInfo;
+        mRangeInfo = (other.mRangeInfo != null)
+                ? RangeInfo.obtain(other.mRangeInfo) : null;
+        mCollectionInfo = (other.mCollectionInfo != null)
+                ? CollectionInfo.obtain(other.mCollectionInfo) : null;
+        mCollectionItemInfo =  (other.mCollectionItemInfo != null)
+                ? CollectionItemInfo.obtain(other.mCollectionItemInfo) : null;
     }
 
     /**
@@ -2602,6 +2605,17 @@ public class AccessibilityNodeInfo implements Parcelable {
         private float mCurrent;
 
         /**
+         * Obtains a pooled instance that is a clone of another one.
+         *
+         * @param other The instance to clone.
+         *
+         * @hide
+         */
+        public static RangeInfo obtain(RangeInfo other) {
+            return obtain(other.mType, other.mMin, other.mMax, other.mCurrent);
+        }
+
+        /**
          * Obtains a pooled instance.
          *
          * @param type The type of the range.
@@ -2708,6 +2722,18 @@ public class AccessibilityNodeInfo implements Parcelable {
         private boolean mHierarchical;
 
         /**
+         * Obtains a pooled instance that is a clone of another one.
+         *
+         * @param other The instance to clone.
+         *
+         * @hide
+         */
+        public static CollectionInfo obtain(CollectionInfo other) {
+            return CollectionInfo.obtain(other.mRowCount, other.mColumnCount,
+                    other.mHierarchical);
+        }
+
+        /**
          * Obtains a pooled instance.
          *
          * @param rowCount The number of rows.
@@ -2796,6 +2822,18 @@ public class AccessibilityNodeInfo implements Parcelable {
                 new SynchronizedPool<CollectionItemInfo>(MAX_POOL_SIZE);
 
         /**
+         * Obtains a pooled instance that is a clone of another one.
+         *
+         * @param other The instance to clone.
+         *
+         * @hide
+         */
+        public static CollectionItemInfo obtain(CollectionItemInfo other) {
+            return CollectionItemInfo.obtain(other.mRowIndex, other.mRowSpan,
+                    other.mColumnIndex, other.mColumnSpan, other.mHeading);
+        }
+
+        /**
          * Obtains a pooled instance.
          *
          * @param rowIndex The row index at which the item is located.