Merge "Deprecate unsafe parcel APIs"

This commit is contained in:
Bernardo Rufino
2021-11-17 09:43:11 +00:00
committed by Gerrit Code Review
2 changed files with 62 additions and 11 deletions

View File

@@ -31446,9 +31446,9 @@ package android.os {
method public byte[] marshall(); method public byte[] marshall();
method @NonNull public static android.os.Parcel obtain(); method @NonNull public static android.os.Parcel obtain();
method @NonNull public static android.os.Parcel obtain(@NonNull android.os.IBinder); method @NonNull public static android.os.Parcel obtain(@NonNull android.os.IBinder);
method @Nullable public Object[] readArray(@Nullable ClassLoader); method @Deprecated @Nullable public Object[] readArray(@Nullable ClassLoader);
method @Nullable public <T> T[] readArray(@Nullable ClassLoader, @NonNull Class<T>); method @Nullable public <T> T[] readArray(@Nullable ClassLoader, @NonNull Class<T>);
method @Nullable public java.util.ArrayList readArrayList(@Nullable ClassLoader); method @Deprecated @Nullable public java.util.ArrayList readArrayList(@Nullable ClassLoader);
method @Nullable public <T> java.util.ArrayList<T> readArrayList(@Nullable ClassLoader, @NonNull Class<? extends T>); method @Nullable public <T> java.util.ArrayList<T> readArrayList(@Nullable ClassLoader, @NonNull Class<? extends T>);
method public void readBinderArray(@NonNull android.os.IBinder[]); method public void readBinderArray(@NonNull android.os.IBinder[]);
method public void readBinderList(@NonNull java.util.List<android.os.IBinder>); method public void readBinderList(@NonNull java.util.List<android.os.IBinder>);
@@ -31466,32 +31466,32 @@ package android.os {
method public android.os.ParcelFileDescriptor readFileDescriptor(); method public android.os.ParcelFileDescriptor readFileDescriptor();
method public float readFloat(); method public float readFloat();
method public void readFloatArray(@NonNull float[]); method public void readFloatArray(@NonNull float[]);
method @Nullable public java.util.HashMap readHashMap(@Nullable ClassLoader); method @Deprecated @Nullable public java.util.HashMap readHashMap(@Nullable ClassLoader);
method @Nullable public <K, V> java.util.HashMap<K,V> readHashMap(@Nullable ClassLoader, @NonNull Class<? extends K>, @NonNull Class<? extends V>); method @Nullable public <K, V> java.util.HashMap<K,V> readHashMap(@Nullable ClassLoader, @NonNull Class<? extends K>, @NonNull Class<? extends V>);
method public int readInt(); method public int readInt();
method public void readIntArray(@NonNull int[]); method public void readIntArray(@NonNull int[]);
method public <T extends android.os.IInterface> void readInterfaceArray(@NonNull T[], @NonNull java.util.function.Function<android.os.IBinder,T>); method public <T extends android.os.IInterface> void readInterfaceArray(@NonNull T[], @NonNull java.util.function.Function<android.os.IBinder,T>);
method public <T extends android.os.IInterface> void readInterfaceList(@NonNull java.util.List<T>, @NonNull java.util.function.Function<android.os.IBinder,T>); method public <T extends android.os.IInterface> void readInterfaceList(@NonNull java.util.List<T>, @NonNull java.util.function.Function<android.os.IBinder,T>);
method public void readList(@NonNull java.util.List, @Nullable ClassLoader); method @Deprecated public void readList(@NonNull java.util.List, @Nullable ClassLoader);
method public <T> void readList(@NonNull java.util.List<? super T>, @Nullable ClassLoader, @NonNull Class<T>); method public <T> void readList(@NonNull java.util.List<? super T>, @Nullable ClassLoader, @NonNull Class<T>);
method public long readLong(); method public long readLong();
method public void readLongArray(@NonNull long[]); method public void readLongArray(@NonNull long[]);
method public void readMap(@NonNull java.util.Map, @Nullable ClassLoader); method @Deprecated public void readMap(@NonNull java.util.Map, @Nullable ClassLoader);
method public <K, V> void readMap(@NonNull java.util.Map<? super K,? super V>, @Nullable ClassLoader, @NonNull Class<K>, @NonNull Class<V>); method public <K, V> void readMap(@NonNull java.util.Map<? super K,? super V>, @Nullable ClassLoader, @NonNull Class<K>, @NonNull Class<V>);
method @Nullable public <T extends android.os.Parcelable> T readParcelable(@Nullable ClassLoader); method @Deprecated @Nullable public <T extends android.os.Parcelable> T readParcelable(@Nullable ClassLoader);
method @Nullable public <T extends android.os.Parcelable> T readParcelable(@Nullable ClassLoader, @NonNull Class<T>); method @Nullable public <T extends android.os.Parcelable> T readParcelable(@Nullable ClassLoader, @NonNull Class<T>);
method @Nullable public android.os.Parcelable[] readParcelableArray(@Nullable ClassLoader); method @Nullable public android.os.Parcelable[] readParcelableArray(@Nullable ClassLoader);
method @Nullable public <T> T[] readParcelableArray(@Nullable ClassLoader, @NonNull Class<T>); method @Nullable public <T> T[] readParcelableArray(@Nullable ClassLoader, @NonNull Class<T>);
method @Nullable public android.os.Parcelable.Creator<?> readParcelableCreator(@Nullable ClassLoader); method @Deprecated @Nullable public android.os.Parcelable.Creator<?> readParcelableCreator(@Nullable ClassLoader);
method @Nullable public <T> android.os.Parcelable.Creator<T> readParcelableCreator(@Nullable ClassLoader, @NonNull Class<T>); method @Nullable public <T> android.os.Parcelable.Creator<T> readParcelableCreator(@Nullable ClassLoader, @NonNull Class<T>);
method @NonNull public <T extends android.os.Parcelable> java.util.List<T> readParcelableList(@NonNull java.util.List<T>, @Nullable ClassLoader); method @NonNull public <T extends android.os.Parcelable> java.util.List<T> readParcelableList(@NonNull java.util.List<T>, @Nullable ClassLoader);
method @Nullable public android.os.PersistableBundle readPersistableBundle(); method @Nullable public android.os.PersistableBundle readPersistableBundle();
method @Nullable public android.os.PersistableBundle readPersistableBundle(@Nullable ClassLoader); method @Nullable public android.os.PersistableBundle readPersistableBundle(@Nullable ClassLoader);
method @Nullable public java.io.Serializable readSerializable(); method @Deprecated @Nullable public java.io.Serializable readSerializable();
method @Nullable public <T extends java.io.Serializable> T readSerializable(@Nullable ClassLoader, @NonNull Class<T>); method @Nullable public <T extends java.io.Serializable> T readSerializable(@Nullable ClassLoader, @NonNull Class<T>);
method @NonNull public android.util.Size readSize(); method @NonNull public android.util.Size readSize();
method @NonNull public android.util.SizeF readSizeF(); method @NonNull public android.util.SizeF readSizeF();
method @Nullable public <T> android.util.SparseArray<T> readSparseArray(@Nullable ClassLoader); method @Deprecated @Nullable public <T> android.util.SparseArray<T> readSparseArray(@Nullable ClassLoader);
method @Nullable public <T> android.util.SparseArray<T> readSparseArray(@Nullable ClassLoader, @NonNull Class<? extends T>); method @Nullable public <T> android.util.SparseArray<T> readSparseArray(@Nullable ClassLoader, @NonNull Class<? extends T>);
method @Nullable public android.util.SparseBooleanArray readSparseBooleanArray(); method @Nullable public android.util.SparseBooleanArray readSparseBooleanArray();
method @Nullable public String readString(); method @Nullable public String readString();

View File

@@ -2990,7 +2990,12 @@ public final class Parcel {
* Please use {@link #readBundle(ClassLoader)} instead (whose data must have * Please use {@link #readBundle(ClassLoader)} instead (whose data must have
* been written with {@link #writeBundle}. Read into an existing Map object * been written with {@link #writeBundle}. Read into an existing Map object
* from the parcel at the current dataPosition(). * from the parcel at the current dataPosition().
*
* @deprecated Consider using {@link #readBundle(ClassLoader)} as stated above, in case this
* method is still preferred use the type-safer version {@link #readMap(Map, ClassLoader,
* Class, Class)} starting from Android {@link Build.VERSION_CODES#TIRAMISU}.
*/ */
@Deprecated
public final void readMap(@NonNull Map outVal, @Nullable ClassLoader loader) { public final void readMap(@NonNull Map outVal, @Nullable ClassLoader loader) {
int n = readInt(); int n = readInt();
readMapInternal(outVal, n, loader, /* clazzKey */ null, /* clazzValue */ null); readMapInternal(outVal, n, loader, /* clazzKey */ null, /* clazzValue */ null);
@@ -3016,7 +3021,14 @@ public final class Parcel {
* Read into an existing List object from the parcel at the current * Read into an existing List object from the parcel at the current
* dataPosition(), using the given class loader to load any enclosed * dataPosition(), using the given class loader to load any enclosed
* Parcelables. If it is null, the default class loader is used. * Parcelables. If it is null, the default class loader is used.
*
* @deprecated Use the type-safer version {@link #readList(List, ClassLoader, Class)} starting
* from Android {@link Build.VERSION_CODES#TIRAMISU}. Also consider changing the format to
* use {@link #readTypedList(List, Parcelable.Creator)} if possible (eg. if the items'
* class is final) since this is also more performant. Note that changing to the latter
* also requires changing the writes.
*/ */
@Deprecated
public final void readList(@NonNull List outVal, @Nullable ClassLoader loader) { public final void readList(@NonNull List outVal, @Nullable ClassLoader loader) {
int N = readInt(); int N = readInt();
readListInternal(outVal, N, loader, /* clazz */ null); readListInternal(outVal, N, loader, /* clazz */ null);
@@ -3043,10 +3055,14 @@ public final class Parcel {
* object from the parcel at the current dataPosition(), using the given * object from the parcel at the current dataPosition(), using the given
* class loader to load any enclosed Parcelables. Returns null if * class loader to load any enclosed Parcelables. Returns null if
* the previously written map object was null. * the previously written map object was null.
*
* @deprecated Consider using {@link #readBundle(ClassLoader)} as stated above, in case this
* method is still preferred use the type-safer version {@link #readHashMap(ClassLoader,
* Class, Class)} starting from Android {@link Build.VERSION_CODES#TIRAMISU}.
*/ */
@Deprecated
@Nullable @Nullable
public final HashMap readHashMap(@Nullable ClassLoader loader) public HashMap readHashMap(@Nullable ClassLoader loader) {
{
int n = readInt(); int n = readInt();
if (n < 0) { if (n < 0) {
return null; return null;
@@ -3247,7 +3263,14 @@ public final class Parcel {
* dataPosition(). Returns null if the previously written list object was * dataPosition(). Returns null if the previously written list object was
* null. The given class loader will be used to load any enclosed * null. The given class loader will be used to load any enclosed
* Parcelables. * Parcelables.
*
* @deprecated Use the type-safer version {@link #readArrayList(ClassLoader, Class)} starting
* from Android {@link Build.VERSION_CODES#TIRAMISU}. Also consider changing the format to
* use {@link #createTypedArrayList(Parcelable.Creator)} if possible (eg. if the items'
* class is final) since this is also more performant. Note that changing to the latter
* also requires changing the writes.
*/ */
@Deprecated
@Nullable @Nullable
public ArrayList readArrayList(@Nullable ClassLoader loader) { public ArrayList readArrayList(@Nullable ClassLoader loader) {
return readArrayListInternal(loader, /* clazz */ null); return readArrayListInternal(loader, /* clazz */ null);
@@ -3274,7 +3297,14 @@ public final class Parcel {
* dataPosition(). Returns null if the previously written array was * dataPosition(). Returns null if the previously written array was
* null. The given class loader will be used to load any enclosed * null. The given class loader will be used to load any enclosed
* Parcelables. * Parcelables.
*
* @deprecated Use the type-safer version {@link #readArray(ClassLoader, Class)} starting from
* Android {@link Build.VERSION_CODES#TIRAMISU}. Also consider changing the format to use
* {@link #createTypedArray(Parcelable.Creator)} if possible (eg. if the items' class is
* final) since this is also more performant. Note that changing to the latter also
* requires changing the writes.
*/ */
@Deprecated
@Nullable @Nullable
public Object[] readArray(@Nullable ClassLoader loader) { public Object[] readArray(@Nullable ClassLoader loader) {
return readArrayInternal(loader, /* clazz */ null); return readArrayInternal(loader, /* clazz */ null);
@@ -3300,7 +3330,14 @@ public final class Parcel {
* dataPosition(). Returns null if the previously written list object was * dataPosition(). Returns null if the previously written list object was
* null. The given class loader will be used to load any enclosed * null. The given class loader will be used to load any enclosed
* Parcelables. * Parcelables.
*
* @deprecated Use the type-safer version {@link #readSparseArray(ClassLoader, Class)} starting
* from Android {@link Build.VERSION_CODES#TIRAMISU}. Also consider changing the format to
* use {@link #createTypedSparseArray(Parcelable.Creator)} if possible (eg. if the items'
* class is final) since this is also more performant. Note that changing to the latter
* also requires changing the writes.
*/ */
@Deprecated
@Nullable @Nullable
public <T> SparseArray<T> readSparseArray(@Nullable ClassLoader loader) { public <T> SparseArray<T> readSparseArray(@Nullable ClassLoader loader) {
return readSparseArrayInternal(loader, /* clazz */ null); return readSparseArrayInternal(loader, /* clazz */ null);
@@ -4107,7 +4144,13 @@ public final class Parcel {
* object has been written. * object has been written.
* @throws BadParcelableException Throws BadParcelableException if there * @throws BadParcelableException Throws BadParcelableException if there
* was an error trying to instantiate the Parcelable. * was an error trying to instantiate the Parcelable.
*
* @deprecated Use the type-safer version {@link #readParcelable(ClassLoader, Class)} starting
* from Android {@link Build.VERSION_CODES#TIRAMISU}. Also consider changing the format to
* use {@link Parcelable.Creator#createFromParcel(Parcel)} if possible since this is also
* more performant. Note that changing to the latter also requires changing the writes.
*/ */
@Deprecated
@Nullable @Nullable
public final <T extends Parcelable> T readParcelable(@Nullable ClassLoader loader) { public final <T extends Parcelable> T readParcelable(@Nullable ClassLoader loader) {
return readParcelableInternal(loader, /* clazz */ null); return readParcelableInternal(loader, /* clazz */ null);
@@ -4176,7 +4219,11 @@ public final class Parcel {
* read the {@link Parcelable.Creator}. * read the {@link Parcelable.Creator}.
* *
* @see #writeParcelableCreator * @see #writeParcelableCreator
*
* @deprecated Use the type-safer version {@link #readParcelableCreator(ClassLoader, Class)}
* starting from Android {@link Build.VERSION_CODES#TIRAMISU}.
*/ */
@Deprecated
@Nullable @Nullable
public final Parcelable.Creator<?> readParcelableCreator(@Nullable ClassLoader loader) { public final Parcelable.Creator<?> readParcelableCreator(@Nullable ClassLoader loader) {
return readParcelableCreatorInternal(loader, /* clazz */ null); return readParcelableCreatorInternal(loader, /* clazz */ null);
@@ -4337,7 +4384,11 @@ public final class Parcel {
* Read and return a new Serializable object from the parcel. * Read and return a new Serializable object from the parcel.
* @return the Serializable object, or null if the Serializable name * @return the Serializable object, or null if the Serializable name
* wasn't found in the parcel. * wasn't found in the parcel.
*
* @deprecated Use the type-safer version {@link #readSerializable(ClassLoader, Class)} starting
* from Android {@link Build.VERSION_CODES#TIRAMISU}.
*/ */
@Deprecated
@Nullable @Nullable
public Serializable readSerializable() { public Serializable readSerializable() {
return readSerializableInternal(/* loader */ null, /* clazz */ null); return readSerializableInternal(/* loader */ null, /* clazz */ null);