Ported: Fix directory access when the running app has the All files access permission

- m4gr3d
e2c7d3e6c0
This commit is contained in:
Relintai 2023-04-15 11:11:29 +02:00
parent 464b0b5e08
commit 76f9237411

View File

@ -76,6 +76,12 @@ internal enum class StorageScope {
return UNKNOWN return UNKNOWN
} }
// If we have 'All Files Access' permission, we can access all directories without
// restriction.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && Environment.isExternalStorageManager()) {
return APP
}
val canonicalPathFile = pathFile.canonicalPath val canonicalPathFile = pathFile.canonicalPath
if (internalAppDir != null && canonicalPathFile.startsWith(internalAppDir)) { if (internalAppDir != null && canonicalPathFile.startsWith(internalAppDir)) {
@ -90,6 +96,11 @@ internal enum class StorageScope {
return APP return APP
} }
val rootDir: String? = System.getenv("ANDROID_ROOT")
if (rootDir != null && canonicalPathFile.startsWith(rootDir)) {
return APP
}
if (sharedDir != null && canonicalPathFile.startsWith(sharedDir)) { if (sharedDir != null && canonicalPathFile.startsWith(sharedDir)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
// Before R, apps had access to shared storage so long as they have the right // Before R, apps had access to shared storage so long as they have the right