OSDN Git Service

Skip legacy-fs-verity setup if file already has it
authorVictor Hsieh <victorhsieh@google.com>
Fri, 31 May 2019 18:07:28 +0000 (11:07 -0700)
committerVictor Hsieh <victorhsieh@google.com>
Mon, 3 Jun 2019 21:57:47 +0000 (21:57 +0000)
Test: 1. put com.foo.apk in /system/priv-app
      2. adb install-multiple -r -p com.foo split.apk
      3. adb install-multiple -r -p com.foo split.apk (second time, only
         succeed with this change)
Test: update a priv app (no regression)
Bug: 129509604
Change-Id: I591dd4504e3ba6f1499ebd045dc4f1adbd88d4e3

services/core/java/com/android/server/pm/PackageManagerService.java

index 5958715..4a5e61b 100644 (file)
@@ -18050,9 +18050,15 @@ public class PackageManagerService extends IPackageManager.Stub
                 if (Build.IS_DEBUGGABLE) Slog.i(TAG, "Enabling verity to " + filePath);
                 final FileDescriptor fd = result.getUnownedFileDescriptor();
                 try {
-                    mInstaller.installApkVerity(filePath, fd, result.getContentSize());
                     final byte[] rootHash = VerityUtils.generateApkVerityRootHash(filePath);
-                    mInstaller.assertFsverityRootHashMatches(filePath, rootHash);
+                    try {
+                        // A file may already have fs-verity, e.g. when reused during a split
+                        // install. If the measurement succeeds, no need to attempt to set up.
+                        mInstaller.assertFsverityRootHashMatches(filePath, rootHash);
+                    } catch (InstallerException e) {
+                        mInstaller.installApkVerity(filePath, fd, result.getContentSize());
+                        mInstaller.assertFsverityRootHashMatches(filePath, rootHash);
+                    }
                 } finally {
                     IoUtils.closeQuietly(fd);
                 }