Skip to content

Commit b3ae74f

Browse files
WinsonAndroid Build Coastguard Worker
authored andcommitted
Fix parsing code parcelling errors
Address problems reading/writing: - ParsingPackageImpl mKeySetMapping - ParsingPackageImpl mQueriesIntent Bug: 187043377 Bug: 195962697 Test: atest com.android.server.pm.test.parsing.parcelling Merged-In: I5b33315f8248d5fcbdef2cc04ecf77cc18dbd7b6 Change-Id: I5b33315f8248d5fcbdef2cc04ecf77cc18dbd7b6 (cherry picked from commit f93af7ef7ebe9d139a34e615b97393a41ebabb56) (cherry picked from commit 37a0b6de89f7fb321fbeac02ec1a012817b8e682)
1 parent 87b6fcd commit b3ae74f

2 files changed

Lines changed: 66 additions & 3 deletions

File tree

core/java/android/content/pm/parsing/ParsingPackageImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ public void writeToParcel(Parcel dest, int flags) {
10051005
sForInternedStringList.parcel(this.requestedPermissions, dest, flags);
10061006
sForInternedStringList.parcel(this.implicitPermissions, dest, flags);
10071007
sForStringSet.parcel(this.upgradeKeySets, dest, flags);
1008-
dest.writeMap(this.keySetMapping);
1008+
ParsingPackageUtils.writeKeySetMapping(dest, this.keySetMapping);
10091009
sForInternedStringList.parcel(this.protectedBroadcasts, dest, flags);
10101010
dest.writeTypedList(this.activities);
10111011
dest.writeTypedList(this.receivers);
@@ -1024,7 +1024,7 @@ public void writeToParcel(Parcel dest, int flags) {
10241024
dest.writeBoolean(this.use32BitAbi);
10251025
dest.writeBoolean(this.visibleToInstantApps);
10261026
dest.writeBoolean(this.forceQueryable);
1027-
dest.writeParcelableList(this.queriesIntents, flags);
1027+
dest.writeTypedList(this.queriesIntents, flags);
10281028
sForInternedStringList.parcel(this.queriesPackages, dest, flags);
10291029
dest.writeString(this.appComponentFactory);
10301030
dest.writeString(this.backupAgentName);
@@ -1166,7 +1166,7 @@ public ParsingPackageImpl(Parcel in) {
11661166
this.requestedPermissions = sForInternedStringList.unparcel(in);
11671167
this.implicitPermissions = sForInternedStringList.unparcel(in);
11681168
this.upgradeKeySets = sForStringSet.unparcel(in);
1169-
this.keySetMapping = in.readHashMap(boot);
1169+
this.keySetMapping = ParsingPackageUtils.readKeySetMapping(in);
11701170
this.protectedBroadcasts = sForInternedStringList.unparcel(in);
11711171

11721172
this.activities = in.createTypedArrayList(ParsedActivity.CREATOR);

core/java/android/content/pm/parsing/ParsingPackageUtils.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import android.os.Build;
8585
import android.os.Bundle;
8686
import android.os.FileUtils;
87+
import android.os.Parcel;
8788
import android.os.RemoteException;
8889
import android.os.Trace;
8990
import android.os.ext.SdkExtensions;
@@ -2834,6 +2835,68 @@ private static String nonResString(@StyleableRes int index, TypedArray sa) {
28342835
return sa.getNonResourceString(index);
28352836
}
28362837

2838+
/**
2839+
* Writes the keyset mapping to the provided package. {@code null} mappings are permitted.
2840+
*/
2841+
public static void writeKeySetMapping(@NonNull Parcel dest,
2842+
@NonNull Map<String, ArraySet<PublicKey>> keySetMapping) {
2843+
if (keySetMapping == null) {
2844+
dest.writeInt(-1);
2845+
return;
2846+
}
2847+
2848+
final int N = keySetMapping.size();
2849+
dest.writeInt(N);
2850+
2851+
for (String key : keySetMapping.keySet()) {
2852+
dest.writeString(key);
2853+
ArraySet<PublicKey> keys = keySetMapping.get(key);
2854+
if (keys == null) {
2855+
dest.writeInt(-1);
2856+
continue;
2857+
}
2858+
2859+
final int M = keys.size();
2860+
dest.writeInt(M);
2861+
for (int j = 0; j < M; j++) {
2862+
dest.writeSerializable(keys.valueAt(j));
2863+
}
2864+
}
2865+
}
2866+
2867+
/**
2868+
* Reads a keyset mapping from the given parcel at the given data position. May return
2869+
* {@code null} if the serialized mapping was {@code null}.
2870+
*/
2871+
@NonNull
2872+
public static ArrayMap<String, ArraySet<PublicKey>> readKeySetMapping(@NonNull Parcel in) {
2873+
final int N = in.readInt();
2874+
if (N == -1) {
2875+
return null;
2876+
}
2877+
2878+
ArrayMap<String, ArraySet<PublicKey>> keySetMapping = new ArrayMap<>();
2879+
for (int i = 0; i < N; ++i) {
2880+
String key = in.readString();
2881+
final int M = in.readInt();
2882+
if (M == -1) {
2883+
keySetMapping.put(key, null);
2884+
continue;
2885+
}
2886+
2887+
ArraySet<PublicKey> keys = new ArraySet<>(M);
2888+
for (int j = 0; j < M; ++j) {
2889+
PublicKey pk = (PublicKey) in.readSerializable();
2890+
keys.add(pk);
2891+
}
2892+
2893+
keySetMapping.put(key, keys);
2894+
}
2895+
2896+
return keySetMapping;
2897+
}
2898+
2899+
28372900
/**
28382901
* Callback interface for retrieving information that may be needed while parsing
28392902
* a package.

0 commit comments

Comments
 (0)