@@ -32,6 +32,7 @@ public class Environment {
3232
3333 private static final String ENV_EXTERNAL_STORAGE = "EXTERNAL_STORAGE" ;
3434 private static final String ENV_EMULATED_STORAGE_TARGET = "EMULATED_STORAGE_TARGET" ;
35+ private static final String ENV_MEDIA_STORAGE = "MEDIA_STORAGE" ;
3536
3637 /** {@hide} */
3738 public static String DIRECTORY_ANDROID = "Android" ;
@@ -88,21 +89,30 @@ public static class UserEnvironment {
8889 private final File mExternalStorageAndroidData ;
8990 private final File mExternalStorageAndroidMedia ;
9091 private final File mExternalStorageAndroidObb ;
92+ private final File mMediaStorage ;
9193
9294 public UserEnvironment (int userId ) {
9395 // See storage config details at http://source.android.com/tech/storage/
9496 String rawExternalStorage = System .getenv (ENV_EXTERNAL_STORAGE );
9597 String rawEmulatedStorageTarget = System .getenv (ENV_EMULATED_STORAGE_TARGET );
98+ String rawMediaStorage = System .getenv (ENV_MEDIA_STORAGE );
99+ if (TextUtils .isEmpty (rawMediaStorage )) {
100+ rawMediaStorage = "/data/media" ;
101+ }
96102
97103 if (!TextUtils .isEmpty (rawEmulatedStorageTarget )) {
98104 // Device has emulated storage; external storage paths should have
99105 // userId burned into them.
106+ final String rawUserId = Integer .toString (userId );
100107 final File emulatedBase = new File (rawEmulatedStorageTarget );
108+ final File mediaBase = new File (rawMediaStorage );
101109
102110 // /storage/emulated/0
103- mExternalStorage = buildPath (emulatedBase , Integer . toString ( userId ) );
111+ mExternalStorage = buildPath (emulatedBase , rawUserId );
104112 // /storage/emulated/obb
105113 mExternalStorageAndroidObb = buildPath (emulatedBase , "obb" );
114+ // /data/media/0
115+ mMediaStorage = buildPath (mediaBase , rawUserId );
106116
107117 } else {
108118 // Device has physical external storage; use plain paths.
@@ -115,6 +125,8 @@ public UserEnvironment(int userId) {
115125 mExternalStorage = new File (rawExternalStorage );
116126 // /storage/sdcard0/Android/obb
117127 mExternalStorageAndroidObb = buildPath (mExternalStorage , DIRECTORY_ANDROID , "obb" );
128+ // /data/media
129+ mMediaStorage = new File (rawMediaStorage );
118130 }
119131
120132 mExternalStorageAndroidData = buildPath (mExternalStorage , DIRECTORY_ANDROID , "data" );
@@ -152,6 +164,10 @@ public File getExternalStorageAppFilesDirectory(String packageName) {
152164 public File getExternalStorageAppCacheDirectory (String packageName ) {
153165 return new File (new File (mExternalStorageAndroidData , packageName ), "cache" );
154166 }
167+
168+ public File getMediaStorageDirectory () {
169+ return mMediaStorage ;
170+ }
155171 }
156172
157173 /**
@@ -198,7 +214,8 @@ public static File getSecureDataDirectory() {
198214 * @hide
199215 */
200216 public static File getMediaStorageDirectory () {
201- return MEDIA_STORAGE_DIRECTORY ;
217+ throwIfSystem ();
218+ return sCurrentUser .getMediaStorageDirectory ();
202219 }
203220
204221 /**
@@ -231,10 +248,6 @@ public static boolean isEncryptedFilesystemEnabled() {
231248 private static final File SECURE_DATA_DIRECTORY
232249 = getDirectory ("ANDROID_SECURE_DATA" , "/data/secure" );
233250
234- /** @hide */
235- private static final File MEDIA_STORAGE_DIRECTORY
236- = getDirectory ("MEDIA_STORAGE" , "/data/media" );
237-
238251 private static final File DOWNLOAD_CACHE_DIRECTORY = getDirectory ("DOWNLOAD_CACHE" , "/cache" );
239252
240253 /**
0 commit comments