summaryrefslogtreecommitdiff
path: root/core/java/android/content
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/content')
-rw-r--r--core/java/android/content/pm/PackageInfo.java10
-rw-r--r--core/java/android/content/pm/PackageParser.java38
2 files changed, 38 insertions, 10 deletions
diff --git a/core/java/android/content/pm/PackageInfo.java b/core/java/android/content/pm/PackageInfo.java
index 3a77a6a269dc..6d22277a5384 100644
--- a/core/java/android/content/pm/PackageInfo.java
+++ b/core/java/android/content/pm/PackageInfo.java
@@ -18,7 +18,6 @@ package android.content.pm;
import android.annotation.Nullable;
import android.annotation.UnsupportedAppUsage;
-import android.apex.ApexInfo;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
@@ -578,15 +577,6 @@ public class PackageInfo implements Parcelable {
}
}
- /**
- * @hide
- */
- public PackageInfo(ApexInfo apexInfo) {
- packageName = apexInfo.packageName;
- setLongVersionCode(apexInfo.versionCode);
- isApex = true;
- }
-
private void propagateApplicationInfo(ApplicationInfo appInfo, ComponentInfo[] components) {
if (components != null) {
for (ComponentInfo ci : components) {
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 5e15b009c39f..a185c8a60f9b 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -8490,4 +8490,42 @@ public class PackageParser {
this.error = error;
}
}
+
+ public static PackageInfo generatePackageInfoFromApex(File apexFile, boolean collectCerts)
+ throws PackageParserException {
+ PackageInfo pi = new PackageInfo();
+ // TODO(b/123052859): We should avoid these repeated calls to parseApkLite each time
+ // we want to generate information for APEX modules.
+ PackageParser.ApkLite apk = PackageParser.parseApkLite(apexFile,
+ collectCerts ? PackageParser.PARSE_COLLECT_CERTIFICATES : 0);
+
+ pi.packageName = apk.packageName;
+ pi.setLongVersionCode(apk.getLongVersionCode());
+
+ if (collectCerts) {
+ if (apk.signingDetails.hasPastSigningCertificates()) {
+ // Package has included signing certificate rotation information. Return
+ // the oldest cert so that programmatic checks keep working even if unaware
+ // of key rotation.
+ pi.signatures = new Signature[1];
+ pi.signatures[0] = apk.signingDetails.pastSigningCertificates[0];
+ } else if (apk.signingDetails.hasSignatures()) {
+ // otherwise keep old behavior
+ int numberOfSigs = apk.signingDetails.signatures.length;
+ pi.signatures = new Signature[numberOfSigs];
+ System.arraycopy(apk.signingDetails.signatures, 0, pi.signatures, 0,
+ numberOfSigs);
+ }
+
+ if (apk.signingDetails != SigningDetails.UNKNOWN) {
+ // only return a valid SigningInfo if there is signing information to report
+ pi.signingInfo = new SigningInfo(apk.signingDetails);
+ } else {
+ pi.signingInfo = null;
+ }
+ }
+
+ pi.isApex = true;
+ return pi;
+ }
}