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

This commit is contained in:
Fredia Huya-Kouadio 2023-03-20 08:56:04 -07:00
parent 18398f477c
commit e2c7d3e6c0

View File

@ -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)) {
@ -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