Merge "android.os.Parcelable: isStable->getStability" am: d1568567ec am: da7e355785 am: c9a09ffd92

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1371499

Change-Id: I2fcdfc48e2516d498a04c17dcf99c0c95d8bd153
This commit is contained in:
Steven Moreland
2020-07-24 18:04:37 +00:00
committed by Automerger Merge Worker
2 changed files with 41 additions and 11 deletions

View File

@@ -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;
}
/**

View File

@@ -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());