Loading core/java/android/app/ActivityThread.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -6057,7 +6057,7 @@ public final class ActivityThread { // StrictMode) on debug builds, but using DropBox, not logs. // StrictMode) on debug builds, but using DropBox, not logs. CloseGuard.setEnabled(false); CloseGuard.setEnabled(false); Environment.initForCurrentUser(); Environment.init(); // Set the reporter for event logging in libcore // Set the reporter for event logging in libcore EventLogger.setReporter(new EventLoggingReporter()); EventLogger.setReporter(new EventLoggingReporter()); Loading core/java/android/os/Environment.java +37 −20 Original line number Original line Diff line number Diff line Loading @@ -62,17 +62,34 @@ public class Environment { private static final File DIR_ODM_ROOT = getDirectory(ENV_ODM_ROOT, "/odm"); private static final File DIR_ODM_ROOT = getDirectory(ENV_ODM_ROOT, "/odm"); private static final File DIR_VENDOR_ROOT = getDirectory(ENV_VENDOR_ROOT, "/vendor"); private static final File DIR_VENDOR_ROOT = getDirectory(ENV_VENDOR_ROOT, "/vendor"); private static UserEnvironment sCurrentUser; // NoPreloadHolder to separate shared data from user-specific data, and to be able to initialize private static boolean sUserRequired; // 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 { static { initForCurrentUser(); sCurrentUser = new UserEnvironment(UserHandle.myUserId()); } // Empty function to be able to trigger static initialization. public static void init() { } // Disallow allocation. private NoPreloadHolder() { } } } /** {@hide} */ /** {@hide} */ public static void initForCurrentUser() { public static void init() { final int userId = UserHandle.myUserId(); NoPreloadHolder.init(); sCurrentUser = new UserEnvironment(userId); // 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(); } } } /** {@hide} */ /** {@hide} */ Loading Loading @@ -428,7 +445,7 @@ public class Environment { */ */ public static File getExternalStorageDirectory() { public static File getExternalStorageDirectory() { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.getExternalDirs()[0]; return NoPreloadHolder.sCurrentUser.getExternalDirs()[0]; } } /** {@hide} */ /** {@hide} */ Loading Loading @@ -612,7 +629,7 @@ public class Environment { */ */ public static File getExternalStoragePublicDirectory(String type) { public static File getExternalStoragePublicDirectory(String type) { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.buildExternalStoragePublicDirs(type)[0]; return NoPreloadHolder.sCurrentUser.buildExternalStoragePublicDirs(type)[0]; } } /** /** Loading @@ -621,7 +638,7 @@ public class Environment { */ */ public static File[] buildExternalStorageAndroidDataDirs() { public static File[] buildExternalStorageAndroidDataDirs() { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.buildExternalStorageAndroidDataDirs(); return NoPreloadHolder.sCurrentUser.buildExternalStorageAndroidDataDirs(); } } /** /** Loading @@ -630,7 +647,7 @@ public class Environment { */ */ public static File[] buildExternalStorageAppDataDirs(String packageName) { public static File[] buildExternalStorageAppDataDirs(String packageName) { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.buildExternalStorageAppDataDirs(packageName); return NoPreloadHolder.sCurrentUser.buildExternalStorageAppDataDirs(packageName); } } /** /** Loading @@ -639,7 +656,7 @@ public class Environment { */ */ public static File[] buildExternalStorageAppMediaDirs(String packageName) { public static File[] buildExternalStorageAppMediaDirs(String packageName) { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.buildExternalStorageAppMediaDirs(packageName); return NoPreloadHolder.sCurrentUser.buildExternalStorageAppMediaDirs(packageName); } } /** /** Loading @@ -648,7 +665,7 @@ public class Environment { */ */ public static File[] buildExternalStorageAppObbDirs(String packageName) { public static File[] buildExternalStorageAppObbDirs(String packageName) { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.buildExternalStorageAppObbDirs(packageName); return NoPreloadHolder.sCurrentUser.buildExternalStorageAppObbDirs(packageName); } } /** /** Loading @@ -657,7 +674,7 @@ public class Environment { */ */ public static File[] buildExternalStorageAppFilesDirs(String packageName) { public static File[] buildExternalStorageAppFilesDirs(String packageName) { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.buildExternalStorageAppFilesDirs(packageName); return NoPreloadHolder.sCurrentUser.buildExternalStorageAppFilesDirs(packageName); } } /** /** Loading @@ -666,7 +683,7 @@ public class Environment { */ */ public static File[] buildExternalStorageAppCacheDirs(String packageName) { public static File[] buildExternalStorageAppCacheDirs(String packageName) { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.buildExternalStorageAppCacheDirs(packageName); return NoPreloadHolder.sCurrentUser.buildExternalStorageAppCacheDirs(packageName); } } /** /** Loading Loading @@ -770,7 +787,7 @@ public class Environment { * {@link #MEDIA_BAD_REMOVAL}, or {@link #MEDIA_UNMOUNTABLE}. * {@link #MEDIA_BAD_REMOVAL}, or {@link #MEDIA_UNMOUNTABLE}. */ */ public static String getExternalStorageState() { public static String getExternalStorageState() { final File externalDir = sCurrentUser.getExternalDirs()[0]; final File externalDir = NoPreloadHolder.sCurrentUser.getExternalDirs()[0]; return getExternalStorageState(externalDir); return getExternalStorageState(externalDir); } } Loading Loading @@ -811,7 +828,7 @@ public class Environment { */ */ public static boolean isExternalStorageRemovable() { public static boolean isExternalStorageRemovable() { if (isStorageDisabled()) return false; if (isStorageDisabled()) return false; final File externalDir = sCurrentUser.getExternalDirs()[0]; final File externalDir = NoPreloadHolder.sCurrentUser.getExternalDirs()[0]; return isExternalStorageRemovable(externalDir); return isExternalStorageRemovable(externalDir); } } Loading Loading @@ -850,7 +867,7 @@ public class Environment { */ */ public static boolean isExternalStorageEmulated() { public static boolean isExternalStorageEmulated() { if (isStorageDisabled()) return false; if (isStorageDisabled()) return false; final File externalDir = sCurrentUser.getExternalDirs()[0]; final File externalDir = NoPreloadHolder.sCurrentUser.getExternalDirs()[0]; return isExternalStorageEmulated(externalDir); return isExternalStorageEmulated(externalDir); } } Loading Loading @@ -885,11 +902,11 @@ public class Environment { /** {@hide} */ /** {@hide} */ public static void setUserRequired(boolean userRequired) { public static void setUserRequired(boolean userRequired) { sUserRequired = userRequired; NoPreloadHolder.sUserRequired = userRequired; } } private static void throwIfUserRequired() { private static void throwIfUserRequired() { if (sUserRequired) { if (NoPreloadHolder.sUserRequired) { Log.wtf(TAG, "Path requests must specify a user by using UserEnvironment", Log.wtf(TAG, "Path requests must specify a user by using UserEnvironment", new Throwable()); new Throwable()); } } Loading core/java/android/os/UserHandle.java +5 −1 Original line number Original line Diff line number Diff line Loading @@ -297,7 +297,11 @@ public final class UserHandle implements Parcelable { */ */ @SystemApi @SystemApi public static @UserIdInt int myUserId() { public static @UserIdInt int myUserId() { return getUserId(Process.myUid()); int myUid = Process.myUid(); if (myUid == 0) { throw new IllegalStateException("myUserId unsupported in zygote."); } return getUserId(myUid); } } /** /** Loading services/java/com/android/server/SystemServer.java +3 −0 Original line number Original line Diff line number Diff line Loading @@ -284,6 +284,9 @@ public final class SystemServer { // we've defined it before booting further. // we've defined it before booting further. Build.ensureFingerprintProperty(); Build.ensureFingerprintProperty(); // Initialize Environment for the system user. Environment.init(); // Within the system server, it is an error to access Environment paths without // Within the system server, it is an error to access Environment paths without // explicitly specifying a user. // explicitly specifying a user. Environment.setUserRequired(true); Environment.setUserRequired(true); Loading Loading
core/java/android/app/ActivityThread.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -6057,7 +6057,7 @@ public final class ActivityThread { // StrictMode) on debug builds, but using DropBox, not logs. // StrictMode) on debug builds, but using DropBox, not logs. CloseGuard.setEnabled(false); CloseGuard.setEnabled(false); Environment.initForCurrentUser(); Environment.init(); // Set the reporter for event logging in libcore // Set the reporter for event logging in libcore EventLogger.setReporter(new EventLoggingReporter()); EventLogger.setReporter(new EventLoggingReporter()); Loading
core/java/android/os/Environment.java +37 −20 Original line number Original line Diff line number Diff line Loading @@ -62,17 +62,34 @@ public class Environment { private static final File DIR_ODM_ROOT = getDirectory(ENV_ODM_ROOT, "/odm"); private static final File DIR_ODM_ROOT = getDirectory(ENV_ODM_ROOT, "/odm"); private static final File DIR_VENDOR_ROOT = getDirectory(ENV_VENDOR_ROOT, "/vendor"); private static final File DIR_VENDOR_ROOT = getDirectory(ENV_VENDOR_ROOT, "/vendor"); private static UserEnvironment sCurrentUser; // NoPreloadHolder to separate shared data from user-specific data, and to be able to initialize private static boolean sUserRequired; // 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 { static { initForCurrentUser(); sCurrentUser = new UserEnvironment(UserHandle.myUserId()); } // Empty function to be able to trigger static initialization. public static void init() { } // Disallow allocation. private NoPreloadHolder() { } } } /** {@hide} */ /** {@hide} */ public static void initForCurrentUser() { public static void init() { final int userId = UserHandle.myUserId(); NoPreloadHolder.init(); sCurrentUser = new UserEnvironment(userId); // 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(); } } } /** {@hide} */ /** {@hide} */ Loading Loading @@ -428,7 +445,7 @@ public class Environment { */ */ public static File getExternalStorageDirectory() { public static File getExternalStorageDirectory() { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.getExternalDirs()[0]; return NoPreloadHolder.sCurrentUser.getExternalDirs()[0]; } } /** {@hide} */ /** {@hide} */ Loading Loading @@ -612,7 +629,7 @@ public class Environment { */ */ public static File getExternalStoragePublicDirectory(String type) { public static File getExternalStoragePublicDirectory(String type) { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.buildExternalStoragePublicDirs(type)[0]; return NoPreloadHolder.sCurrentUser.buildExternalStoragePublicDirs(type)[0]; } } /** /** Loading @@ -621,7 +638,7 @@ public class Environment { */ */ public static File[] buildExternalStorageAndroidDataDirs() { public static File[] buildExternalStorageAndroidDataDirs() { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.buildExternalStorageAndroidDataDirs(); return NoPreloadHolder.sCurrentUser.buildExternalStorageAndroidDataDirs(); } } /** /** Loading @@ -630,7 +647,7 @@ public class Environment { */ */ public static File[] buildExternalStorageAppDataDirs(String packageName) { public static File[] buildExternalStorageAppDataDirs(String packageName) { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.buildExternalStorageAppDataDirs(packageName); return NoPreloadHolder.sCurrentUser.buildExternalStorageAppDataDirs(packageName); } } /** /** Loading @@ -639,7 +656,7 @@ public class Environment { */ */ public static File[] buildExternalStorageAppMediaDirs(String packageName) { public static File[] buildExternalStorageAppMediaDirs(String packageName) { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.buildExternalStorageAppMediaDirs(packageName); return NoPreloadHolder.sCurrentUser.buildExternalStorageAppMediaDirs(packageName); } } /** /** Loading @@ -648,7 +665,7 @@ public class Environment { */ */ public static File[] buildExternalStorageAppObbDirs(String packageName) { public static File[] buildExternalStorageAppObbDirs(String packageName) { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.buildExternalStorageAppObbDirs(packageName); return NoPreloadHolder.sCurrentUser.buildExternalStorageAppObbDirs(packageName); } } /** /** Loading @@ -657,7 +674,7 @@ public class Environment { */ */ public static File[] buildExternalStorageAppFilesDirs(String packageName) { public static File[] buildExternalStorageAppFilesDirs(String packageName) { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.buildExternalStorageAppFilesDirs(packageName); return NoPreloadHolder.sCurrentUser.buildExternalStorageAppFilesDirs(packageName); } } /** /** Loading @@ -666,7 +683,7 @@ public class Environment { */ */ public static File[] buildExternalStorageAppCacheDirs(String packageName) { public static File[] buildExternalStorageAppCacheDirs(String packageName) { throwIfUserRequired(); throwIfUserRequired(); return sCurrentUser.buildExternalStorageAppCacheDirs(packageName); return NoPreloadHolder.sCurrentUser.buildExternalStorageAppCacheDirs(packageName); } } /** /** Loading Loading @@ -770,7 +787,7 @@ public class Environment { * {@link #MEDIA_BAD_REMOVAL}, or {@link #MEDIA_UNMOUNTABLE}. * {@link #MEDIA_BAD_REMOVAL}, or {@link #MEDIA_UNMOUNTABLE}. */ */ public static String getExternalStorageState() { public static String getExternalStorageState() { final File externalDir = sCurrentUser.getExternalDirs()[0]; final File externalDir = NoPreloadHolder.sCurrentUser.getExternalDirs()[0]; return getExternalStorageState(externalDir); return getExternalStorageState(externalDir); } } Loading Loading @@ -811,7 +828,7 @@ public class Environment { */ */ public static boolean isExternalStorageRemovable() { public static boolean isExternalStorageRemovable() { if (isStorageDisabled()) return false; if (isStorageDisabled()) return false; final File externalDir = sCurrentUser.getExternalDirs()[0]; final File externalDir = NoPreloadHolder.sCurrentUser.getExternalDirs()[0]; return isExternalStorageRemovable(externalDir); return isExternalStorageRemovable(externalDir); } } Loading Loading @@ -850,7 +867,7 @@ public class Environment { */ */ public static boolean isExternalStorageEmulated() { public static boolean isExternalStorageEmulated() { if (isStorageDisabled()) return false; if (isStorageDisabled()) return false; final File externalDir = sCurrentUser.getExternalDirs()[0]; final File externalDir = NoPreloadHolder.sCurrentUser.getExternalDirs()[0]; return isExternalStorageEmulated(externalDir); return isExternalStorageEmulated(externalDir); } } Loading Loading @@ -885,11 +902,11 @@ public class Environment { /** {@hide} */ /** {@hide} */ public static void setUserRequired(boolean userRequired) { public static void setUserRequired(boolean userRequired) { sUserRequired = userRequired; NoPreloadHolder.sUserRequired = userRequired; } } private static void throwIfUserRequired() { private static void throwIfUserRequired() { if (sUserRequired) { if (NoPreloadHolder.sUserRequired) { Log.wtf(TAG, "Path requests must specify a user by using UserEnvironment", Log.wtf(TAG, "Path requests must specify a user by using UserEnvironment", new Throwable()); new Throwable()); } } Loading
core/java/android/os/UserHandle.java +5 −1 Original line number Original line Diff line number Diff line Loading @@ -297,7 +297,11 @@ public final class UserHandle implements Parcelable { */ */ @SystemApi @SystemApi public static @UserIdInt int myUserId() { public static @UserIdInt int myUserId() { return getUserId(Process.myUid()); int myUid = Process.myUid(); if (myUid == 0) { throw new IllegalStateException("myUserId unsupported in zygote."); } return getUserId(myUid); } } /** /** Loading
services/java/com/android/server/SystemServer.java +3 −0 Original line number Original line Diff line number Diff line Loading @@ -284,6 +284,9 @@ public final class SystemServer { // we've defined it before booting further. // we've defined it before booting further. Build.ensureFingerprintProperty(); Build.ensureFingerprintProperty(); // Initialize Environment for the system user. Environment.init(); // Within the system server, it is an error to access Environment paths without // Within the system server, it is an error to access Environment paths without // explicitly specifying a user. // explicitly specifying a user. Environment.setUserRequired(true); Environment.setUserRequired(true); Loading