Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 82679a69 authored by Steven Moreland's avatar Steven Moreland
Browse files

android.os.Parcelable: isStable->getStability

In preparation for APEX stability, make this API support arbitrary
stability levels.

Bug: 139325195
Test: AIDL's run_integration_test.py
Change-Id: I0c1b50f228683717db2978aa909befa46de5302c
parent 83cbf59a
Loading
Loading
Loading
Loading
+31 −2
Original line number Diff line number Diff line
@@ -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;
    }

    /**
+10 −9
Original line number Diff line number Diff line
@@ -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());