diff options
| -rw-r--r-- | core/java/android/os/Parcelable.java | 33 | ||||
| -rw-r--r-- | core/java/android/os/ParcelableHolder.java | 19 |
2 files changed, 41 insertions, 11 deletions
diff --git a/core/java/android/os/Parcelable.java b/core/java/android/os/Parcelable.java index 9b360edb7238..bedbba04255e 100644 --- a/core/java/android/os/Parcelable.java +++ b/core/java/android/os/Parcelable.java @@ -99,6 +99,35 @@ public interface Parcelable { @Retention(RetentionPolicy.SOURCE) public @interface ContentsFlags {} + /** @hide */ + @IntDef(flag = true, prefix = { "PARCELABLE_STABILITY_" }, value = { + PARCELABLE_STABILITY_LOCAL, + PARCELABLE_STABILITY_VINTF, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface Stability {} + + /** + * Something that is not meant to cross compilation boundaries. + * + * Note: unlike binder/Stability.h which uses bitsets to detect stability, + * since we don't currently have a notion of different local locations, + * higher stability levels are formed at higher levels. + * + * For instance, contained entirely within system partitions. + * @see #getStability() + * @see ParcelableHolder + * @hide + */ + public static final int PARCELABLE_STABILITY_LOCAL = 0x0000; + /** + * Something that is meant to be used between system and vendor. + * @see #getStability() + * @see ParcelableHolder + * @hide + */ + public static final int PARCELABLE_STABILITY_VINTF = 0x0001; + /** * Descriptor bit used with {@link #describeContents()}: indicates that * the Parcelable object's flattened representation includes a file descriptor. @@ -129,8 +158,8 @@ public interface Parcelable { * @return true if this parcelable is stable. * @hide */ - default boolean isStable() { - return false; + default @Stability int getStability() { + return PARCELABLE_STABILITY_LOCAL; } /** diff --git a/core/java/android/os/ParcelableHolder.java b/core/java/android/os/ParcelableHolder.java index c37a2ff1112c..181f94b39841 100644 --- a/core/java/android/os/ParcelableHolder.java +++ b/core/java/android/os/ParcelableHolder.java @@ -37,10 +37,10 @@ public final class ParcelableHolder implements Parcelable { * if {@link ParcelableHolder} contains value, otherwise, both are null. */ private Parcel mParcel; - private boolean mIsStable = false; + private @Parcelable.Stability int mStability = Parcelable.PARCELABLE_STABILITY_LOCAL; - public ParcelableHolder(boolean isStable) { - mIsStable = isStable; + public ParcelableHolder(@Parcelable.Stability int stability) { + mStability = stability; } private ParcelableHolder() { @@ -50,11 +50,11 @@ public final class ParcelableHolder implements Parcelable { /** * {@link ParcelableHolder}'s stability is determined by the parcelable * which contains this ParcelableHolder. - * For more detail refer to {@link Parcelable#isStable}. + * For more detail refer to {@link Parcelable#getStability}. */ @Override - public boolean isStable() { - return mIsStable; + public @Parcelable.Stability int getStability() { + return mStability; } @NonNull @@ -81,7 +81,8 @@ public final class ParcelableHolder implements Parcelable { * @return {@code false} if the parcelable's stability is more unstable ParcelableHolder. */ public synchronized boolean setParcelable(@Nullable Parcelable p) { - if (p != null && this.isStable() && !p.isStable()) { + // a ParcelableHolder can only hold things at its stability or higher + if (p != null && this.getStability() > p.getStability()) { return false; } mParcelable = p; @@ -123,7 +124,7 @@ public final class ParcelableHolder implements Parcelable { * Read ParcelableHolder from a parcel. */ public synchronized void readFromParcel(@NonNull Parcel parcel) { - this.mIsStable = parcel.readBoolean(); + this.mStability = parcel.readInt(); mParcelable = null; @@ -145,7 +146,7 @@ public final class ParcelableHolder implements Parcelable { @Override public synchronized void writeToParcel(@NonNull Parcel parcel, int flags) { - parcel.writeBoolean(this.mIsStable); + parcel.writeInt(this.mStability); if (mParcel != null) { parcel.writeInt(mParcel.dataSize()); |