summaryrefslogtreecommitdiffstats
path: root/core/java/android/os
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2015-07-28 10:49:47 -0700
committerJeff Sharkey <jsharkey@android.com>2015-07-28 14:42:34 -0700
commit4634987668eb7e1fa1434bddbde969ef43de6b40 (patch)
treedfb9e8e2618ac10f58888678cc0226c334864f72 /core/java/android/os
parent2e606d7be5275f2bff4c5755351bc3191ecb1bf1 (diff)
downloadframeworks_base-4634987668eb7e1fa1434bddbde969ef43de6b40.zip
frameworks_base-4634987668eb7e1fa1434bddbde969ef43de6b40.tar.gz
frameworks_base-4634987668eb7e1fa1434bddbde969ef43de6b40.tar.bz2
Give secondary users read-only physical cards.
Long ago, we mounted secondary physical cards as readable by all users on the device, which enabled the use-case of loading media on a card and viewing it from all users. More recently, we started giving write access to these secondary physical cards, but this created a one-directional channel for communication across user boundaries; something that CDD disallows. This change is designed to give us the best of both worlds: the package-specific directories are writable for the user that mounted the card, but access to those "Android" directories are blocked for all other users. Other users remain able to read content elsewhere on the card. Bug: 22787184 Change-Id: Ied8c98995fec1b7b50ff7d930550feabb4398582
Diffstat (limited to 'core/java/android/os')
-rw-r--r--core/java/android/os/Environment.java3
-rw-r--r--core/java/android/os/storage/IMountService.java8
-rw-r--r--core/java/android/os/storage/StorageManager.java11
-rw-r--r--core/java/android/os/storage/VolumeInfo.java35
4 files changed, 46 insertions, 11 deletions
diff --git a/core/java/android/os/Environment.java b/core/java/android/os/Environment.java
index 2080856..64d6da5 100644
--- a/core/java/android/os/Environment.java
+++ b/core/java/android/os/Environment.java
@@ -80,7 +80,8 @@ public class Environment {
}
public File[] getExternalDirs() {
- final StorageVolume[] volumes = StorageManager.getVolumeList(mUserId);
+ final StorageVolume[] volumes = StorageManager.getVolumeList(mUserId,
+ StorageManager.FLAG_FOR_WRITE);
final File[] files = new File[volumes.length];
for (int i = 0; i < volumes.length; i++) {
files[i] = volumes[i].getPathFile();
diff --git a/core/java/android/os/storage/IMountService.java b/core/java/android/os/storage/IMountService.java
index c3b098b..fce09dd 100644
--- a/core/java/android/os/storage/IMountService.java
+++ b/core/java/android/os/storage/IMountService.java
@@ -758,7 +758,7 @@ public interface IMountService extends IInterface {
return _result;
}
- public StorageVolume[] getVolumeList(int uid, String packageName)
+ public StorageVolume[] getVolumeList(int uid, String packageName, int flags)
throws RemoteException {
Parcel _data = Parcel.obtain();
Parcel _reply = Parcel.obtain();
@@ -767,6 +767,7 @@ public interface IMountService extends IInterface {
_data.writeInterfaceToken(DESCRIPTOR);
_data.writeInt(uid);
_data.writeString(packageName);
+ _data.writeInt(flags);
mRemote.transact(Stub.TRANSACTION_getVolumeList, _data, _reply, 0);
_reply.readException();
_result = _reply.createTypedArray(StorageVolume.CREATOR);
@@ -1609,7 +1610,8 @@ public interface IMountService extends IInterface {
data.enforceInterface(DESCRIPTOR);
int uid = data.readInt();
String packageName = data.readString();
- StorageVolume[] result = getVolumeList(uid, packageName);
+ int _flags = data.readInt();
+ StorageVolume[] result = getVolumeList(uid, packageName, _flags);
reply.writeNoException();
reply.writeTypedArray(result, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
return true;
@@ -2059,7 +2061,7 @@ public interface IMountService extends IInterface {
/**
* Returns list of all mountable volumes.
*/
- public StorageVolume[] getVolumeList(int uid, String packageName) throws RemoteException;
+ public StorageVolume[] getVolumeList(int uid, String packageName, int flags) throws RemoteException;
/**
* Gets the path on the filesystem for the ASEC container itself.
diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java
index b2cec60..d1f3743 100644
--- a/core/java/android/os/storage/StorageManager.java
+++ b/core/java/android/os/storage/StorageManager.java
@@ -86,6 +86,9 @@ public class StorageManager {
/** {@hide} */
public static final int DEBUG_FORCE_ADOPTABLE = 1 << 0;
+ /** {@hide} */
+ public static final int FLAG_FOR_WRITE = 1 << 0;
+
private final Context mContext;
private final ContentResolver mResolver;
@@ -812,7 +815,7 @@ public class StorageManager {
/** {@hide} */
public static @Nullable StorageVolume getStorageVolume(File file, int userId) {
- return getStorageVolume(getVolumeList(userId), file);
+ return getStorageVolume(getVolumeList(userId, 0), file);
}
/** {@hide} */
@@ -852,11 +855,11 @@ public class StorageManager {
/** {@hide} */
public @NonNull StorageVolume[] getVolumeList() {
- return getVolumeList(mContext.getUserId());
+ return getVolumeList(mContext.getUserId(), 0);
}
/** {@hide} */
- public static @NonNull StorageVolume[] getVolumeList(int userId) {
+ public static @NonNull StorageVolume[] getVolumeList(int userId, int flags) {
final IMountService mountService = IMountService.Stub.asInterface(
ServiceManager.getService("mount"));
try {
@@ -877,7 +880,7 @@ public class StorageManager {
if (uid <= 0) {
return new StorageVolume[0];
}
- return mountService.getVolumeList(uid, packageName);
+ return mountService.getVolumeList(uid, packageName, flags);
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
diff --git a/core/java/android/os/storage/VolumeInfo.java b/core/java/android/os/storage/VolumeInfo.java
index 8d603a1..ef54d84 100644
--- a/core/java/android/os/storage/VolumeInfo.java
+++ b/core/java/android/os/storage/VolumeInfo.java
@@ -46,6 +46,19 @@ import java.util.Objects;
* Information about a storage volume that may be mounted. A volume may be a
* partition on a physical {@link DiskInfo}, an emulated volume above some other
* storage medium, or a standalone container like an ASEC or OBB.
+ * <p>
+ * Volumes may be mounted with various flags:
+ * <ul>
+ * <li>{@link #MOUNT_FLAG_PRIMARY} means the volume provides primary external
+ * storage, historically found at {@code /sdcard}.
+ * <li>{@link #MOUNT_FLAG_VISIBLE} means the volume is visible to third-party
+ * apps for direct filesystem access. The system should send out relevant
+ * storage broadcasts and index any media on visible volumes. Visible volumes
+ * are considered a more stable part of the device, which is why we take the
+ * time to index them. In particular, transient volumes like USB OTG devices
+ * <em>should not</em> be marked as visible; their contents should be surfaced
+ * to apps through the Storage Access Framework.
+ * </ul>
*
* @hide
*/
@@ -255,8 +268,23 @@ public class VolumeInfo implements Parcelable {
return (mountFlags & MOUNT_FLAG_VISIBLE) != 0;
}
- public boolean isVisibleToUser(int userId) {
- if (type == TYPE_PUBLIC && userId == this.mountUserId) {
+ public boolean isVisibleForRead(int userId) {
+ if (type == TYPE_PUBLIC) {
+ if (isPrimary() && mountUserId != userId) {
+ // Primary physical is only visible to single user
+ return false;
+ } else {
+ return isVisible();
+ }
+ } else if (type == TYPE_EMULATED) {
+ return isVisible();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isVisibleForWrite(int userId) {
+ if (type == TYPE_PUBLIC && mountUserId == userId) {
return isVisible();
} else if (type == TYPE_EMULATED) {
return isVisible();
@@ -276,7 +304,7 @@ public class VolumeInfo implements Parcelable {
public File getPathForUser(int userId) {
if (path == null) {
return null;
- } else if (type == TYPE_PUBLIC && userId == this.mountUserId) {
+ } else if (type == TYPE_PUBLIC) {
return new File(path);
} else if (type == TYPE_EMULATED) {
return new File(path, Integer.toString(userId));
@@ -306,6 +334,7 @@ public class VolumeInfo implements Parcelable {
final boolean allowMassStorage = false;
final String envState = reportUnmounted
? Environment.MEDIA_UNMOUNTED : getEnvironmentForState(state);
+
File userPath = getPathForUser(userId);
if (userPath == null) {
userPath = new File("/dev/null");