From 050b79975b1a8031acbab61cdd2b2c220efc4217 Mon Sep 17 00:00:00 2001 From: Dan Cashman Date: Tue, 6 Feb 2018 17:08:58 -0800 Subject: [PATCH] PackageInfo: add Parcel read/write for cert history. commit: 5cdda3425ccf3c62e400a1646615f4479a8266af added a new flag, GET_SIGNING_CERTIFICATES to PackageManager for use with getPackageInfo that returns the signing certificate history, including the current signer, of the given package. This is intended to replace the existing GET_SIGNATURES flag and corresponding field. The previous commit did not, however, implement the read/write Parcelable methods so that this information could be reconstructed client side. Implement those methods to actually expose the new API. Bug: 64686581 Test: Test app pull of PackageInfo with GET_SIGNING_CERTIFICATES succeeds. Change-Id: I1c023da2a6fd03e11432953080045a79b9f56839 --- core/java/android/content/pm/PackageInfo.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/java/android/content/pm/PackageInfo.java b/core/java/android/content/pm/PackageInfo.java index 09a46b8acf4ba..0342c93bb34ff 100644 --- a/core/java/android/content/pm/PackageInfo.java +++ b/core/java/android/content/pm/PackageInfo.java @@ -468,6 +468,18 @@ public class PackageInfo implements Parcelable { dest.writeBoolean(mOverlayIsStatic); dest.writeInt(compileSdkVersion); dest.writeString(compileSdkVersionCodename); + writeSigningCertificateHistoryToParcel(dest, parcelableFlags); + } + + private void writeSigningCertificateHistoryToParcel(Parcel dest, int parcelableFlags) { + if (signingCertificateHistory != null) { + dest.writeInt(signingCertificateHistory.length); + for (int i = 0; i < signingCertificateHistory.length; i++) { + dest.writeTypedArray(signingCertificateHistory[i], parcelableFlags); + } + } else { + dest.writeInt(-1); + } } public static final Parcelable.Creator CREATOR @@ -523,6 +535,7 @@ public class PackageInfo implements Parcelable { mOverlayIsStatic = source.readBoolean(); compileSdkVersion = source.readInt(); compileSdkVersionCodename = source.readString(); + readSigningCertificateHistoryFromParcel(source); // The component lists were flattened with the redundant ApplicationInfo // instances omitted. Distribute the canonical one here as appropriate. @@ -534,6 +547,16 @@ public class PackageInfo implements Parcelable { } } + private void readSigningCertificateHistoryFromParcel(Parcel source) { + int len = source.readInt(); + if (len != -1) { + signingCertificateHistory = new Signature[len][]; + for (int i = 0; i < len; i++) { + signingCertificateHistory[i] = source.createTypedArray(Signature.CREATOR); + } + } + } + private void propagateApplicationInfo(ApplicationInfo appInfo, ComponentInfo[] components) { if (components != null) { for (ComponentInfo ci : components) {