From aa4e9dfda8174d604244a0aed408040d1adbf62c Mon Sep 17 00:00:00 2001 From: Hao Ke Date: Thu, 2 Dec 2021 15:39:44 +0000 Subject: [PATCH] Deprecate unsafe readParcelableList API. Deprecate unsafe parcel APIs and point to the safer ones that take the expected type as parameter. Also mentioned the typed ones that take the creator as argument since those are also more performant. Test: Builds Bug: 195622897 Bug: 199275680 Bug: 205985058 Change-Id: I77a1a925d8759fd122936780587e3488705d4c56 --- core/api/current.txt | 2 +- core/java/android/os/Parcel.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/api/current.txt b/core/api/current.txt index 99226159348b1..6936ca724c387 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -31513,7 +31513,7 @@ package android.os { method @Nullable public T[] readParcelableArray(@Nullable ClassLoader, @NonNull Class); method @Deprecated @Nullable public android.os.Parcelable.Creator readParcelableCreator(@Nullable ClassLoader); method @Nullable public android.os.Parcelable.Creator readParcelableCreator(@Nullable ClassLoader, @NonNull Class); - method @NonNull public java.util.List readParcelableList(@NonNull java.util.List, @Nullable ClassLoader); + method @Deprecated @NonNull public java.util.List readParcelableList(@NonNull java.util.List, @Nullable ClassLoader); method @NonNull public java.util.List readParcelableList(@NonNull java.util.List, @Nullable ClassLoader, @NonNull Class); method @Nullable public android.os.PersistableBundle readPersistableBundle(); method @Nullable public android.os.PersistableBundle readPersistableBundle(@Nullable ClassLoader); diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java index afd0ff747b93c..36645155a4723 100644 --- a/core/java/android/os/Parcel.java +++ b/core/java/android/os/Parcel.java @@ -3646,7 +3646,14 @@ public final class Parcel { * list was {@code null}, {@code list} is cleared. * * @see #writeParcelableList(List, int) + * + * @deprecated Use the type-safer version {@link #readParcelableList(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 @NonNull public final List readParcelableList(@NonNull List list, @Nullable ClassLoader cl) {