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
This commit is contained in:
Mark Renouf
2022-06-01 19:16:46 +00:00
parent 58bda6d509
commit 9d5f710317

View File

@@ -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);