summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorSudheer Shanka <sudheersai@google.com>2018-09-18 13:07:59 -0700
committerSudheer Shanka <sudheersai@google.com>2018-09-27 14:43:45 -0700
commit3f0645ba835111d3df9fe2ceac8aa8e456f604c2 (patch)
tree44ff42e6ebba6d15f022815a565e054eee345016 /core/java
parent2925bdd35a4a4db4362057798bf352ec9157f26f (diff)
Bind mount pkg specific dirs in the zygote child namespaces.
- Also update vold to create sandboxes for secondary storage devices. - Since bind mounts are created in the process specific namespaces, we don't need /mnt/storage anymore which we were using it to prevent some bind mounts from propagating onto /mnt/runtime/write. - Create bind mounts for {media,obb} dirs similar to data dir in per process namespace. - Also fix a bug where we are not passing correct packages to vold when a new user starts. Bug: 111890351 Test: manual Change-Id: I1abbafabc58993860305e5a928c980420f89f289
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/os/Process.java12
-rw-r--r--core/java/android/os/ZygoteProcess.java39
-rw-r--r--core/java/android/os/storage/StorageManagerInternal.java7
-rw-r--r--core/java/android/os/storage/VolumeInfo.java2
-rw-r--r--core/java/com/android/internal/os/Zygote.java15
-rw-r--r--core/java/com/android/internal/os/ZygoteConnection.java13
6 files changed, 74 insertions, 14 deletions
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 6fab3c412ae5..0f64c4531bc3 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -483,6 +483,8 @@ public class Process {
* @param appDataDir null-ok the data directory of the app.
* @param invokeWith null-ok the command to invoke with.
* @param packageName null-ok the name of the package this process belongs to.
+ * @param packagesForUid null-ok all the packages with the same uid as this process.
+ * @param visibleVols null-ok storage volumes that can be accessed by this process.
* @param zygoteArgs Additional arguments to supply to the zygote process.
*
* @return An object that describes the result of the attempt to start the process.
@@ -501,10 +503,13 @@ public class Process {
@Nullable String appDataDir,
@Nullable String invokeWith,
@Nullable String packageName,
+ @Nullable String[] packagesForUid,
+ @Nullable String[] visibleVols,
@Nullable String[] zygoteArgs) {
return zygoteProcess.start(processClass, niceName, uid, gid, gids,
runtimeFlags, mountExternal, targetSdkVersion, seInfo,
- abi, instructionSet, appDataDir, invokeWith, packageName, zygoteArgs);
+ abi, instructionSet, appDataDir, invokeWith, packageName,
+ packagesForUid, visibleVols, zygoteArgs);
}
/** @hide */
@@ -519,10 +524,13 @@ public class Process {
@Nullable String appDataDir,
@Nullable String invokeWith,
@Nullable String packageName,
+ @Nullable String[] packagesForUid,
+ @Nullable String[] visibleVols,
@Nullable String[] zygoteArgs) {
return WebViewZygote.getProcess().start(processClass, niceName, uid, gid, gids,
runtimeFlags, mountExternal, targetSdkVersion, seInfo,
- abi, instructionSet, appDataDir, invokeWith, packageName, zygoteArgs);
+ abi, instructionSet, appDataDir, invokeWith, packageName,
+ packagesForUid, visibleVols, zygoteArgs);
}
/**
diff --git a/core/java/android/os/ZygoteProcess.java b/core/java/android/os/ZygoteProcess.java
index 99181acb03c7..7fd0a4b66d66 100644
--- a/core/java/android/os/ZygoteProcess.java
+++ b/core/java/android/os/ZygoteProcess.java
@@ -215,6 +215,8 @@ public class ZygoteProcess {
* @param appDataDir null-ok the data directory of the app.
* @param invokeWith null-ok the command to invoke with.
* @param packageName null-ok the name of the package this process belongs to.
+ * @param packagesForUid null-ok all the packages with the same uid as this process.
+ * @param visibleVols null-ok storage volumes that can be accessed by this process.
* @param zygoteArgs Additional arguments to supply to the zygote process.
*
* @return An object that describes the result of the attempt to start the process.
@@ -231,12 +233,14 @@ public class ZygoteProcess {
@Nullable String appDataDir,
@Nullable String invokeWith,
@Nullable String packageName,
+ @Nullable String[] packagesForUid,
+ @Nullable String[] visibleVols,
@Nullable String[] zygoteArgs) {
try {
return startViaZygote(processClass, niceName, uid, gid, gids,
runtimeFlags, mountExternal, targetSdkVersion, seInfo,
abi, instructionSet, appDataDir, invokeWith, false /* startChildZygote */,
- packageName, zygoteArgs);
+ packageName, packagesForUid, visibleVols, zygoteArgs);
} catch (ZygoteStartFailedEx ex) {
Log.e(LOG_TAG,
"Starting VM process through Zygote failed");
@@ -355,6 +359,8 @@ public class ZygoteProcess {
* @param startChildZygote Start a sub-zygote. This creates a new zygote process
* that has its state cloned from this zygote process.
* @param packageName null-ok the name of the package this process belongs to.
+ * @param packagesForUid null-ok all the packages with the same uid as this process.
+ * @param visibleVols null-ok storage volumes that can be accessed by this process.
* @param extraArgs Additional arguments to supply to the zygote process.
* @return An object that describes the result of the attempt to start the process.
* @throws ZygoteStartFailedEx if process start failed for any reason
@@ -372,6 +378,8 @@ public class ZygoteProcess {
@Nullable String invokeWith,
boolean startChildZygote,
@Nullable String packageName,
+ @Nullable String[] packagesForUid,
+ @Nullable String[] visibleVols,
@Nullable String[] extraArgs)
throws ZygoteStartFailedEx {
ArrayList<String> argsForZygote = new ArrayList<String>();
@@ -439,6 +447,32 @@ public class ZygoteProcess {
argsForZygote.add("--package-name=" + packageName);
}
+ if (packagesForUid != null && packagesForUid.length > 0) {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("--packages-for-uid=");
+
+ for (int i = 0; i < packagesForUid.length; ++i) {
+ if (i != 0) {
+ sb.append(',');
+ }
+ sb.append(packagesForUid[i]);
+ }
+ argsForZygote.add(sb.toString());
+ }
+
+ if (visibleVols != null && visibleVols.length > 0) {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("--visible-vols=");
+
+ for (int i = 0; i < visibleVols.length; ++i) {
+ if (i != 0) {
+ sb.append(',');
+ }
+ sb.append(visibleVols[i]);
+ }
+ argsForZygote.add(sb.toString());
+ }
+
argsForZygote.add(processClass);
if (extraArgs != null) {
@@ -746,7 +780,8 @@ public class ZygoteProcess {
result = startViaZygote(processClass, niceName, uid, gid,
gids, runtimeFlags, 0 /* mountExternal */, 0 /* targetSdkVersion */, seInfo,
abi, instructionSet, null /* appDataDir */, null /* invokeWith */,
- true /* startChildZygote */, null /* packageName */, extraArgs);
+ true /* startChildZygote */, null /* packageName */,
+ null /* packagesForUid */, null /* visibleVolumes */, extraArgs);
} catch (ZygoteStartFailedEx ex) {
throw new RuntimeException("Starting child-zygote through Zygote failed", ex);
}
diff --git a/core/java/android/os/storage/StorageManagerInternal.java b/core/java/android/os/storage/StorageManagerInternal.java
index d850e27e913f..1f54ea53facc 100644
--- a/core/java/android/os/storage/StorageManagerInternal.java
+++ b/core/java/android/os/storage/StorageManagerInternal.java
@@ -89,8 +89,13 @@ public abstract class StorageManagerInternal {
* @param appId The appId for the given package.
* @param sharedUserId The sharedUserId for given package if it specified
* {@code android:sharedUserId} in the manifest, otherwise {@code null}
- * @param userId
+ * @param userId The userId in which the storage needs to be mounted.
*/
public abstract void mountExternalStorageForApp(String packageName, int appId,
String sharedUserId, int userId);
+
+ /**
+ * @return Labels of storage volumes that are visible to the given userId.
+ */
+ public abstract String[] getVisibleVolumesForUser(int userId);
}
diff --git a/core/java/android/os/storage/VolumeInfo.java b/core/java/android/os/storage/VolumeInfo.java
index afd383691300..e55afb69bab9 100644
--- a/core/java/android/os/storage/VolumeInfo.java
+++ b/core/java/android/os/storage/VolumeInfo.java
@@ -157,7 +157,7 @@ public class VolumeInfo implements Parcelable {
public final DiskInfo disk;
public final String partGuid;
public int mountFlags = 0;
- public int mountUserId = -1;
+ public int mountUserId = UserHandle.USER_NULL;
@UnsupportedAppUsage
public int state = STATE_UNMOUNTED;
public String fsType;
diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.java
index 927322e97e28..98b7b5d28779 100644
--- a/core/java/com/android/internal/os/Zygote.java
+++ b/core/java/com/android/internal/os/Zygote.java
@@ -133,15 +133,16 @@ public final class Zygote {
* if this is the parent, or -1 on error.
*/
public static int forkAndSpecialize(int uid, int gid, int[] gids, int runtimeFlags,
- int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose,
- int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir,
- String packageName) {
+ int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose,
+ int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir,
+ String packageName, String[] packagesForUid, String[] visibleVolIds) {
VM_HOOKS.preFork();
// Resets nice priority for zygote process.
resetNicePriority();
int pid = nativeForkAndSpecialize(
uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName, fdsToClose,
- fdsToIgnore, startChildZygote, instructionSet, appDataDir, packageName);
+ fdsToIgnore, startChildZygote, instructionSet, appDataDir, packageName,
+ packagesForUid, visibleVolIds);
// Enable tracing as soon as possible for the child process.
if (pid == 0) {
Trace.setTracingEnabled(true, runtimeFlags);
@@ -154,9 +155,9 @@ public final class Zygote {
}
native private static int nativeForkAndSpecialize(int uid, int gid, int[] gids,int runtimeFlags,
- int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose,
- int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir,
- String packageName);
+ int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose,
+ int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir,
+ String packageName, String[] packagesForUid, String[] visibleVolIds);
/**
* Called to do any initialization before starting an application.
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index 06c41d858f7c..4a94ec4a4071 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -241,7 +241,8 @@ class ZygoteConnection {
pid = Zygote.forkAndSpecialize(parsedArgs.uid, parsedArgs.gid, parsedArgs.gids,
parsedArgs.runtimeFlags, rlimits, parsedArgs.mountExternal, parsedArgs.seInfo,
parsedArgs.niceName, fdsToClose, fdsToIgnore, parsedArgs.startChildZygote,
- parsedArgs.instructionSet, parsedArgs.appDataDir, parsedArgs.packageName);
+ parsedArgs.instructionSet, parsedArgs.appDataDir, parsedArgs.packageName,
+ parsedArgs.packagesForUid, parsedArgs.visibleVolIds);
try {
if (pid == 0) {
@@ -432,6 +433,12 @@ class ZygoteConnection {
/** from --package-name */
String packageName;
+ /** from --packages-for-uid */
+ String[] packagesForUid;
+
+ /** from --visible-vols */
+ String[] visibleVolIds;
+
/**
* Any args after and including the first non-option arg
* (or after a '--')
@@ -687,6 +694,10 @@ class ZygoteConnection {
throw new IllegalArgumentException("Duplicate arg specified");
}
packageName = arg.substring(arg.indexOf('=') + 1);
+ } else if (arg.startsWith("--packages-for-uid=")) {
+ packagesForUid = arg.substring(arg.indexOf('=') + 1).split(",");
+ } else if (arg.startsWith("--visible-vols=")) {
+ visibleVolIds = arg.substring(arg.indexOf('=') + 1).split(",");
} else {
break;
}