Restore files ownership only when file isn't pending anymore

because the system doesn't allow us to open files that we don't own
This commit is contained in:
Torsten Grote 2024-08-22 09:34:59 -03:00
parent 3683f82363
commit a2189bc1f7
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF

View file

@ -122,8 +122,6 @@ internal class FileRestore(
val contentValues = ContentValues().apply { val contentValues = ContentValues().apply {
put(MediaColumns.DISPLAY_NAME, mediaFile.name) put(MediaColumns.DISPLAY_NAME, mediaFile.name)
put(MediaColumns.RELATIVE_PATH, mediaFile.path) put(MediaColumns.RELATIVE_PATH, mediaFile.path)
// changing owner requires backup permission
put(MediaColumns.OWNER_PACKAGE_NAME, mediaFile.ownerPackageName)
put(MediaColumns.IS_PENDING, 1) put(MediaColumns.IS_PENDING, 1)
put(MediaColumns.IS_FAVORITE, if (mediaFile.isFavorite) 1 else 0) put(MediaColumns.IS_FAVORITE, if (mediaFile.isFavorite) 1 else 0)
} }
@ -139,6 +137,9 @@ internal class FileRestore(
contentValues.clear() contentValues.clear()
contentValues.apply { contentValues.apply {
put(MediaColumns.IS_PENDING, 0) put(MediaColumns.IS_PENDING, 0)
// changing owner requires backup permission
// done here because we are not allowed to access pending media we don't own
put(MediaColumns.OWNER_PACKAGE_NAME, mediaFile.ownerPackageName)
} }
try { try {
contentResolver.update(uri, contentValues, null, null) contentResolver.update(uri, contentValues, null, null)