From 39de85b953d3264de774db5690c4ef630b0ecf20 Mon Sep 17 00:00:00 2001 From: Victor Hsieh Date: Tue, 29 Nov 2022 12:10:51 -0800 Subject: Reland: Enable fs-verity in background thread The previous attempt was reverted due to CTS failure. The workaround is implemented in the test since the API contract isn't broken. In this reland, avoid running a custom thread by leverage the existing background handler. Bug: 259179666 Test: on cuttlefish, run ChecksumsTest#testInstallerSignedChecksumsUpdate Change-Id: Ie88ae3b219e904c0cd9f85b7eb31ac21e56e36d5 --- .../android/server/pm/InstallPackageHelper.java | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/services/core/java/com/android/server/pm/InstallPackageHelper.java b/services/core/java/com/android/server/pm/InstallPackageHelper.java index 283640d7613a..f96d6636fb2b 100644 --- a/services/core/java/com/android/server/pm/InstallPackageHelper.java +++ b/services/core/java/com/android/server/pm/InstallPackageHelper.java @@ -2259,20 +2259,26 @@ final class InstallPackageHelper { incrementalStorages.add(storage); } - try { - if (!VerityUtils.hasFsverity(pkg.getBaseApkPath())) { - VerityUtils.setUpFsverity(pkg.getBaseApkPath(), (byte[]) null); - } - for (String path : pkg.getSplitCodePaths()) { - if (!VerityUtils.hasFsverity(path)) { - VerityUtils.setUpFsverity(path, (byte[]) null); + // Enabling fs-verity is a blocking operation. To reduce the impact to the install time, + // run in a background thread. + final ArrayList apkPaths = new ArrayList<>(); + apkPaths.add(pkg.getBaseApkPath()); + if (pkg.getSplitCodePaths() != null) { + Collections.addAll(apkPaths, pkg.getSplitCodePaths()); + } + mInjector.getBackgroundHandler().post(() -> { + try { + for (String path : apkPaths) { + if (!VerityUtils.hasFsverity(path)) { + VerityUtils.setUpFsverity(path, (byte[]) null); + } } + } catch (IOException e) { + // There's nothing we can do if the setup failed. Since fs-verity is + // optional, just ignore the error for now. + Slog.e(TAG, "Failed to fully enable fs-verity to " + packageName); } - } catch (IOException e) { - // There's nothing we can do if the setup failed. Since fs-verity is - // optional, just ignore the error for now. - Slog.e(TAG, "Failed to fully enable fs-verity to " + packageName); - } + }); // Hardcode previousAppId to 0 to disable any data migration (http://b/221088088) mAppDataHelper.prepareAppDataPostCommitLIF(pkg, 0); -- cgit v1.2.3-59-g8ed1b