Skip to content

Commit

Permalink
Fix directory access when the running app has the All files access
Browse files Browse the repository at this point in the history
…permission
  • Loading branch information
m4gr3d committed Mar 20, 2023
1 parent 18398f4 commit e2c7d3e
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ internal enum class StorageScope {
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

if (internalAppDir != null && canonicalPathFile.startsWith(internalAppDir)) {
Expand All @@ -90,6 +97,11 @@ internal enum class StorageScope {
return APP
}

val rootDir: String? = System.getenv("ANDROID_ROOT")
if (rootDir != null && canonicalPathFile.startsWith(rootDir)) {
return APP
}

if (sharedDir != null && canonicalPathFile.startsWith(sharedDir)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
// Before R, apps had access to shared storage so long as they have the right
Expand Down

0 comments on commit e2c7d3e

Please sign in to comment.