Skip to content

Commit 791e70d

Browse files
committed
Fixed: Lost persisted URIs after granted
1 parent 0545320 commit 791e70d

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ android.useAndroidX=true
1919
android.enableJetifier=true
2020
# Kotlin code style for this project: "official" or "obsolete":
2121
kotlin.code.style=official
22-
STORAGE_VERSION=0.4.0
22+
STORAGE_VERSION=0.4.1

storage/src/main/java/com/anggrayudi/storage/SimpleStorage.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,9 @@ class SimpleStorage private constructor(private val wrapper: ComponentWrapper) {
360360
.filter { it.isReadPermission && it.isWritePermission && it.uri.isExternalStorageDocument }
361361
.map { it.uri }
362362
val writeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
363-
val uniqueUriParents = DocumentFileCompat.findUniqueParents(persistedUris.mapNotNull { it.path })
363+
val uniqueUriParents = DocumentFileCompat.findUniqueParents(persistedUris.mapNotNull { it.path?.substringAfter("/tree/") })
364364
persistedUris.forEach {
365-
if (it.path !in uniqueUriParents) {
365+
if (DocumentFileCompat.buildAbsolutePath(it.path.orEmpty().substringAfter("/tree/")) !in uniqueUriParents) {
366366
resolver.releasePersistableUriPermission(it, writeFlags)
367367
Timber.d("Removed redundant URI permission => $it")
368368
}

storage/src/test/java/com/anggrayudi/storage/file/DocumentFileCompatTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ class DocumentFileCompatTest {
5959
"/storage/9016-4EF8/Music/Favorites/Pop",
6060
"/storage/emulated/0/Music",
6161
"/storage/emulated/0/Music Indo",
62-
"/tree/primary/b/c",
63-
"/tree/primary/b",
64-
"/tree/primary/b/d",
62+
"/folder/subFolder/b/c",
63+
"/folder/subFolder/b",
64+
"/folder/subFolder/b/d",
6565
"primary:Alarm/Morning",
6666
"primary:Alarm",
6767
)
@@ -72,7 +72,7 @@ class DocumentFileCompatTest {
7272
"/storage/9016-4EF8/Music",
7373
"/storage/emulated/0/Music",
7474
"/storage/emulated/0/Music Indo",
75-
"/tree/primary/b",
75+
"/folder/subFolder/b",
7676
"/storage/emulated/0/Alarm",
7777
)
7878

0 commit comments

Comments
 (0)