Prompt for shared folders named Android/data, and reload after any regrant (#3435)

Prompt for shared folders named Android/data, and reload the folder after any regrant
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-29 15:06:47 -05:00
1 parent ae94009382
commit 678057d727
3 files changed
+11 -6

No files matched your search

@@ -8,15 +8,17 @@ import android.os.Environment
import android.provider.Settings
object AllFilesAccess {
private val VOLUME = Regex("^(/storage/emulated/\\d+|/storage/[^/]+|/sdcard)(/.*)?$")
private val APP_FOLDERS = listOf("/Android/data", "/Android/obb")
fun missing(sdk: Int = Build.VERSION.SDK_INT, granted: () -> Boolean = { Environment.isExternalStorageManager() }): Boolean =
sdk >= Build.VERSION_CODES.R && !granted()
/** Whether reading [path] takes all-files access: shared storage, outside the per-app folders Android always lets the app use. */
fun covers(path: String): Boolean =
(path.startsWith("/storage/") || path.startsWith("/sdcard")) &&
APP_FOLDERS.none { path.endsWith(it) || path.contains("$it/") }
/** Whether reading [path] takes all-files access: shared storage, outside the per-app folders directly under a volume's root, which Android always lets the app use. */
fun covers(path: String): Boolean {
val inside = VOLUME.matchEntire(path)?.groupValues?.get(2) ?: return false
return APP_FOLDERS.none { inside == it || inside.startsWith("$it/") }
}
fun open(context: Context) {
val app = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, Uri.parse("package:" + context.packageName))
@@ -527,8 +527,9 @@ fun FileManagerScreen(
LaunchedEffect(currentDir, storageTick) {
if (!AllFilesAccess.missing()) {
if (accessWasMissing) { accessWasMissing = false; loadDirectory(currentDir, resetScroll = false, record = false) }
} else if (!accessDeclined && accessDrive == null && AllFilesAccess.covers(currentDir.path)) {
accessDrive = drives.firstOrNull { currentDir.path.startsWith(it.dir.path) }?.label ?: context.getString(R.string.fm_drive_internal)
} else {
accessWasMissing = true
if (!accessDeclined && accessDrive == null && AllFilesAccess.covers(currentDir.path)) accessDrive = drives.firstOrNull { currentDir.path.startsWith(it.dir.path) }?.label ?: context.getString(R.string.fm_drive_internal)
}
}
val linuxRoot = remember(storageTick) {