Modern Apps git

← Modern-Apps.git

photos: a denied album move can no longer fire on a later consent

Commit
58e61f10f493fac45fcd5c55ac4f0f8feb2ca5bb
Author
Vayun Mathur <[email protected]>
When
2026-12-01 06:51 UTC (5 days ago)
Parents
4460173
The pending-move record outlived its consent request: the
media-result launchers reacted only to RESULT_OK and left
pendingMove set on any other result. Sequence: user refuses
a move of photo P to album X (system consent denied), later
selects Q and approves a trash/delete request on the same
launcher — RESULT_OK consumed the stale move, rewriting P's
RELATIVE_PATH to Pictures/X and recording it in album X:
photos the user explicitly refused to move were moved, and
the trash action's own clear-selection/resync was swallowed
so trashed items stayed selected. AlbumDetailPage had the
same hole for denied rename/remove/delete-album moves.

The ViewModel (owner of pendingMove) now has
abandonPendingMove(), called by both launchers on any
non-OK result; a later grant can then only run the move it
actually approved. New regression test requests a move,
abandons it via the denial path, asserts a later consume
returns false with the album untouched, then a fresh granted
move still applies. Sync watermark, secure-folder restore,
face clustering and share GPS stripping were audited and
cleared. Verified: :photos:testDevUnitTest 414 tests pass;
lint errors are pre-existing on untouched files.

Diff

photos/src/main/java/com/vayunmathur/photos/platform/GalleryViewModel.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/platform/GalleryViewModel.kt b/photos/src/main/java/com/vayunmathur/photos/platform/GalleryViewModel.ktindex 77621175c9..4de88f2135 100644--- a/photos/src/main/java/com/vayunmathur/photos/platform/GalleryViewModel.kt+++ b/photos/src/main/java/com/vayunmathur/photos/platform/GalleryViewModel.kt@@ -639,6 +639,21 @@ class GalleryViewModel(         return true     } +    /**+     * Drop the move recorded by [requestAlbumMove] without performing it.+     *+     * The launchers that run the write-consent request must call this when+     * that request ends without RESULT_OK (user denied/cancelled): the move+     * was never granted, so nothing may perform it later. Leaving it in+     * place lets the next RESULT_OK delivered to a shared launcher (a trash,+     * delete or secure-folder grant) consume the stale move and relocate+     * photos the user explicitly refused to move, while also swallowing+     * that action's own clear-selection/resync.+     */+    fun abandonPendingMove() {+        pendingMove = null+    }+     /**      * Persist the RELATIVE_PATH move for [photos] into [album] (null = move back      * to the media root), then reflect the new bucket locally and resync. Write
photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailPage.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailPage.kt b/photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailPage.ktindex 098d799617..5602cb1058 100644--- a/photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailPage.kt+++ b/photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailPage.kt@@ -68,6 +68,10 @@ fun AlbumDetailPage(             }         } else {             pendingPop = false+            // Denied/cancelled: the pending move dies with its request, so a+            // later grant elsewhere cannot execute it (see+            // GalleryViewModel.abandonPendingMove).+            galleryViewModel.abandonPendingMove()         }     } 
photos/src/main/java/com/vayunmathur/photos/ui/RememberGalleryActions.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/RememberGalleryActions.kt b/photos/src/main/java/com/vayunmathur/photos/ui/RememberGalleryActions.ktindex 6fb1195e79..67ccb3608b 100644--- a/photos/src/main/java/com/vayunmathur/photos/ui/RememberGalleryActions.kt+++ b/photos/src/main/java/com/vayunmathur/photos/ui/RememberGalleryActions.kt@@ -56,6 +56,11 @@ fun rememberGalleryActions(                 galleryViewModel.clearSelection()                 galleryViewModel.runSync()             }+        } else {+            // Denied/cancelled: any pending album move dies with its request, so a+            // later grant on this shared launcher cannot execute it (see+            // GalleryViewModel.abandonPendingMove).+            galleryViewModel.abandonPendingMove()         }     } 
photos/src/test/java/com/vayunmathur/photos/util/GalleryViewModelRealRepoTest.kt
diff --git a/photos/src/test/java/com/vayunmathur/photos/util/GalleryViewModelRealRepoTest.kt b/photos/src/test/java/com/vayunmathur/photos/util/GalleryViewModelRealRepoTest.ktindex b382b6d513..4b5fae22a4 100644--- a/photos/src/test/java/com/vayunmathur/photos/util/GalleryViewModelRealRepoTest.kt+++ b/photos/src/test/java/com/vayunmathur/photos/util/GalleryViewModelRealRepoTest.kt@@ -191,6 +191,35 @@ class GalleryViewModelRealRepoTest {         Unit     } +    @Test fun deniedAlbumMoveIsAbandonedAndCannotHijackLaterGrant() = runBlocking {+        // Provider whose update always succeeds, so a wrongly-consumed move+        // would visibly land in Room (the pre-fix failure mode).+        val provider = UpdateProvider()+        provider.attachInfo(app, android.content.pm.ProviderInfo().apply {+            authority = "media"+            packageName = app.packageName+        })+        org.robolectric.shadows.ShadowContentResolver.registerProviderInternal("media", provider)+        val repo = installed.photos+        repo.upsertAll(listOf(photo("stay", 100L)))+        val row = repo.getAll().single()+        val vm = viewModel()+        // User denied the album-move write request: the launcher's non-OK+        // path abandons the pending move.+        vm.requestAlbumMove(listOf(row), "Holidays")+        vm.abandonPendingMove()+        // A later RESULT_OK on the shared launcher (e.g. an approved trash)+        // must find nothing to consume and must not relocate the photo.+        assertFalse(vm.consumePendingMove())+        assertEquals(null, repo.getAll().single().album)+        // Abandoning does not poison the state machine: a fresh, granted+        // move still consumes and applies.+        vm.requestAlbumMove(listOf(row), "Holidays")+        assertTrue(vm.consumePendingMove())+        await("granted move applied") { repo.getAll().single().album == "Holidays" }+        Unit+    }+     @Test fun pendingAlbumMoveBookkeeping() = runBlocking {         val repo = installed.photos         repo.upsertAll(listOf(photo("a", 100L)))