summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/app/ActivityThread.java2
-rw-r--r--core/java/android/os/Environment.java57
-rw-r--r--core/java/android/os/UserHandle.java6
-rw-r--r--services/java/com/android/server/SystemServer.java3
4 files changed, 22 insertions, 46 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index fef1e2c63e46..3f15a755bd79 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -6057,7 +6057,7 @@ public final class ActivityThread {
// StrictMode) on debug builds, but using DropBox, not logs.
CloseGuard.setEnabled(false);
- Environment.init();
+ Environment.initForCurrentUser();
// Set the reporter for event logging in libcore
EventLogger.setReporter(new EventLoggingReporter());
diff --git a/core/java/android/os/Environment.java b/core/java/android/os/Environment.java
index fa328090e90a..80927f368e0c 100644
--- a/core/java/android/os/Environment.java
+++ b/core/java/android/os/Environment.java
@@ -62,34 +62,17 @@ public class Environment {
private static final File DIR_ODM_ROOT = getDirectory(ENV_ODM_ROOT, "/odm");
private static final File DIR_VENDOR_ROOT = getDirectory(ENV_VENDOR_ROOT, "/vendor");
- // NoPreloadHolder to separate shared data from user-specific data, and to be able to initialize
- // Environment without side effect (allowing a lazy init of the data where possible).
- private static class NoPreloadHolder {
- public final static UserEnvironment sCurrentUser;
- public static boolean sUserRequired;
-
- static {
- sCurrentUser = new UserEnvironment(UserHandle.myUserId());
- }
-
- // Empty function to be able to trigger static initialization.
- public static void init() {
- }
+ private static UserEnvironment sCurrentUser;
+ private static boolean sUserRequired;
- // Disallow allocation.
- private NoPreloadHolder() {
- }
+ static {
+ initForCurrentUser();
}
/** {@hide} */
- public static void init() {
- NoPreloadHolder.init();
-
- // Check for expected outcome. We only allow one initialization, this will trigger if
- // somebody tried to re-initialize.
- if (NoPreloadHolder.sCurrentUser.mUserId != UserHandle.myUserId()) {
- throw new IllegalStateException();
- }
+ public static void initForCurrentUser() {
+ final int userId = UserHandle.myUserId();
+ sCurrentUser = new UserEnvironment(userId);
}
/** {@hide} */
@@ -445,7 +428,7 @@ public class Environment {
*/
public static File getExternalStorageDirectory() {
throwIfUserRequired();
- return NoPreloadHolder.sCurrentUser.getExternalDirs()[0];
+ return sCurrentUser.getExternalDirs()[0];
}
/** {@hide} */
@@ -629,7 +612,7 @@ public class Environment {
*/
public static File getExternalStoragePublicDirectory(String type) {
throwIfUserRequired();
- return NoPreloadHolder.sCurrentUser.buildExternalStoragePublicDirs(type)[0];
+ return sCurrentUser.buildExternalStoragePublicDirs(type)[0];
}
/**
@@ -638,7 +621,7 @@ public class Environment {
*/
public static File[] buildExternalStorageAndroidDataDirs() {
throwIfUserRequired();
- return NoPreloadHolder.sCurrentUser.buildExternalStorageAndroidDataDirs();
+ return sCurrentUser.buildExternalStorageAndroidDataDirs();
}
/**
@@ -647,7 +630,7 @@ public class Environment {
*/
public static File[] buildExternalStorageAppDataDirs(String packageName) {
throwIfUserRequired();
- return NoPreloadHolder.sCurrentUser.buildExternalStorageAppDataDirs(packageName);
+ return sCurrentUser.buildExternalStorageAppDataDirs(packageName);
}
/**
@@ -656,7 +639,7 @@ public class Environment {
*/
public static File[] buildExternalStorageAppMediaDirs(String packageName) {
throwIfUserRequired();
- return NoPreloadHolder.sCurrentUser.buildExternalStorageAppMediaDirs(packageName);
+ return sCurrentUser.buildExternalStorageAppMediaDirs(packageName);
}
/**
@@ -665,7 +648,7 @@ public class Environment {
*/
public static File[] buildExternalStorageAppObbDirs(String packageName) {
throwIfUserRequired();
- return NoPreloadHolder.sCurrentUser.buildExternalStorageAppObbDirs(packageName);
+ return sCurrentUser.buildExternalStorageAppObbDirs(packageName);
}
/**
@@ -674,7 +657,7 @@ public class Environment {
*/
public static File[] buildExternalStorageAppFilesDirs(String packageName) {
throwIfUserRequired();
- return NoPreloadHolder.sCurrentUser.buildExternalStorageAppFilesDirs(packageName);
+ return sCurrentUser.buildExternalStorageAppFilesDirs(packageName);
}
/**
@@ -683,7 +666,7 @@ public class Environment {
*/
public static File[] buildExternalStorageAppCacheDirs(String packageName) {
throwIfUserRequired();
- return NoPreloadHolder.sCurrentUser.buildExternalStorageAppCacheDirs(packageName);
+ return sCurrentUser.buildExternalStorageAppCacheDirs(packageName);
}
/**
@@ -787,7 +770,7 @@ public class Environment {
* {@link #MEDIA_BAD_REMOVAL}, or {@link #MEDIA_UNMOUNTABLE}.
*/
public static String getExternalStorageState() {
- final File externalDir = NoPreloadHolder.sCurrentUser.getExternalDirs()[0];
+ final File externalDir = sCurrentUser.getExternalDirs()[0];
return getExternalStorageState(externalDir);
}
@@ -828,7 +811,7 @@ public class Environment {
*/
public static boolean isExternalStorageRemovable() {
if (isStorageDisabled()) return false;
- final File externalDir = NoPreloadHolder.sCurrentUser.getExternalDirs()[0];
+ final File externalDir = sCurrentUser.getExternalDirs()[0];
return isExternalStorageRemovable(externalDir);
}
@@ -867,7 +850,7 @@ public class Environment {
*/
public static boolean isExternalStorageEmulated() {
if (isStorageDisabled()) return false;
- final File externalDir = NoPreloadHolder.sCurrentUser.getExternalDirs()[0];
+ final File externalDir = sCurrentUser.getExternalDirs()[0];
return isExternalStorageEmulated(externalDir);
}
@@ -902,11 +885,11 @@ public class Environment {
/** {@hide} */
public static void setUserRequired(boolean userRequired) {
- NoPreloadHolder.sUserRequired = userRequired;
+ sUserRequired = userRequired;
}
private static void throwIfUserRequired() {
- if (NoPreloadHolder.sUserRequired) {
+ if (sUserRequired) {
Log.wtf(TAG, "Path requests must specify a user by using UserEnvironment",
new Throwable());
}
diff --git a/core/java/android/os/UserHandle.java b/core/java/android/os/UserHandle.java
index 10e3718601ea..b3f44536214b 100644
--- a/core/java/android/os/UserHandle.java
+++ b/core/java/android/os/UserHandle.java
@@ -297,11 +297,7 @@ public final class UserHandle implements Parcelable {
*/
@SystemApi
public static @UserIdInt int myUserId() {
- int myUid = Process.myUid();
- if (myUid == 0) {
- throw new IllegalStateException("myUserId unsupported in zygote.");
- }
- return getUserId(myUid);
+ return getUserId(Process.myUid());
}
/**
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index fa3479cca5e7..76424d82a2b0 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -284,9 +284,6 @@ public final class SystemServer {
// we've defined it before booting further.
Build.ensureFingerprintProperty();
- // Initialize Environment for the system user.
- Environment.init();
-
// Within the system server, it is an error to access Environment paths without
// explicitly specifying a user.
Environment.setUserRequired(true);