From b4ffbd0d3b797a26b4c926104829f70d47884e59 Mon Sep 17 00:00:00 2001 From: Billy Lau Date: Wed, 9 Feb 2022 18:34:58 -0800 Subject: [PATCH] Compute SHA256 digest of binaries asynchronously post boot. Instead of waiting until first invocation of commandline, we will execute the computation of SHA256 digest of APEXs and Modules in a separate thread post boot (to not hold up boot time). This allows the logging of APEX information to statsd to happen once every reboot. Otherwise, logging may never occur if the users never make use of the commandline. Bug: 217469982 Test: Manual. `adb shell cmd transparency get apex_info` no longer has latency upon first invocation. Change-Id: I1f09316f5b7cde1795dc49456bae97362e30d5c6 --- .../android/server/BinaryTransparencyService.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/BinaryTransparencyService.java b/services/core/java/com/android/server/BinaryTransparencyService.java index 91d2f55519a6a..6c220f6f9503f 100644 --- a/services/core/java/com/android/server/BinaryTransparencyService.java +++ b/services/core/java/com/android/server/BinaryTransparencyService.java @@ -45,6 +45,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.Executors; import java.util.stream.Collectors; /** @@ -369,10 +370,13 @@ public class BinaryTransparencyService extends SystemService { // we are only interested in doing things at PHASE_BOOT_COMPLETED if (phase == PHASE_BOOT_COMPLETED) { - // due to potentially long computation that holds up boot time, apex sha computations - // are deferred to first call Slog.i(TAG, "Boot completed. Getting VBMeta Digest."); getVBMetaDigestInformation(); + + // due to potentially long computation that may hold up boot time, SHA256 computations + // for APEXs and Modules will be executed via threads. + Slog.i(TAG, "Executing APEX & Module digest computations"); + computeApexAndModuleDigests(); } } @@ -382,6 +386,12 @@ public class BinaryTransparencyService extends SystemService { FrameworkStatsLog.write(FrameworkStatsLog.VBMETA_DIGEST_REPORTED, mVbmetaDigest); } + private void computeApexAndModuleDigests() { + // using Executors will allow the computations to be done asynchronously, thus not holding + // up boot time. + Executors.defaultThreadFactory().newThread(() -> updateBinaryMeasurements()).start(); + } + @NonNull private List getInstalledApexs() { List results = new ArrayList();