summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Songchun Fan <schfan@google.com> 2020-01-22 18:40:19 -0800
committer Alex Buynytskyy <alexbuy@google.com> 2020-02-06 05:26:16 +0000
commit476bcf76ac58a28157b71637b5f18ea90282b0f4 (patch)
tree34d50bf1ea0c582acebf34a1a38a190fe9b9d54a
parentc69e256934517f0c3dca1c223c7f2a3d17ac8bce (diff)
Set incremental apk directories
Set up incremental storages such that it works with the new app code path layout. Ensures that package names do not show up in /proc/mounts $ cat /proc/self/mountinfo 2806 90 0:79 / /data/incremental/data_incremental_tmp_1042476774/mount rw,nosuid,nodev,noatime shared:34 - incremental-fs incfs.img rw,read_timeout_ms=10000,readahead=0,rlog_pages=2,rlog_wakeup_cnt=10 6946 90 0:79 /st2 /data/app/~~WE4d9B-MZg0iZckOxIhPGQ== rw,nosuid,nodev,noatime shared:34 - incremental-fs incfs.img rw,read_timeout_ms=10000,readahead=0,rlog_pages=2,rlog_wakeup_cnt=10 7014 2806 0:79 /st2 /data/incremental/data_incremental_tmp_1042476774/mount/st2 rw,nosuid,nodev,noatime shared:34 - incremental-fs incfs.img rw,read_timeout_ms=10000,readahead=0,rlog_pages=2,rlog_wakeup_cnt=10 7013 6946 0:79 /st2 /data/app/~~WE4d9B-MZg0iZckOxIhPGQ== rw,nosuid,nodev,noatime shared:34 - incremental-fs incfs.img rw,read_timeout_ms=10000,readahead=0,rlog_pages=2,rlog_wakeup_cnt=10 BUG: b/147371381 b/148237378 Test: manual Change-Id: I149903ae63ee27da5957e41c16f21f3435f9e636
-rw-r--r--core/java/android/os/incremental/IncrementalManager.java142
-rw-r--r--services/core/java/com/android/server/pm/PackageManagerService.java4
2 files changed, 40 insertions, 106 deletions
diff --git a/core/java/android/os/incremental/IncrementalManager.java b/core/java/android/os/incremental/IncrementalManager.java
index 8990bdf06a6f..35fa37a491de 100644
--- a/core/java/android/os/incremental/IncrementalManager.java
+++ b/core/java/android/os/incremental/IncrementalManager.java
@@ -23,8 +23,6 @@ import android.annotation.SystemService;
import android.content.Context;
import android.content.pm.DataLoaderParams;
import android.os.RemoteException;
-import android.system.ErrnoException;
-import android.system.Os;
import android.util.SparseArray;
import com.android.internal.annotations.GuardedBy;
@@ -193,116 +191,54 @@ public final class IncrementalManager {
}
/**
- * Renames an Incremental path to a new path. If source path is a file, make a link from the old
- * Incremental file to the new one. If source path is a dir, unbind old dir from Incremental
- * Storage and bind the new one.
- * <ol>
- * <li> For renaming a dir, dest dir will be created if not exists, and does not need to
- * be on the same Incremental storage as the source. </li>
- * <li> For renaming a file, dest file must be on the same Incremental storage as source.
- * </li>
- * </ol>
+ * Set up an app's code path. The expected outcome of this method is:
+ * 1) The actual apk directory under /data/incremental is bind-mounted to the parent directory
+ * of {@code afterCodeFile}.
+ * 2) All the files under {@code beforeCodeFile} will show up under {@code afterCodeFile}.
*
- * @param sourcePath Absolute path to the source. Should be the same type as the destPath (file
- * or dir). Expected to already exist and is an Incremental path.
- * @param destPath Absolute path to the destination.
- * @throws IllegalArgumentException when 1) source does not exist, or 2) source and dest type
- * mismatch (one is file and the other is dir), or 3) source
- * path is not on Incremental File System,
- * @throws IOException when 1) cannot find the root path of the Incremental storage
- * of source, or 2) cannot retrieve the Incremental storage
- * instance of the source, or 3) renaming a file, but dest is
- * not on the same Incremental Storage, or 4) renaming a dir,
- * dest dir does not exist but fails to be created.
- * <p>
- * TODO(b/136132412): add unit tests
+ * @param beforeCodeFile Path that is currently bind-mounted and have APKs under it.
+ * Should no longer have any APKs after this method is called.
+ * Example: /data/app/vmdl*tmp
+ * @param afterCodeFile Path that should will have APKs after this method is called. Its parent
+ * directory should be bind-mounted to a directory under /data/incremental.
+ * Example: /data/app/~~[randomStringA]/[packageName]-[randomStringB]
+ * @throws IllegalArgumentException
+ * @throws IOException
+ * TODO(b/147371381): add unit tests
*/
- public void rename(@NonNull String sourcePath, @NonNull String destPath) throws IOException {
- final File source = new File(sourcePath);
- final File dest = new File(destPath);
- if (!source.exists()) {
- throw new IllegalArgumentException("Path not exist: " + sourcePath);
+ public void renameCodePath(File beforeCodeFile, File afterCodeFile)
+ throws IllegalArgumentException, IOException {
+ final String beforeCodePath = beforeCodeFile.getAbsolutePath();
+ final String afterCodePathParent = afterCodeFile.getParentFile().getAbsolutePath();
+ if (!isIncrementalPath(beforeCodePath)) {
+ throw new IllegalArgumentException("Not an Incremental path: " + beforeCodePath);
}
- if (dest.exists()) {
- throw new IllegalArgumentException("Target path already exists: " + destPath);
+ final String afterCodePathName = afterCodeFile.getName();
+ final Path apkStoragePath = Paths.get(beforeCodePath);
+ if (apkStoragePath == null || apkStoragePath.toAbsolutePath() == null) {
+ throw new IOException("Invalid source storage path for: " + beforeCodePath);
}
- if (source.isDirectory() && dest.exists() && dest.isFile()) {
- throw new IllegalArgumentException(
- "Trying to rename a dir but destination is a file: " + destPath);
- }
- if (source.isFile() && dest.exists() && dest.isDirectory()) {
- throw new IllegalArgumentException(
- "Trying to rename a file but destination is a dir: " + destPath);
- }
- if (!isIncrementalPath(sourcePath)) {
- throw new IllegalArgumentException("Not an Incremental path: " + sourcePath);
- }
-
- Path storagePath = Paths.get(sourcePath);
- if (source.isFile()) {
- storagePath = getStoragePathForFile(source);
- }
- if (storagePath == null || storagePath.toAbsolutePath() == null) {
- throw new IOException("Invalid source storage path for: " + sourcePath);
- }
- final IncrementalStorage storage = openStorage(storagePath.toAbsolutePath().toString());
- if (storage == null) {
+ final IncrementalStorage apkStorage =
+ openStorage(apkStoragePath.toAbsolutePath().toString());
+ if (apkStorage == null) {
throw new IOException("Failed to retrieve storage from Incremental Service.");
}
-
- if (source.isFile()) {
- renameFile(storage, storagePath, source, dest);
- } else {
- renameDir(storage, storagePath, source, dest);
- }
- }
-
- private void renameFile(IncrementalStorage storage, Path storagePath,
- File source, File dest) throws IOException {
- Path sourcePath = source.toPath();
- Path destPath = dest.toPath();
- if (!sourcePath.startsWith(storagePath)) {
- throw new IOException("Path: " + source.getAbsolutePath() + " is not on storage at: "
- + storagePath.toString());
- }
- if (!destPath.startsWith(storagePath)) {
- throw new IOException("Path: " + dest.getAbsolutePath() + " is not on storage at: "
- + storagePath.toString());
+ final IncrementalStorage linkedApkStorage = createStorage(afterCodePathParent, apkStorage,
+ IncrementalManager.CREATE_MODE_CREATE
+ | IncrementalManager.CREATE_MODE_PERMANENT_BIND);
+ if (linkedApkStorage == null) {
+ throw new IOException("Failed to create linked storage at dir: " + afterCodePathParent);
}
- final Path sourceRelativePath = storagePath.relativize(sourcePath);
- final Path destRelativePath = storagePath.relativize(destPath);
- storage.moveFile(sourceRelativePath.toString(), destRelativePath.toString());
-
- }
-
- private void renameDir(IncrementalStorage storage, Path storagePath,
- File source, File dest) throws IOException {
- Path destPath = dest.toPath();
- boolean usedMkdir = false;
- try {
- Os.mkdir(dest.getAbsolutePath(), 0755);
- usedMkdir = true;
- } catch (ErrnoException e) {
- // Traditional mkdir fails but maybe we can create it on Incremental File System if
- // the dest path is on the same Incremental storage as the source.
- if (destPath.startsWith(storagePath)) {
- storage.makeDirectories(storagePath.relativize(destPath).toString());
- } else {
- throw new IOException("Failed to create directory: " + dest.getAbsolutePath(), e);
- }
- }
- try {
- storage.moveDir(source.getAbsolutePath(), dest.getAbsolutePath());
- } catch (Exception ex) {
- if (usedMkdir) {
- try {
- Os.remove(dest.getAbsolutePath());
- } catch (ErrnoException ignored) {
- }
+ linkedApkStorage.makeDirectory(afterCodePathName);
+ File[] files = beforeCodeFile.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isFile()) {
+ String fileName = files[i].getName();
+ apkStorage.makeLink(
+ fileName, linkedApkStorage, afterCodePathName + "/" + fileName);
}
- throw new IOException(
- "Failed to move " + source.getAbsolutePath() + " to " + dest.getAbsolutePath());
}
+ apkStorage.unBind(beforeCodePath);
}
/**
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index c14b42dd69c8..541ac0cf871c 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -14983,9 +14983,7 @@ public class PackageManagerService extends IPackageManager.Stub
try {
makeDirRecursive(afterCodeFile.getParentFile(), 0775);
if (onIncremental) {
- // TODO(b/147371381): fix incremental installation
- mIncrementalManager.rename(beforeCodeFile.getAbsolutePath(),
- afterCodeFile.getAbsolutePath());
+ mIncrementalManager.renameCodePath(beforeCodeFile, afterCodeFile);
} else {
Os.rename(beforeCodeFile.getAbsolutePath(), afterCodeFile.getAbsolutePath());
}