OSDN Git Service

Fix PersistableBundle handling in Parcel.writeValue
authorSamuel Tan <samueltan@google.com>
Sat, 12 Dec 2015 00:50:58 +0000 (16:50 -0800)
committerSamuel Tan <samueltan@google.com>
Tue, 15 Dec 2015 23:22:52 +0000 (15:22 -0800)
Previously, in Parcel.writeValue, PersistableBundle objects
would be handled as Parcelable types, since we check for
the Parcelable type before the PersistableBundle type (and
PersistableBundle implements the Parcelable interface).

Fix this by moving the PersistableBundle type "if" condition
above the Parcealble type "if" condition. Also, add a comment
that explicitly states this nuance, in order to prevent future
regressions.

BUG: 25815410
Change-Id: Ia86aa5fc39423422342df0609a0d37e7f38d7ddd

core/java/android/os/Parcel.java

index 9b68f90..2902021 100644 (file)
@@ -1370,7 +1370,13 @@ public final class Parcel {
             // Must be before Parcelable
             writeInt(VAL_BUNDLE);
             writeBundle((Bundle) v);
+        } else if (v instanceof PersistableBundle) {
+            writeInt(VAL_PERSISTABLEBUNDLE);
+            writePersistableBundle((PersistableBundle) v);
         } else if (v instanceof Parcelable) {
+            // IMPOTANT: cases for classes that implement Parcelable must
+            // come before the Parcelable case, so that their specific VAL_*
+            // types will be written.
             writeInt(VAL_PARCELABLE);
             writeParcelable((Parcelable) v, 0);
         } else if (v instanceof Short) {
@@ -1426,9 +1432,6 @@ public final class Parcel {
         } else if (v instanceof Byte) {
             writeInt(VAL_BYTE);
             writeInt((Byte) v);
-        } else if (v instanceof PersistableBundle) {
-            writeInt(VAL_PERSISTABLEBUNDLE);
-            writePersistableBundle((PersistableBundle) v);
         } else if (v instanceof Size) {
             writeInt(VAL_SIZE);
             writeSize((Size) v);