From a2189bc1f753a895c34491a9bdc45bb1c4c89adc Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Thu, 22 Aug 2024 09:34:59 -0300 Subject: [PATCH] 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 --- .../java/org/calyxos/backup/storage/restore/FileRestore.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/storage/lib/src/main/java/org/calyxos/backup/storage/restore/FileRestore.kt b/storage/lib/src/main/java/org/calyxos/backup/storage/restore/FileRestore.kt index 4084d73cd..facf90c33 100644 --- a/storage/lib/src/main/java/org/calyxos/backup/storage/restore/FileRestore.kt +++ b/storage/lib/src/main/java/org/calyxos/backup/storage/restore/FileRestore.kt @@ -122,8 +122,6 @@ internal class FileRestore( val contentValues = ContentValues().apply { put(MediaColumns.DISPLAY_NAME, mediaFile.name) 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_FAVORITE, if (mediaFile.isFavorite) 1 else 0) } @@ -139,6 +137,9 @@ internal class FileRestore( contentValues.clear() contentValues.apply { 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 { contentResolver.update(uri, contentValues, null, null)