diff options
| author | 2022-09-09 14:02:15 +0100 | |
|---|---|---|
| committer | 2022-09-21 15:44:23 +0100 | |
| commit | 4e65c53b43429e08a65aa901f043c9016e02f23c (patch) | |
| tree | 77e9152627662a9506bf708b6d989fc0b530bbf0 | |
| parent | 636c721c731063d1b6214b499a7ce58f0c8b12c6 (diff) | |
Fixing Storage Volume listing for Cloned User.
Current implementation only returns the Volumes for the current user.
In case of Cloned user this causes issues as Cloned user uses Media
Provider of User 0, thereby returning only Volume 0, causing problems in
assigning projectIds, and affecting storage calculation.
The projectId assignement happens via
MediaProvider.updateExternalStorageFileQuota.
Bug: 235321217
Test: atest android.appsecurity.cts.StorageHostTest
Change-Id: I617bae9b201fd66d7b62b6cbd1c48b9f276f1924
| -rw-r--r-- | core/api/system-current.txt | 2 | ||||
| -rw-r--r-- | core/java/android/os/storage/StorageManager.java | 9 |
2 files changed, 8 insertions, 3 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index f09244ad7859..e39431dd5ea7 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -10040,7 +10040,7 @@ package android.os.storage { method @WorkerThread public long getAllocatableBytes(@NonNull java.util.UUID, @RequiresPermission int) throws java.io.IOException; method @RequiresPermission(android.Manifest.permission.WRITE_MEDIA_STORAGE) public int getExternalStorageMountMode(int, @NonNull String); method public static boolean hasIsolatedStorage(); - method public void updateExternalStorageFileQuotaType(@NonNull java.io.File, int) throws java.io.IOException; + method @RequiresPermission(android.Manifest.permission.MANAGE_EXTERNAL_STORAGE) public void updateExternalStorageFileQuotaType(@NonNull java.io.File, int) throws java.io.IOException; field @RequiresPermission(android.Manifest.permission.ALLOCATE_AGGRESSIVE) public static final int FLAG_ALLOCATE_AGGRESSIVE = 1; // 0x1 field public static final int MOUNT_MODE_EXTERNAL_ANDROID_WRITABLE = 4; // 0x4 field public static final int MOUNT_MODE_EXTERNAL_DEFAULT = 1; // 0x1 diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java index 08de87ebe2e6..c1606e89645e 100644 --- a/core/java/android/os/storage/StorageManager.java +++ b/core/java/android/os/storage/StorageManager.java @@ -2549,7 +2549,7 @@ public class StorageManager { * called on first creation of a new file on external storage, and whenever the * media type of the file is updated later. * - * This API doesn't require any special permissions, though typical implementations + * This API requires MANAGE_EXTERNAL_STORAGE permission and typical implementations * will require being called from an SELinux domain that allows setting file attributes * related to quota (eg the GID or project ID). * @@ -2568,11 +2568,16 @@ public class StorageManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MANAGE_EXTERNAL_STORAGE) public void updateExternalStorageFileQuotaType(@NonNull File path, @QuotaType int quotaType) throws IOException { long projectId; final String filePath = path.getCanonicalPath(); - final StorageVolume volume = getStorageVolume(path); + // MANAGE_EXTERNAL_STORAGE permission is required as FLAG_INCLUDE_SHARED_PROFILE is being + // set while querying getVolumeList. + final StorageVolume[] availableVolumes = getVolumeList(mContext.getUserId(), + FLAG_REAL_STATE | FLAG_INCLUDE_INVISIBLE | FLAG_INCLUDE_SHARED_PROFILE); + final StorageVolume volume = getStorageVolume(availableVolumes, path); if (volume == null) { Log.w(TAG, "Failed to update quota type for " + filePath); return; |