Enable fs-verity in background thread

This is another attempt to reduce the install time impact.

Bug: 259179666
Test: m
Change-Id: I964f463e7c2e03fcce3b0865f1a7062f2b28f5b9
This commit is contained in:
Victor Hsieh
2022-11-29 12:10:51 -08:00
parent c2665dd82f
commit 03a0c6c737

View File

@@ -2228,20 +2228,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.
new Thread("fsverity-setup") {
@Override public void run() {
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);
}
}
} 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);
}
}.start();
// Hardcode previousAppId to 0 to disable any data migration (http://b/221088088)
mAppDataHelper.prepareAppDataPostCommitLIF(pkg, 0);