Merge "Refactor PackageParser (13/n)"

This commit is contained in:
Jackal Guo
2021-07-29 00:58:27 +00:00
committed by Android (Google) Code Review
17 changed files with 248 additions and 83 deletions

View File

@@ -18,6 +18,8 @@ package android.content.pm.parsing;
import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
import static android.content.pm.parsing.ParsingPackageUtils.checkRequiredSystemProperties;
import static android.content.pm.parsing.ParsingPackageUtils.parsePublicKey;
import static android.content.pm.parsing.ParsingPackageUtils.validateName;
import static android.content.pm.parsing.ParsingUtils.ANDROID_RES_NAMESPACE;
import static android.content.pm.parsing.ParsingUtils.DEFAULT_MIN_SDK_VERSION;
@@ -27,7 +29,6 @@ import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER;
import android.annotation.NonNull;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
import android.content.pm.SigningDetails;
import android.content.pm.VerifierInfo;
import android.content.pm.parsing.result.ParseInput;
@@ -78,8 +79,6 @@ public class ApkLiteParseUtils {
* This performs validity checking on cluster style packages, such as
* requiring identical package name and version codes, a single base APK,
* and unique split names.
*
* @see PackageParser#parsePackage(File, int)
*/
public static ParseResult<PackageLite> parsePackageLite(ParseInput input,
File packageFile, int flags) {
@@ -506,7 +505,7 @@ public class ApkLiteParseUtils {
}
// Check to see if overlay should be excluded based on system property condition
if (!PackageParser.checkRequiredSystemProperties(requiredSystemPropertyName,
if (!checkRequiredSystemProperties(requiredSystemPropertyName,
requiredSystemPropertyValue)) {
Slog.i(TAG, "Skipping target and overlay pair " + targetPackage + " and "
+ codePath + ": overlay ignored due to required system property: "
@@ -577,7 +576,7 @@ public class ApkLiteParseUtils {
return null;
}
final PublicKey publicKey = PackageParser.parsePublicKey(encodedPublicKey);
final PublicKey publicKey = parsePublicKey(encodedPublicKey);
if (publicKey == null) {
Slog.i(TAG, "Unable to parse verifier public key for " + packageName);
return null;

View File

@@ -47,7 +47,6 @@ import android.content.pm.FeatureInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.Property;
import android.content.pm.PackageParser;
import android.content.pm.Signature;
import android.content.pm.SigningDetails;
import android.content.pm.parsing.component.ComponentParseUtils;
@@ -91,6 +90,7 @@ import android.os.Bundle;
import android.os.FileUtils;
import android.os.Parcel;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.os.ext.SdkExtensions;
@@ -99,6 +99,7 @@ import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.AttributeSet;
import android.util.Base64;
import android.util.DisplayMetrics;
import android.util.Pair;
import android.util.Slog;
@@ -122,7 +123,12 @@ import java.io.File;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.spec.EncodedKeySpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -330,8 +336,6 @@ public class ParsingPackageUtils {
* result from a previous parse of the same {@code packageFile} with the same
* {@code flags}. Note that this method does not check whether {@code packageFile}
* has changed since the last parse, it's up to callers to do so.
*
* @see PackageParser#parsePackageLite(File, int)
*/
public ParseResult<ParsingPackage> parsePackage(ParseInput input, File packageFile, int flags) {
if (packageFile.isDirectory()) {
@@ -1069,7 +1073,7 @@ public class ParsingPackageUtils {
+ " must define a public-key value on first use at "
+ parser.getPositionDescription());
} else if (encodedKey != null) {
PublicKey currentKey = PackageParser.parsePublicKey(encodedKey);
PublicKey currentKey = parsePublicKey(encodedKey);
if (currentKey == null) {
Slog.w(TAG, "No recognized valid key in 'public-key' tag at "
+ parser.getPositionDescription() + " key-set "
@@ -1613,8 +1617,39 @@ public class ParsingPackageUtils {
}
/**
* {@link ParseResult} version of
* {@link PackageParser#computeMinSdkVersion(int, String, int, String[], String[])}
* Computes the minSdkVersion to use at runtime. If the package is not
* compatible with this platform, populates {@code outError[0]} with an
* error message.
* <p>
* If {@code minCode} is not specified, e.g. the value is {@code null},
* then behavior varies based on the {@code platformSdkVersion}:
* <ul>
* <li>If the platform SDK version is greater than or equal to the
* {@code minVers}, returns the {@code mniVers} unmodified.
* <li>Otherwise, returns -1 to indicate that the package is not
* compatible with this platform.
* </ul>
* <p>
* Otherwise, the behavior varies based on whether the current platform
* is a pre-release version, e.g. the {@code platformSdkCodenames} array
* has length > 0:
* <ul>
* <li>If this is a pre-release platform and the value specified by
* {@code targetCode} is contained within the array of allowed pre-release
* codenames, this method will return {@link Build.VERSION_CODES#CUR_DEVELOPMENT}.
* <li>If this is a released platform, this method will return -1 to
* indicate that the package is not compatible with this platform.
* </ul>
*
* @param minVers minSdkVersion number, if specified in the application
* manifest, or 1 otherwise
* @param minCode minSdkVersion code, if specified in the application
* manifest, or {@code null} otherwise
* @param platformSdkVersion platform SDK version number, typically
* Build.VERSION.SDK_INT
* @param platformSdkCodenames array of allowed prerelease SDK codenames
* for this platform
* @return the minSdkVersion to use at runtime if successful
*/
public static ParseResult<Integer> computeMinSdkVersion(@IntRange(from = 1) int minVers,
@Nullable String minCode, @IntRange(from = 1) int platformSdkVersion,
@@ -1651,8 +1686,31 @@ public class ParsingPackageUtils {
}
/**
* {@link ParseResult} version of
* {@link PackageParser#computeTargetSdkVersion(int, String, String[], String[])}
* Computes the targetSdkVersion to use at runtime. If the package is not
* compatible with this platform, populates {@code outError[0]} with an
* error message.
* <p>
* If {@code targetCode} is not specified, e.g. the value is {@code null},
* then the {@code targetVers} will be returned unmodified.
* <p>
* Otherwise, the behavior varies based on whether the current platform
* is a pre-release version, e.g. the {@code platformSdkCodenames} array
* has length > 0:
* <ul>
* <li>If this is a pre-release platform and the value specified by
* {@code targetCode} is contained within the array of allowed pre-release
* codenames, this method will return {@link Build.VERSION_CODES#CUR_DEVELOPMENT}.
* <li>If this is a released platform, this method will return -1 to
* indicate that the package is not compatible with this platform.
* </ul>
*
* @param targetVers targetSdkVersion number, if specified in the
* application manifest, or 0 otherwise
* @param targetCode targetSdkVersion code, if specified in the application
* manifest, or {@code null} otherwise
* @param platformSdkCodenames array of allowed pre-release SDK codenames
* for this platform
* @return the targetSdkVersion to use at runtime if successful
*/
public static ParseResult<Integer> computeTargetSdkVersion(@IntRange(from = 0) int targetVers,
@Nullable String targetCode, @NonNull String[] platformSdkCodenames,
@@ -2684,7 +2742,7 @@ public class ParsingPackageUtils {
R.styleable.AndroidManifestResourceOverlay_requiredSystemPropertyName);
String propValue = sa.getString(
R.styleable.AndroidManifestResourceOverlay_requiredSystemPropertyValue);
if (!PackageParser.checkRequiredSystemProperties(propName, propValue)) {
if (!checkRequiredSystemProperties(propName, propValue)) {
String message = "Skipping target and overlay pair " + target + " and "
+ pkg.getBaseApkPath()
+ ": overlay ignored due to required system property: "
@@ -2961,6 +3019,114 @@ public class ParsingPackageUtils {
}
}
/**
* @return {@link PublicKey} of a given encoded public key.
*/
public static final PublicKey parsePublicKey(final String encodedPublicKey) {
if (encodedPublicKey == null) {
Slog.w(TAG, "Could not parse null public key");
return null;
}
try {
return parsePublicKey(Base64.decode(encodedPublicKey, Base64.DEFAULT));
} catch (IllegalArgumentException e) {
Slog.w(TAG, "Could not parse verifier public key; invalid Base64");
return null;
}
}
/**
* @return {@link PublicKey} of the given byte array of a public key.
*/
public static final PublicKey parsePublicKey(final byte[] publicKey) {
if (publicKey == null) {
Slog.w(TAG, "Could not parse null public key");
return null;
}
final EncodedKeySpec keySpec;
try {
keySpec = new X509EncodedKeySpec(publicKey);
} catch (IllegalArgumentException e) {
Slog.w(TAG, "Could not parse verifier public key; invalid Base64");
return null;
}
/* First try the key as an RSA key. */
try {
final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return keyFactory.generatePublic(keySpec);
} catch (NoSuchAlgorithmException e) {
Slog.wtf(TAG, "Could not parse public key: RSA KeyFactory not included in build");
} catch (InvalidKeySpecException e) {
// Not a RSA public key.
}
/* Now try it as a ECDSA key. */
try {
final KeyFactory keyFactory = KeyFactory.getInstance("EC");
return keyFactory.generatePublic(keySpec);
} catch (NoSuchAlgorithmException e) {
Slog.wtf(TAG, "Could not parse public key: EC KeyFactory not included in build");
} catch (InvalidKeySpecException e) {
// Not a ECDSA public key.
}
/* Now try it as a DSA key. */
try {
final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
return keyFactory.generatePublic(keySpec);
} catch (NoSuchAlgorithmException e) {
Slog.wtf(TAG, "Could not parse public key: DSA KeyFactory not included in build");
} catch (InvalidKeySpecException e) {
// Not a DSA public key.
}
/* Not a supported key type */
return null;
}
/**
* Returns {@code true} if both the property name and value are empty or if the given system
* property is set to the specified value. Properties can be one or more, and if properties are
* more than one, they must be separated by comma, and count of names and values must be equal,
* and also every given system property must be set to the corresponding value.
* In all other cases, returns {@code false}
*/
public static boolean checkRequiredSystemProperties(@Nullable String rawPropNames,
@Nullable String rawPropValues) {
if (TextUtils.isEmpty(rawPropNames) || TextUtils.isEmpty(rawPropValues)) {
if (!TextUtils.isEmpty(rawPropNames) || !TextUtils.isEmpty(rawPropValues)) {
// malformed condition - incomplete
Slog.w(TAG, "Disabling overlay - incomplete property :'" + rawPropNames
+ "=" + rawPropValues + "' - require both requiredSystemPropertyName"
+ " AND requiredSystemPropertyValue to be specified.");
return false;
}
// no valid condition set - so no exclusion criteria, overlay will be included.
return true;
}
final String[] propNames = rawPropNames.split(",");
final String[] propValues = rawPropValues.split(",");
if (propNames.length != propValues.length) {
Slog.w(TAG, "Disabling overlay - property :'" + rawPropNames
+ "=" + rawPropValues + "' - require both requiredSystemPropertyName"
+ " AND requiredSystemPropertyValue lists to have the same size.");
return false;
}
for (int i = 0; i < propNames.length; i++) {
// Check property value: make sure it is both set and equal to expected value
final String currValue = SystemProperties.get(propNames[i]);
if (!TextUtils.equals(currValue, propValues[i])) {
return false;
}
}
return true;
}
/**
* Collect certificates from all the APKs described in the given package. Also asserts that
* all APK contents are signed correctly and consistently.

View File

@@ -16,9 +16,10 @@
package android.content.pm.parsing;
import static android.content.pm.parsing.ParsingPackageUtils.RIGID_PARSER;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.pm.PackageParser;
import android.content.pm.parsing.result.ParseInput;
import android.content.pm.parsing.result.ParseResult;
import android.content.res.XmlResourceParser;
@@ -62,7 +63,7 @@ public class ParsingUtils {
@NonNull
public static ParseResult unknownTag(String parentTag, ParsingPackage pkg,
XmlResourceParser parser, ParseInput input) throws IOException, XmlPullParserException {
if (PackageParser.RIGID_PARSER) {
if (RIGID_PARSER) {
return input.error("Bad element under " + parentTag + ": " + parser.getName());
}
Slog.w(TAG, "Unknown element under " + parentTag + ": "

View File

@@ -16,10 +16,11 @@
package android.content.pm.parsing.component;
import static android.content.pm.parsing.ParsingUtils.ANDROID_RES_NAMESPACE;
import android.annotation.NonNull;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageParser;
import android.content.pm.parsing.ParsingPackage;
import android.content.pm.parsing.ParsingPackageUtils;
import android.content.pm.parsing.ParsingUtils;
@@ -97,8 +98,7 @@ public class ParsedIntentInfoUtils {
String nodeName = parser.getName();
switch (nodeName) {
case "action": {
String value = parser.getAttributeValue(PackageParser.ANDROID_RESOURCES,
"name");
String value = parser.getAttributeValue(ANDROID_RES_NAMESPACE, "name");
if (value == null) {
result = input.error("No value supplied for <android:name>");
} else if (value.isEmpty()) {
@@ -113,8 +113,7 @@ public class ParsedIntentInfoUtils {
break;
}
case "category": {
String value = parser.getAttributeValue(PackageParser.ANDROID_RESOURCES,
"name");
String value = parser.getAttributeValue(ANDROID_RES_NAMESPACE, "name");
if (value == null) {
result = input.error("No value supplied for <android:name>");
} else if (value.isEmpty()) {

View File

@@ -16,10 +16,10 @@
package android.content.pm.parsing.component;
import static android.content.pm.parsing.ParsingPackageUtils.RIGID_PARSER;
import static android.content.pm.parsing.component.ComponentParseUtils.flag;
import android.annotation.NonNull;
import android.content.pm.PackageParser;
import android.content.pm.PathPermission;
import android.content.pm.ProviderInfo;
import android.content.pm.parsing.ParsingPackage;
@@ -262,7 +262,7 @@ public class ParsedProviderUtils {
}
provider.setGrantUriPermissions(true);
} else {
if (PackageParser.RIGID_PARSER) {
if (RIGID_PARSER) {
return input.error("No path, pathPrefix, or pathPattern for <path-permission>");
}
@@ -308,7 +308,7 @@ public class ParsedProviderUtils {
}
if (!havePerm) {
if (PackageParser.RIGID_PARSER) {
if (RIGID_PARSER) {
return input.error(
"No readPermission or writePermission for <path-permission>");
}
@@ -365,7 +365,7 @@ public class ParsedProviderUtils {
provider.setPathPermissions(newp);
}
} else {
if (PackageParser.RIGID_PARSER) {
if (RIGID_PARSER) {
return input.error(
"No path, pathPrefix, or pathPattern for <path-permission>");
}

View File

@@ -115,8 +115,8 @@ public class SplitAssetDependencyLoader extends SplitDependencyLoader<IllegalArg
@Override
public AssetManager getSplitAssetManager(int idx) throws IllegalArgumentException {
// Since we insert the base at position 0, and PackageParser keeps splits separate from
// the base, we need to adjust the index.
// Since we insert the base at position 0, and ParsingPackageUtils keeps splits separate
// from the base, we need to adjust the index.
loadDependenciesForSplit(idx + 1);
return mCachedAssetManagers[idx + 1];
}

View File

@@ -66,8 +66,8 @@ public class WearPackageUtil {
/**
* In order to make sure that the Wearable Asset Manager has a reasonable apk that can be used
* by the PackageManager, we will parse it before sending it to the PackageManager.
* Unfortunately, PackageParser needs a file to parse. So, we have to temporarily convert the fd
* to a File.
* Unfortunately, ParsingPackageUtils needs a file to parse. So, we have to temporarily convert
* the fd to a File.
*
* @param context
* @param fd FileDescriptor to convert to File

View File

@@ -17,10 +17,10 @@
package com.android.server.pm;
import static android.content.pm.PackageManager.INSTALL_FAILED_INVALID_APK;
import static android.content.pm.parsing.ParsingPackageUtils.parsePublicKey;
import static com.android.server.pm.PackageManagerService.SCAN_INITIAL;
import android.content.pm.PackageParser;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Base64;
@@ -801,7 +801,7 @@ public class KeySetManagerService {
long identifier = parser.getAttributeLong(null, "identifier");
int refCount = 0;
byte[] publicKey = parser.getAttributeBytesBase64(null, "value", null);
PublicKey pub = PackageParser.parsePublicKey(publicKey);
PublicKey pub = parsePublicKey(publicKey);
if (pub != null) {
PublicKeyHandle pkh = new PublicKeyHandle(identifier, refCount, pub);
mPublicKeys.put(identifier, pkh);

View File

@@ -210,7 +210,7 @@ public class PackageDexOptimizer {
if (paths.size() != classLoaderContexts.length) {
String[] splitCodePaths = pkg.getSplitCodePaths();
throw new IllegalStateException("Inconsistent information "
+ "between PackageParser.Package and its ApplicationInfo. "
+ "between AndroidPackage and its ApplicationInfo. "
+ "pkg.getAllCodePaths=" + paths
+ " pkg.getBaseCodePath=" + pkg.getBaseApkPath()
+ " pkg.getSplitCodePaths="

View File

@@ -571,7 +571,7 @@ final class Policy {
* In all cases, a return value of null should be interpreted as the apk failing
* to match this Policy instance; i.e. failing this policy stanza.
* </p>
* @param pkg the apk to check given as a PackageParser.Package object
* @param pkg the apk to check given as a AndroidPackage object
* @return A string representing the seinfo matched during policy lookup.
* A value of null can also be returned if no match occured.
*/

View File

@@ -88,7 +88,7 @@ public final class SharedUserSetting extends SettingBase {
uidFlags = orig.uidFlags;
uidPrivateFlags = orig.uidPrivateFlags;
packages = new ArraySet(orig.packages);
// A PackageParser.SigningDetails seems to consist solely of final attributes, so
// A SigningDetails seems to consist solely of final attributes, so
// it is safe to copy the reference.
signatures.mSigningDetails = orig.signatures.mSigningDetails;
signaturesChanged = orig.signaturesChanged;

View File

@@ -487,7 +487,7 @@ class UserSystemPackageInstaller {
/**
* Gets the system package names that should be installed on users of the given user type, as
* determined by SystemConfig, the allowlist mode, and the apps actually on the device.
* Names are the {@link PackageParser.Package#packageName}, not necessarily the manifest names.
* Names are the {@link AndroidPackage#getPackageName()}, not necessarily the manifest names.
*
* Returns null if all system packages should be installed (due to enforce-mode being off).
*/

View File

@@ -22,7 +22,6 @@ import android.annotation.Nullable;
import android.app.ActivityThread;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageParser;
import android.content.pm.parsing.ParsingPackage;
import android.content.pm.parsing.ParsingPackageUtils;
import android.content.pm.parsing.ParsingUtils;
@@ -47,7 +46,7 @@ import java.io.File;
import java.util.List;
/**
* The v2 of {@link PackageParser} for use when parsing is initiated in the server and must
* The v2 of package parsing for use when parsing is initiated in the server and must
* contain state contained by the server.
*
* The {@link AutoCloseable} helps signal that this class contains resources that must be freed.

View File

@@ -31,8 +31,7 @@ import java.util.List;
import java.util.stream.Collectors;
/**
* For use by {@link PackageSetting} to maintain functionality that used to exist in
* {@link PackageParser.Package}.
* For use by {@link PackageSetting} to maintain functionality that used to exist in PackageParser.
*
* It is assumed that anything inside the package was not cached or written to disk, so none of
* these fields are either. They must be set on every boot from other state on the device.

View File

@@ -17,7 +17,8 @@
package com.android.server.pm;
import android.content.pm.PackageParser;
import static android.content.pm.parsing.ParsingPackageUtils.parsePublicKey;
import android.content.pm.Signature;
import android.test.AndroidTestCase;
import android.util.ArrayMap;
@@ -60,11 +61,11 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
assertEquals(0, aliases.size());
}
/* test equivalence of PackageManager cert encoding and PackageParser manifest keys */
/* test equivalence of PackageManager cert encoding and ParsingPackageUtils manifest keys */
public void testPublicKeyCertReprEquiv() throws CertificateException {
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyC = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyC);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyB = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyC = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyC);
Signature sigA = new Signature(KeySetStrings.ctsKeySetCertA);
Signature sigB = new Signature(KeySetStrings.ctsKeySetCertB);
@@ -99,9 +100,9 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
new WatchedArrayMap<String, PackageSetting>();
KeySetManagerService ksms = new KeySetManagerService(packagesMap);
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyC = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyC);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyB = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyC = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyC);
assertEquals(ksms.encodePublicKey(keyA), KeySetStrings.ctsKeySetPublicKeyA);
assertEquals(ksms.encodePublicKey(keyB), KeySetStrings.ctsKeySetPublicKeyB);
@@ -119,7 +120,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect signing key and add */
ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
signingKeys.add(keyA);
mKsms.addSigningKeySetToPackageLPw(ps, signingKeys);
@@ -146,7 +147,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect signing key and add */
ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
signingKeys.add(keyA);
mKsms.addSigningKeySetToPackageLPw(ps, signingKeys);
@@ -176,12 +177,12 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect signing key and add */
ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
signingKeys.add(keyA);
mKsms.addSigningKeySetToPackageLPw(ps, signingKeys);
/* now upgrade with new key */
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyB = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
signingKeys.removeAt(0);
signingKeys.add(keyB);
mKsms.addSigningKeySetToPackageLPw(ps, signingKeys);
@@ -213,13 +214,13 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect signing key and add */
ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
signingKeys.add(keyA);
mKsms.addSigningKeySetToPackageLPw(ps1, signingKeys);
mKsms.addSigningKeySetToPackageLPw(ps2, signingKeys);
/* now upgrade with new key */
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyB = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
signingKeys.removeAt(0);
signingKeys.add(keyB);
mKsms.addSigningKeySetToPackageLPw(ps1, signingKeys);
@@ -256,13 +257,13 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect signing key and add */
ArraySet<PublicKey> signingKeys1 = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
signingKeys1.add(keyA);
mKsms.addSigningKeySetToPackageLPw(ps1, signingKeys1);
/* collect second signing key and add */
ArraySet<PublicKey> signingKeys2 = new ArraySet<PublicKey>();
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyB = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
signingKeys2.add(keyB);
mKsms.addSigningKeySetToPackageLPw(ps2, signingKeys2);
@@ -301,7 +302,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect signing key and add */
ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
signingKeys.add(keyA);
mKsms.addSigningKeySetToPackageLPw(ps1, signingKeys);
@@ -334,12 +335,12 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect signing key and add */
ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
signingKeys.add(keyA);
mKsms.addSigningKeySetToPackageLPw(ps1, signingKeys);
/* give ps2 a superset (add keyB) */
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyB = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
signingKeys.add(keyB);
mKsms.addSigningKeySetToPackageLPw(ps2, signingKeys);
@@ -375,12 +376,12 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect signing key and add */
ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
signingKeys.add(keyA);
mKsms.addSigningKeySetToPackageLPw(ps, signingKeys);
/* now with additional key */
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyB = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
signingKeys.add(keyB);
mKsms.addSigningKeySetToPackageLPw(ps, signingKeys);
@@ -413,7 +414,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect key and add */
ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
keys.add(keyA);
definedKS.put("aliasA", keys);
mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
@@ -440,7 +441,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect key and add */
ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
keys.add(keyA);
definedKS.put("aliasA", keys);
definedKS.put("aliasA2", keys);
@@ -470,14 +471,14 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect key and add */
ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
keys.add(keyA);
definedKS.put("aliasA", keys);
mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
/* now upgrade to different defined key-set */
keys = new ArraySet<PublicKey>();
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyB = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
keys.add(keyB);
definedKS.remove("aliasA");
definedKS.put("aliasB", keys);
@@ -510,14 +511,14 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect key and add */
ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
keys.add(keyA);
definedKS.put("aliasA", keys);
mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
/* now upgrade to different set w/same alias as before */
keys = new ArraySet<PublicKey>();
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyB = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
keys.add(keyB);
definedKS.put("aliasA", keys);
mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
@@ -548,8 +549,8 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
ArraySet<PublicKey> keys1 = new ArraySet<PublicKey>();
ArraySet<PublicKey> keys2 = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyB = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
keys1.add(keyA);
keys2.add(keyB);
definedKS.put("aliasA", keys1);
@@ -558,7 +559,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* now upgrade to different set (B, C) */
keys1 = new ArraySet<PublicKey>();
PublicKey keyC = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyC);
PublicKey keyC = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyC);
keys1.add(keyC);
definedKS.remove("aliasA");
definedKS.put("aliasC", keys1);
@@ -612,14 +613,14 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect key and add */
ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
ArraySet<PublicKey> keys1 = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
keys1.add(keyA);
definedKS.put("aliasA", keys1);
mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
/* now upgrade to different set */
ArraySet<PublicKey> keys2 = new ArraySet<PublicKey>();
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyB = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
keys2.add(keyB);
definedKS.remove("aliasA");
definedKS.put("aliasB", keys2);
@@ -655,7 +656,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect key and add, and denote as an upgrade keyset */
ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
keys.add(keyA);
definedKS.put("aliasA", keys);
mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
@@ -677,7 +678,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect key and add and try to specify bogus upgrade keyset */
ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
keys.add(keyA);
definedKS.put("aliasA", keys);
mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
@@ -704,7 +705,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect key and add */
ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
keys.add(keyA);
definedKS.put("aliasA", keys);
mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
@@ -713,7 +714,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
mKsms.addUpgradeKeySetsToPackageLPw(ps, upgradeKS);
keys = new ArraySet<PublicKey>();
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyB = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
keys.add(keyB);
definedKS.remove("aliasA");
definedKS.put("aliasB", keys);
@@ -730,7 +731,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect signing key and add */
ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
signingKeys.add(keyA);
mKsms.addSigningKeySetToPackageLPw(ps, signingKeys);
@@ -755,7 +756,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect signing key and add for both packages */
ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
signingKeys.add(keyA);
mKsms.addSigningKeySetToPackageLPw(ps1, signingKeys);
mKsms.addSigningKeySetToPackageLPw(ps2, signingKeys);
@@ -781,7 +782,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase {
/* collect key and add */
ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
keys.add(keyA);
/* removal requires signing keyset to be specified (since all apps are

View File

@@ -22,6 +22,7 @@ import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
import static android.content.pm.SuspendDialogInfo.BUTTON_ACTION_MORE_DETAILS;
import static android.content.pm.SuspendDialogInfo.BUTTON_ACTION_UNSUSPEND;
import static android.content.pm.parsing.ParsingPackageUtils.parsePublicKey;
import static android.content.res.Resources.ID_NULL;
import static org.hamcrest.CoreMatchers.is;
@@ -39,7 +40,6 @@ import android.annotation.NonNull;
import android.app.PropertyInvalidatedCache;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
import android.content.pm.PackageUserState;
import android.content.pm.SuspendDialogInfo;
import android.content.pm.UserInfo;
@@ -1216,9 +1216,9 @@ public class PackageManagerSettingsTests {
assertThat(KeySetUtils.getPubKeyRefCount(ksms, 3), is(1));
/* verify public keys properly read */
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyC = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyC);
PublicKey keyA = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyB = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyC = parsePublicKey(KeySetStrings.ctsKeySetPublicKeyC);
assertThat(KeySetUtils.getPubKey(ksms, 1), is(keyA));
assertThat(KeySetUtils.getPubKey(ksms, 2), is(keyB));
assertThat(KeySetUtils.getPubKey(ksms, 3), is(keyC));

View File

@@ -29,6 +29,7 @@ import android.content.pm.PackageUserState
import android.content.pm.PermissionInfo
import android.content.pm.ProviderInfo
import android.content.pm.ServiceInfo
import android.content.pm.parsing.ParsingPackageUtils
import android.os.Bundle
import android.os.Debug
import android.os.Environment
@@ -109,7 +110,7 @@ open class AndroidPackageParsingTestBase {
apks.mapNotNull {
try {
packageParser.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false) to
packageParser2.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR,
packageParser2.parsePackage(it, ParsingPackageUtils.PARSE_IS_SYSTEM_DIR,
false)
} catch (ignored: Exception) {
// It is intentional that a failure of either call here will result in failing