BinaryTransparencyService: Fix printPackageInstallationInfo

It seems that APEX_PRELOAD_LOCATION_ERROR is consistently returned
as the value of original APEX location when calling
`getOriginalApexPreinstalledLocation` when preloaded APEXs are
compressed.

While this change does not address the root issue of why that is
the case, it prevents the error value to be used as a legitimate
path to compute digests for by guarding the control flow based on
sane values of apex install location.

Bug: 264925790
Test: Manual.
	adb shell cmd transparency get apex_info -v
Change-Id: I924ba889cb6d11a874cf06ca8692f8320b86b588
This commit is contained in:
Billy Lau
2023-01-10 14:13:20 -06:00
parent 565b61b9c6
commit 0000111103

View File

@@ -531,27 +531,30 @@ public class BinaryTransparencyService extends SystemService {
pw.println("|--> Pre-installed package install location: "
+ origPackageFilepath);
if (useSha256) {
String sha256Digest = PackageUtils.computeSha256DigestForLargeFile(
origPackageFilepath, PackageUtils.createLargeFileBuffer());
pw.println("|--> Pre-installed package SHA-256 digest: "
+ sha256Digest);
}
if (!origPackageFilepath.equals(APEX_PRELOAD_LOCATION_ERROR)) {
if (useSha256) {
String sha256Digest = PackageUtils.computeSha256DigestForLargeFile(
origPackageFilepath, PackageUtils.createLargeFileBuffer());
pw.println("|--> Pre-installed package SHA-256 digest: "
+ sha256Digest);
}
Map<Integer, byte[]> contentDigests = computeApkContentDigest(
origPackageFilepath);
if (contentDigests == null) {
pw.println("ERROR: Failed to compute package content digest for "
+ origPackageFilepath);
} else {
for (Map.Entry<Integer, byte[]> entry : contentDigests.entrySet()) {
Integer algorithmId = entry.getKey();
byte[] contentDigest = entry.getValue();
pw.println("|--> Pre-installed package content digest: "
+ HexEncoding.encodeToString(contentDigest, false));
pw.println("|--> Pre-installed package content digest algorithm: "
+ translateContentDigestAlgorithmIdToString(algorithmId));
Map<Integer, byte[]> contentDigests = computeApkContentDigest(
origPackageFilepath);
if (contentDigests == null) {
pw.println("|--> ERROR: Failed to compute package content digest "
+ "for " + origPackageFilepath);
} else {
for (Map.Entry<Integer, byte[]> entry : contentDigests.entrySet()) {
Integer algorithmId = entry.getKey();
byte[] contentDigest = entry.getValue();
pw.println("|--> Pre-installed package content digest: "
+ HexEncoding.encodeToString(contentDigest, false));
pw.println("|--> Pre-installed package content digest "
+ "algorithm: "
+ translateContentDigestAlgorithmIdToString(
algorithmId));
}
}
}
}