From 9d5f710317aa47ca5d4f7feb2ca663515a5b716f Mon Sep 17 00:00:00 2001 From: Mark Renouf Date: Wed, 1 Jun 2022 19:16:46 +0000 Subject: [PATCH] Fix crash in DisplayResolveInfo writeToParcel impl This fixes an incorrect use of List.toArray() leading to a crash When passed no arguments, toArray returns an Object[] and not T[], hence the unchecked cast will throw ClassCastException when this is run. This change cleans up the parcelable implementation by replacing writeParcelableArray with writeTypedList, which is more efficient and avoids the conversion to/from an array entirely. Bug: 200347466 Test: Take screenshot, tap share, long press an app, short press power Change-Id: I225664c8709502c7e45ac06c2858c0c5ac0b7506 --- .../android/internal/app/chooser/DisplayResolveInfo.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/core/java/com/android/internal/app/chooser/DisplayResolveInfo.java b/core/java/com/android/internal/app/chooser/DisplayResolveInfo.java index 5ebc9154023ca..96cc5e1bd7d26 100644 --- a/core/java/com/android/internal/app/chooser/DisplayResolveInfo.java +++ b/core/java/com/android/internal/app/chooser/DisplayResolveInfo.java @@ -35,7 +35,6 @@ import com.android.internal.app.ResolverActivity; import com.android.internal.app.ResolverListAdapter.ResolveInfoPresentationGetter; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; /** @@ -206,7 +205,7 @@ public class DisplayResolveInfo implements TargetInfo, Parcelable { dest.writeCharSequence(mDisplayLabel); dest.writeCharSequence(mExtendedInfo); dest.writeParcelable(mResolvedIntent, 0); - dest.writeParcelableArray((Intent[]) mSourceIntents.toArray(), 0); + dest.writeTypedList(mSourceIntents); dest.writeBoolean(mIsSuspended); dest.writeBoolean(mPinned); dest.writeParcelable(mResolveInfo, 0); @@ -227,9 +226,7 @@ public class DisplayResolveInfo implements TargetInfo, Parcelable { mDisplayLabel = in.readCharSequence(); mExtendedInfo = in.readCharSequence(); mResolvedIntent = in.readParcelable(null /* ClassLoader */, android.content.Intent.class); - mSourceIntents.addAll( - Arrays.asList((Intent[]) in.readParcelableArray(null /* ClassLoader */, - Intent.class))); + in.readTypedList(mSourceIntents, Intent.CREATOR); mIsSuspended = in.readBoolean(); mPinned = in.readBoolean(); mResolveInfo = in.readParcelable(null /* ClassLoader */, android.content.pm.ResolveInfo.class);