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

Commit 7e56edb8 authored by Jeongik Cha's avatar Jeongik Cha Committed by Automerger Merge Worker
Browse files

Merge "Expose 'ParcelableHolder' as SystemApi" am: 135efb0b am: 5e1cacaa...

Merge "Expose 'ParcelableHolder' as SystemApi" am: 135efb0b am: 5e1cacaa am: d5bae241 am: 0522a33e

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

Change-Id: Ic28ef16a1e1d08db0f2ea6c735295d748b3f8a89
parents df6efd50 0522a33e
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -157,8 +157,6 @@ package android.os {

  public interface Parcelable {
    method public default int getStability();
    field public static final int PARCELABLE_STABILITY_LOCAL = 0; // 0x0
    field public static final int PARCELABLE_STABILITY_VINTF = 1; // 0x1
  }

  public class StatsFrameworkInitializer {
+16 −0
Original line number Diff line number Diff line
@@ -8810,6 +8810,22 @@ package android.os {
    method public boolean hasSingleFileDescriptor();
  }
  public interface Parcelable {
    field public static final int PARCELABLE_STABILITY_LOCAL = 0; // 0x0
    field public static final int PARCELABLE_STABILITY_VINTF = 1; // 0x1
  }
  public final class ParcelableHolder implements android.os.Parcelable {
    ctor public ParcelableHolder(int);
    method public int describeContents();
    method @Nullable public <T extends android.os.Parcelable> T getParcelable(@NonNull Class<T>);
    method public int getStability();
    method public void readFromParcel(@NonNull android.os.Parcel);
    method public boolean setParcelable(@Nullable android.os.Parcelable);
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.os.ParcelableHolder> CREATOR;
  }
  public final class PowerManager {
    method @RequiresPermission(allOf={android.Manifest.permission.READ_DREAM_STATE, android.Manifest.permission.WRITE_DREAM_STATE}) public void dream(long);
    method @RequiresPermission(android.Manifest.permission.DEVICE_POWER) public boolean forceSuspend();
+2 −2
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ public interface Parcelable {
     * @see ParcelableHolder
     * @hide
     */
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    @SystemApi(client = SystemApi.Client.PRIVILEGED_APPS)
    public static final int PARCELABLE_STABILITY_LOCAL = 0x0000;
    /**
     * Something that is meant to be used between system and vendor.
@@ -128,7 +128,7 @@ public interface Parcelable {
     * @see ParcelableHolder
     * @hide
     */
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    @SystemApi(client = SystemApi.Client.PRIVILEGED_APPS)
    public static final int PARCELABLE_STABILITY_VINTF = 0x0001;

    /**
+48 −6
Original line number Diff line number Diff line
@@ -18,12 +18,54 @@ package android.os;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.util.MathUtils;

/**
 * Parcelable containing the other Parcelable object.
 * ParcelableHolder is a Parcelable which can contain another Parcelable.
 * The main use case of ParcelableHolder is to make a Parcelable extensible.
 * For example, an AOSP-defined Parcelable <code>AospDefinedParcelable</code>
 * is expected to be extended by device implementers for their value-add features.
 * Previously without ParcelableHolder, the device implementers had to
 * directly modify the Parcelable to add more fields:
 * <pre> {@code
 * parcelable AospDefinedParcelable {
 *   int a;
 *   String b;
 *   String x; // added by a device implementer
 *   int[] y; // added by a device implementer
 * }}</pre>
 *
 * This practice is very error-prone because the fields added by the device implementer
 * might have a conflict when the Parcelable is revisioned in the next releases of Android.
 *
 * Using ParcelableHolder, one can define an extension point in a Parcelable.
 * <pre> {@code
 * parcelable AospDefinedParcelable {
 *   int a;
 *   String b;
 *   ParcelableHolder extension;
 * }}</pre>
 * Then the device implementers can define their own Parcelable for their extension.
 *
 * <pre> {@code
 * parcelable OemDefinedParcelable {
 *   String x;
 *   int[] y;
 * }}</pre>
 * Finally, the new Parcelable can be attached to the original Parcelable via
 * the ParcelableHolder field.
 *
 * <pre> {@code
 * AospDefinedParcelable ap = ...;
 * OemDefinedParcelable op = new OemDefinedParcelable();
 * op.x = ...;
 * op.y = ...;
 * ap.extension.setParcelable(op);}</pre>
 *
 * @hide
 */
@SystemApi
public final class ParcelableHolder implements Parcelable {
    /**
     * This is set by {@link #setParcelable}.
@@ -80,7 +122,7 @@ public final class ParcelableHolder implements Parcelable {
     * Write a parcelable into ParcelableHolder, the previous parcelable will be removed.
     * @return {@code false} if the parcelable's stability is more unstable ParcelableHolder.
     */
    public synchronized boolean setParcelable(@Nullable Parcelable p) {
    public boolean setParcelable(@Nullable Parcelable p) {
        // a ParcelableHolder can only hold things at its stability or higher
        if (p != null && this.getStability() > p.getStability()) {
            return false;
@@ -99,7 +141,7 @@ public final class ParcelableHolder implements Parcelable {
     *         the type written by (@link #setParcelable}.
     */
    @Nullable
    public synchronized <T extends Parcelable> T getParcelable(@NonNull Class<T> clazz) {
    public <T extends Parcelable> T getParcelable(@NonNull Class<T> clazz) {
        if (mParcel == null) {
            if (!clazz.isInstance(mParcelable)) {
                return null;
@@ -123,7 +165,7 @@ public final class ParcelableHolder implements Parcelable {
    /**
     * Read ParcelableHolder from a parcel.
     */
    public synchronized void readFromParcel(@NonNull Parcel parcel) {
    public void readFromParcel(@NonNull Parcel parcel) {
        this.mStability = parcel.readInt();

        mParcelable = null;
@@ -145,7 +187,7 @@ public final class ParcelableHolder implements Parcelable {
    }

    @Override
    public synchronized void writeToParcel(@NonNull Parcel parcel, int flags) {
    public void writeToParcel(@NonNull Parcel parcel, int flags) {
        parcel.writeInt(this.mStability);

        if (mParcel != null) {
@@ -166,7 +208,7 @@ public final class ParcelableHolder implements Parcelable {
    }

    @Override
    public synchronized int describeContents() {
    public int describeContents() {
        if (mParcel != null) {
            return mParcel.hasFileDescriptors() ? Parcelable.CONTENTS_FILE_DESCRIPTOR : 0;
        }
+0 −2
Original line number Diff line number Diff line
@@ -107,8 +107,6 @@ package android.os {

  public interface Parcelable {
    method public default int getStability();
    field public static final int PARCELABLE_STABILITY_LOCAL = 0; // 0x0
    field public static final int PARCELABLE_STABILITY_VINTF = 1; // 0x1
  }

  public class StatsServiceManager {
Loading