From a9cb2102da997f016245da9a2a56f9ef134e8f91 Mon Sep 17 00:00:00 2001 From: Bernardo Rufino Date: Tue, 1 Mar 2022 15:10:47 +0000 Subject: [PATCH] Adjust Class parameter bounds in new Bundle APIs So they are consistent with Parcel and allow for patterns where the client specifies a more narrow type to perform the check while returning or populating a list of a broader type. Test: atest -d android.os.cts.BundleTest Bug: b/220872166#comment3 Change-Id: Ie0d430bb0ecd7fe4ee4bbbd245e38ff2813cc4eb --- core/api/current.txt | 4 ++-- core/java/android/os/BaseBundle.java | 2 +- core/java/android/os/Bundle.java | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index ba430af43ea86..3e5dc3fd2d0df 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -29670,7 +29670,7 @@ package android.os { method @Deprecated @Nullable public android.os.Parcelable[] getParcelableArray(@Nullable String); method @Nullable public T[] getParcelableArray(@Nullable String, @NonNull Class); method @Deprecated @Nullable public java.util.ArrayList getParcelableArrayList(@Nullable String); - method @Nullable public java.util.ArrayList getParcelableArrayList(@Nullable String, @NonNull Class); + method @Nullable public java.util.ArrayList getParcelableArrayList(@Nullable String, @NonNull Class); method @Deprecated @Nullable public java.io.Serializable getSerializable(@Nullable String); method @Nullable public T getSerializable(@Nullable String, @NonNull Class); method public short getShort(String); @@ -29679,7 +29679,7 @@ package android.os { method @Nullable public android.util.Size getSize(@Nullable String); method @Nullable public android.util.SizeF getSizeF(@Nullable String); method @Deprecated @Nullable public android.util.SparseArray getSparseParcelableArray(@Nullable String); - method @Nullable public android.util.SparseArray getSparseParcelableArray(@Nullable String, @NonNull Class); + method @Nullable public android.util.SparseArray getSparseParcelableArray(@Nullable String, @NonNull Class); method @Nullable public java.util.ArrayList getStringArrayList(@Nullable String); method public boolean hasFileDescriptors(); method public void putAll(android.os.Bundle); diff --git a/core/java/android/os/BaseBundle.java b/core/java/android/os/BaseBundle.java index 45812e5516188..e5dab0539a8e6 100644 --- a/core/java/android/os/BaseBundle.java +++ b/core/java/android/os/BaseBundle.java @@ -1453,7 +1453,7 @@ public class BaseBundle { @SuppressWarnings("unchecked") @Nullable - ArrayList getArrayList(@Nullable String key, @NonNull Class clazz) { + ArrayList getArrayList(@Nullable String key, @NonNull Class clazz) { unparcel(); try { return getValue(key, ArrayList.class, requireNonNull(clazz)); diff --git a/core/java/android/os/Bundle.java b/core/java/android/os/Bundle.java index edbbb59ac77d0..a19b51b7811b7 100644 --- a/core/java/android/os/Bundle.java +++ b/core/java/android/os/Bundle.java @@ -1059,7 +1059,8 @@ public final class Bundle extends BaseBundle implements Cloneable, Parcelable { @SuppressLint("NullableCollection") @SuppressWarnings("unchecked") @Nullable - public ArrayList getParcelableArrayList(@Nullable String key, @NonNull Class clazz) { + public ArrayList getParcelableArrayList(@Nullable String key, + @NonNull Class clazz) { // The reason for not using is because the caller could provide a // super class to restrict the children that doesn't implement Parcelable itself while the // children do, more details at b/210800751 (same reasoning applies here). @@ -1107,7 +1108,7 @@ public final class Bundle extends BaseBundle implements Cloneable, Parcelable { @SuppressWarnings("unchecked") @Nullable public SparseArray getSparseParcelableArray(@Nullable String key, - @NonNull Class clazz) { + @NonNull Class clazz) { // The reason for not using is because the caller could provide a // super class to restrict the children that doesn't implement Parcelable itself while the // children do, more details at b/210800751 (same reasoning applies here).