diff options
| author | TreeHugger Robot <treehugger-gerrit@google.com> | 2021-05-21 10:58:21 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-05-21 10:58:21 +0000 |
| commit | 604a342f142b46c9f8250f50cd7ba4f878cf1ea2 (patch) | |
| tree | e4e3b09a68058b333fc4380a636eda008123d1ac /src/com | |
| parent | 04901180bff0fb5977bf895f28dd10a3a4cbaf94 (diff) | |
| parent | c18a2c437c6410541893e8ae486dcdd52c0180e9 (diff) | |
| download | platform_packages_providers_MediaProvider-604a342f142b46c9f8250f50cd7ba4f878cf1ea2.tar.gz platform_packages_providers_MediaProvider-604a342f142b46c9f8250f50cd7ba4f878cf1ea2.tar.bz2 platform_packages_providers_MediaProvider-604a342f142b46c9f8250f50cd7ba4f878cf1ea2.zip | |
Merge "Allow volume paths from both users when verifying file columns." into sc-dev
Diffstat (limited to 'src/com')
| -rw-r--r-- | src/com/android/providers/media/MediaProvider.java | 18 | ||||
| -rw-r--r-- | src/com/android/providers/media/util/UserCache.java | 6 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/com/android/providers/media/MediaProvider.java b/src/com/android/providers/media/MediaProvider.java index 5fd69ed6..c3692571 100644 --- a/src/com/android/providers/media/MediaProvider.java +++ b/src/com/android/providers/media/MediaProvider.java @@ -417,9 +417,21 @@ public class MediaProvider extends ContentProvider { return mVolumeCache.getVolumeId(file); } - public @NonNull Collection<File> getVolumeScanPaths(String volumeName) + private @NonNull Collection<File> getAllowedVolumePaths(String volumeName) throws FileNotFoundException { - return mVolumeCache.getVolumeScanPaths(volumeName, mCallingIdentity.get().getUser()); + // This method is used to verify whether a path belongs to a certain volume name; + // we can't always use the calling user's identity here to determine exactly which + // volume is meant, because the MediaScanner may scan paths belonging to another user, + // eg a clone user. + // So, for volumes like external_primary, just return allowed paths for all users. + List<UserHandle> users = mUserCache.getUsersCached(); + ArrayList<File> allowedPaths = new ArrayList<>(); + for (UserHandle user : users) { + Collection<File> volumeScanPaths = mVolumeCache.getVolumeScanPaths(volumeName, user); + allowedPaths.addAll(volumeScanPaths); + } + + return allowedPaths; } /** @@ -3476,7 +3488,7 @@ public class MediaProvider extends ContentProvider { final String volumeName = resolveVolumeName(uri); try { // Quick check that the requested path actually lives on volume - final Collection<File> allowed = getVolumeScanPaths(volumeName); + final Collection<File> allowed = getAllowedVolumePaths(volumeName); final File actual = new File(values.getAsString(MediaColumns.DATA)) .getCanonicalFile(); if (!FileUtils.contains(allowed, actual)) { diff --git a/src/com/android/providers/media/util/UserCache.java b/src/com/android/providers/media/util/UserCache.java index 885e07e9..276e3f8e 100644 --- a/src/com/android/providers/media/util/UserCache.java +++ b/src/com/android/providers/media/util/UserCache.java @@ -84,6 +84,12 @@ public class UserCache { } } + public @NonNull List<UserHandle> getUsersCached() { + synchronized (mLock) { + return (List<UserHandle>) mUsers.clone(); + } + } + public @NonNull Context getContextForUser(@NonNull UserHandle user) { Context userContext; synchronized (mLock) { |
