Merge "android.os.Parcelable: isStable->getStability" am: d1568567ec am: da7e355785
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1371499 Change-Id: I0f62379a8de4d7b1622ed0667b785d8a74a11ccb
This commit is contained in:
@@ -99,6 +99,35 @@ public interface Parcelable {
|
|||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
public @interface ContentsFlags {}
|
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
|
* Descriptor bit used with {@link #describeContents()}: indicates that
|
||||||
* the Parcelable object's flattened representation includes a file descriptor.
|
* the Parcelable object's flattened representation includes a file descriptor.
|
||||||
@@ -129,8 +158,8 @@ public interface Parcelable {
|
|||||||
* @return true if this parcelable is stable.
|
* @return true if this parcelable is stable.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
default boolean isStable() {
|
default @Stability int getStability() {
|
||||||
return false;
|
return PARCELABLE_STABILITY_LOCAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ public final class ParcelableHolder implements Parcelable {
|
|||||||
* if {@link ParcelableHolder} contains value, otherwise, both are null.
|
* if {@link ParcelableHolder} contains value, otherwise, both are null.
|
||||||
*/
|
*/
|
||||||
private Parcel mParcel;
|
private Parcel mParcel;
|
||||||
private boolean mIsStable = false;
|
private @Parcelable.Stability int mStability = Parcelable.PARCELABLE_STABILITY_LOCAL;
|
||||||
|
|
||||||
public ParcelableHolder(boolean isStable) {
|
public ParcelableHolder(@Parcelable.Stability int stability) {
|
||||||
mIsStable = isStable;
|
mStability = stability;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ParcelableHolder() {
|
private ParcelableHolder() {
|
||||||
@@ -50,11 +50,11 @@ public final class ParcelableHolder implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* {@link ParcelableHolder}'s stability is determined by the parcelable
|
* {@link ParcelableHolder}'s stability is determined by the parcelable
|
||||||
* which contains this ParcelableHolder.
|
* which contains this ParcelableHolder.
|
||||||
* For more detail refer to {@link Parcelable#isStable}.
|
* For more detail refer to {@link Parcelable#getStability}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isStable() {
|
public @Parcelable.Stability int getStability() {
|
||||||
return mIsStable;
|
return mStability;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -81,7 +81,8 @@ public final class ParcelableHolder implements Parcelable {
|
|||||||
* @return {@code false} if the parcelable's stability is more unstable ParcelableHolder.
|
* @return {@code false} if the parcelable's stability is more unstable ParcelableHolder.
|
||||||
*/
|
*/
|
||||||
public synchronized boolean setParcelable(@Nullable Parcelable p) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
mParcelable = p;
|
mParcelable = p;
|
||||||
@@ -123,7 +124,7 @@ public final class ParcelableHolder implements Parcelable {
|
|||||||
* Read ParcelableHolder from a parcel.
|
* Read ParcelableHolder from a parcel.
|
||||||
*/
|
*/
|
||||||
public synchronized void readFromParcel(@NonNull Parcel parcel) {
|
public synchronized void readFromParcel(@NonNull Parcel parcel) {
|
||||||
this.mIsStable = parcel.readBoolean();
|
this.mStability = parcel.readInt();
|
||||||
|
|
||||||
mParcelable = null;
|
mParcelable = null;
|
||||||
|
|
||||||
@@ -145,7 +146,7 @@ public final class ParcelableHolder implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void writeToParcel(@NonNull Parcel parcel, int flags) {
|
public synchronized void writeToParcel(@NonNull Parcel parcel, int flags) {
|
||||||
parcel.writeBoolean(this.mIsStable);
|
parcel.writeInt(this.mStability);
|
||||||
|
|
||||||
if (mParcel != null) {
|
if (mParcel != null) {
|
||||||
parcel.writeInt(mParcel.dataSize());
|
parcel.writeInt(mParcel.dataSize());
|
||||||
|
|||||||
Reference in New Issue
Block a user