Skip to content

Commit a490bdd

Browse files
jsharkeyAndroid (Google) Code Review
authored andcommitted
Merge changes I4513afbd,I20e2194c into jb-mr1-dev
* changes: Make getMediaStorageDirectory() user-aware. Lockdown should only augment connected networks.
2 parents 549be8b + 3fe5bf6 commit a490bdd

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

core/java/android/os/Environment.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/**

services/java/com/android/server/net/LockdownVpnTracker.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,11 @@ public void onVpnStateChanged(NetworkInfo info) {
268268
}
269269

270270
public NetworkInfo augmentNetworkInfo(NetworkInfo info) {
271-
final NetworkInfo vpnInfo = mVpn.getNetworkInfo();
272-
info = new NetworkInfo(info);
273-
info.setDetailedState(vpnInfo.getDetailedState(), vpnInfo.getReason(), null);
271+
if (info.isConnected()) {
272+
final NetworkInfo vpnInfo = mVpn.getNetworkInfo();
273+
info = new NetworkInfo(info);
274+
info.setDetailedState(vpnInfo.getDetailedState(), vpnInfo.getReason(), null);
275+
}
274276
return info;
275277
}
276278

0 commit comments

Comments
 (0)