瀏覽代碼

Merge pull request #75147 from m4gr3d/fix_directory_access_with_all_files_access_permission_3x

[3.x] Fix directory access when the running app has the `All files access` permission
Rémi Verschelde 2 年之前
父節點
當前提交
98f0809373
共有 1 個文件被更改,包括 12 次插入0 次删除
  1. 12 0
      platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt

+ 12 - 0
platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt

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