Fix renaming files in clone volumes.
When an application running in the owner user tries to rename a file
that's located in a clone user volume, for example by modifying
RELATIVE_PATH, we need to make sure that we compute the new DATA
column correctly, by taking the existing location of the file into
account.
Bug: 199822693
Test: TEST_MAPPING, manual
Change-Id: Idab885dd78c75d12452319463dcc07b837502149
diff --git a/src/com/android/providers/media/MediaProvider.java b/src/com/android/providers/media/MediaProvider.java
index 6b7a866..83876f7 100644
--- a/src/com/android/providers/media/MediaProvider.java
+++ b/src/com/android/providers/media/MediaProvider.java
@@ -3601,9 +3601,23 @@
// Generate path when undefined
if (TextUtils.isEmpty(values.getAsString(MediaColumns.DATA))) {
+ // Note that just the volume name isn't enough to determine the path,
+ // since we can manage different volumes with the same name for
+ // different users. Instead, if we have a current path (which implies
+ // an already existing file to be renamed), use that to derive the
+ // user-id of the file, and in turn use that to derive the correct
+ // volume. Cross-user renames are not supported without a specified
+ // DATA column.
File volumePath;
+ UserHandle userHandle = mCallingIdentity.get().getUser();
+ if (currentPath != null) {
+ int userId = FileUtils.extractUserId(currentPath);
+ if (userId != -1) {
+ userHandle = UserHandle.of(userId);
+ }
+ }
try {
- volumePath = getVolumePath(resolvedVolumeName);
+ volumePath = mVolumeCache.getVolumePath(resolvedVolumeName, userHandle);
} catch (FileNotFoundException e) {
throw new IllegalArgumentException(e);
}