Merge "Fix Bundle#getParcelableArray call" into rvc-dev am: d70c7dda50

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

Change-Id: I18687d77b5383d35b5cd079345be1cbac64dd532
This commit is contained in:
TreeHugger Robot
2020-07-03 02:40:20 +00:00
committed by Automerger Merge Worker

View File

@@ -96,9 +96,9 @@ import com.android.internal.util.ContrastColorUtil;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@@ -1620,7 +1620,7 @@ public class Notification implements Parcelable
* of non-textual RemoteInputs do not access these remote inputs. * of non-textual RemoteInputs do not access these remote inputs.
*/ */
public RemoteInput[] getDataOnlyRemoteInputs() { public RemoteInput[] getDataOnlyRemoteInputs() {
return (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); return getParcelableArrayFromBundle(mExtras, EXTRA_DATA_ONLY_INPUTS, RemoteInput.class);
} }
/** /**
@@ -1802,8 +1802,8 @@ public class Notification implements Parcelable
checkContextualActionNullFields(); checkContextualActionNullFields();
ArrayList<RemoteInput> dataOnlyInputs = new ArrayList<>(); ArrayList<RemoteInput> dataOnlyInputs = new ArrayList<>();
RemoteInput[] previousDataInputs = RemoteInput[] previousDataInputs = getParcelableArrayFromBundle(
(RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); mExtras, EXTRA_DATA_ONLY_INPUTS, RemoteInput.class);
if (previousDataInputs != null) { if (previousDataInputs != null) {
for (RemoteInput input : previousDataInputs) { for (RemoteInput input : previousDataInputs) {
dataOnlyInputs.add(input); dataOnlyInputs.add(input);
@@ -5368,8 +5368,8 @@ public class Notification implements Parcelable
big.setViewVisibility(R.id.actions_container, View.GONE); big.setViewVisibility(R.id.actions_container, View.GONE);
} }
RemoteInputHistoryItem[] replyText = (RemoteInputHistoryItem[]) RemoteInputHistoryItem[] replyText = getParcelableArrayFromBundle(
mN.extras.getParcelableArray(EXTRA_REMOTE_INPUT_HISTORY_ITEMS); mN.extras, EXTRA_REMOTE_INPUT_HISTORY_ITEMS, RemoteInputHistoryItem.class);
if (validRemoteInput && replyText != null && replyText.length > 0 if (validRemoteInput && replyText != null && replyText.length > 0
&& !TextUtils.isEmpty(replyText[0].getText()) && !TextUtils.isEmpty(replyText[0].getText())
&& p.maxRemoteInputHistory > 0) { && p.maxRemoteInputHistory > 0) {
@@ -8155,8 +8155,9 @@ public class Notification implements Parcelable
if (mBuilder.mActions.size() > 0) { if (mBuilder.mActions.size() > 0) {
maxRows--; maxRows--;
} }
RemoteInputHistoryItem[] remoteInputHistory = (RemoteInputHistoryItem[]) RemoteInputHistoryItem[] remoteInputHistory = getParcelableArrayFromBundle(
mBuilder.mN.extras.getParcelableArray(EXTRA_REMOTE_INPUT_HISTORY_ITEMS); mBuilder.mN.extras, EXTRA_REMOTE_INPUT_HISTORY_ITEMS,
RemoteInputHistoryItem.class);
if (remoteInputHistory != null if (remoteInputHistory != null
&& remoteInputHistory.length > NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION) { && remoteInputHistory.length > NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION) {
// Let's remove some messages to make room for the remote input history. // Let's remove some messages to make room for the remote input history.
@@ -9579,8 +9580,8 @@ public class Notification implements Parcelable
mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS);
mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT);
Notification[] pages = getNotificationArrayFromBundle( Notification[] pages = getParcelableArrayFromBundle(
wearableBundle, KEY_PAGES); wearableBundle, KEY_PAGES, Notification.class);
if (pages != null) { if (pages != null) {
Collections.addAll(mPages, pages); Collections.addAll(mPages, pages);
} }
@@ -10838,17 +10839,22 @@ public class Notification implements Parcelable
} }
/** /**
* Get an array of Notification objects from a parcelable array bundle field. * Get an array of Parcelable objects from a parcelable array bundle field.
* Update the bundle to have a typed array so fetches in the future don't need * Update the bundle to have a typed array so fetches in the future don't need
* to do an array copy. * to do an array copy.
*/ */
private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { @Nullable
Parcelable[] array = bundle.getParcelableArray(key); private static <T extends Parcelable> T[] getParcelableArrayFromBundle(
if (array instanceof Notification[] || array == null) { Bundle bundle, String key, Class<T> itemClass) {
return (Notification[]) array; final Parcelable[] array = bundle.getParcelableArray(key);
final Class<?> arrayClass = Array.newInstance(itemClass, 0).getClass();
if (arrayClass.isInstance(array) || array == null) {
return (T[]) array;
}
final T[] typedArray = (T[]) Array.newInstance(itemClass, array.length);
for (int i = 0; i < array.length; i++) {
typedArray[i] = (T) array[i];
} }
Notification[] typedArray = Arrays.copyOf(array, array.length,
Notification[].class);
bundle.putParcelableArray(key, typedArray); bundle.putParcelableArray(key, typedArray);
return typedArray; return typedArray;
} }