diff --git a/core/api/current.txt b/core/api/current.txt
index 6a2b9c12ec102..641f71be8e404 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -31427,6 +31427,8 @@ package android.os {
method @Nullable public double[] createDoubleArray();
method @Nullable public float[] createFloatArray();
method @Nullable public int[] createIntArray();
+ method @Nullable public T[] createInterfaceArray(@NonNull java.util.function.IntFunction, @NonNull java.util.function.Function);
+ method @Nullable public java.util.ArrayList createInterfaceArrayList(@NonNull java.util.function.Function);
method @Nullable public long[] createLongArray();
method @Nullable public String[] createStringArray();
method @Nullable public java.util.ArrayList createStringArrayList();
@@ -31467,6 +31469,8 @@ package android.os {
method @Nullable public java.util.HashMap readHashMap(@Nullable ClassLoader);
method public int readInt();
method public void readIntArray(@NonNull int[]);
+ method public void readInterfaceArray(@NonNull T[], @NonNull java.util.function.Function);
+ method public void readInterfaceList(@NonNull java.util.List, @NonNull java.util.function.Function);
method public void readList(@NonNull java.util.List, @Nullable ClassLoader);
method public void readList(@NonNull java.util.List super T>, @Nullable ClassLoader, @NonNull Class);
method public long readLong();
@@ -31519,6 +31523,8 @@ package android.os {
method public void writeFloatArray(@Nullable float[]);
method public void writeInt(int);
method public void writeIntArray(@Nullable int[]);
+ method public void writeInterfaceArray(@Nullable T[]);
+ method public void writeInterfaceList(@Nullable java.util.List);
method public void writeInterfaceToken(@NonNull String);
method public void writeList(@Nullable java.util.List);
method public void writeLong(long);
diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java
index d1e6716918975..5a2f27d838936 100644
--- a/core/java/android/os/Parcel.java
+++ b/core/java/android/os/Parcel.java
@@ -62,6 +62,8 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.function.Function;
+import java.util.function.IntFunction;
import java.util.function.Supplier;
/**
@@ -178,8 +180,12 @@ import java.util.function.Supplier;
* {@link #writeStrongInterface(IInterface)}, {@link #readStrongBinder()},
* {@link #writeBinderArray(IBinder[])}, {@link #readBinderArray(IBinder[])},
* {@link #createBinderArray()},
+ * {@link #writeInterfaceArray(T[])}, {@link #readInterfaceArray(T[], Function)},
+ * {@link #createInterfaceArray(IntFunction, Function)},
* {@link #writeBinderList(List)}, {@link #readBinderList(List)},
- * {@link #createBinderArrayList()}.
+ * {@link #createBinderArrayList()},
+ * {@link #writeInterfaceList(List)}, {@link #readInterfaceList(List, Function)},
+ * {@link #createInterfaceArrayList(Function)}.
*
* FileDescriptor objects, representing raw Linux file descriptor identifiers,
* can be written and {@link ParcelFileDescriptor} objects returned to operate
@@ -1729,6 +1735,30 @@ public final class Parcel {
}
}
+ /**
+ * Flatten a homogeneous array containing an IInterface type into the parcel,
+ * at the current dataPosition() and growing dataCapacity() if needed. The
+ * type of the objects in the array must be one that implements IInterface.
+ *
+ * @param val The array of objects to be written.
+ *
+ * @see #createInterfaceArray
+ * @see #readInterfaceArray
+ * @see IInterface
+ */
+ public final void writeInterfaceArray(
+ @SuppressLint("ArrayReturn") @Nullable T[] val) {
+ if (val != null) {
+ int N = val.length;
+ writeInt(N);
+ for (int i=0; i T[] createInterfaceArray(
+ @NonNull IntFunction newArray, @NonNull Function asInterface) {
+ int N = readInt();
+ if (N >= 0) {
+ T[] val = newArray.apply(N);
+ for (int i=0; i void readInterfaceArray(
+ @SuppressLint("ArrayReturn") @NonNull T[] val,
+ @NonNull Function asInterface) {
+ int N = readInt();
+ if (N == val.length) {
+ for (int i=0; i void writeInterfaceList(@Nullable List val) {
+ if (val == null) {
+ writeInt(-1);
+ return;
+ }
+ int N = val.size();
+ int i=0;
+ writeInt(N);
+ while (i < N) {
+ writeStrongInterface(val.get(i));
+ i++;
+ }
+ }
+
/**
* Flatten a {@code List} containing arbitrary {@code Parcelable} objects into this parcel
* at the current position. They can later be retrieved using
@@ -3379,6 +3475,32 @@ public final class Parcel {
return l;
}
+ /**
+ * Read and return a new ArrayList containing T (IInterface) objects from
+ * the parcel that was written with {@link #writeInterfaceList} at the
+ * current dataPosition(). Returns null if the
+ * previously written list object was null.
+ *
+ * @return A newly created ArrayList containing T (IInterface)
+ *
+ * @see #writeInterfaceList
+ */
+ @SuppressLint({"ConcreteCollection", "NullableCollection"})
+ @Nullable
+ public final ArrayList createInterfaceArrayList(
+ @NonNull Function asInterface) {
+ int N = readInt();
+ if (N < 0) {
+ return null;
+ }
+ ArrayList l = new ArrayList(N);
+ while (N > 0) {
+ l.add(asInterface.apply(readStrongBinder()));
+ N--;
+ }
+ return l;
+ }
+
/**
* Read into the given List items String objects that were written with
* {@link #writeStringList} at the current dataPosition().
@@ -3421,6 +3543,28 @@ public final class Parcel {
}
}
+ /**
+ * Read into the given List items IInterface objects that were written with
+ * {@link #writeInterfaceList} at the current dataPosition().
+ *
+ * @see #writeInterfaceList
+ */
+ public final void readInterfaceList(@NonNull List list,
+ @NonNull Function asInterface) {
+ int M = list.size();
+ int N = readInt();
+ int i = 0;
+ for (; i < M && i < N; i++) {
+ list.set(i, asInterface.apply(readStrongBinder()));
+ }
+ for (; i