From e2c7d3e6c03176dabffe86d4c25fdc31b37096f7 Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Mon, 20 Mar 2023 08:56:04 -0700 Subject: [PATCH] Fix directory access when the running app has the `All files access` permission --- .../lib/src/org/godotengine/godot/io/StorageScope.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt b/platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt index c793921e7c66..8ee3d5f48f72 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt +++ b/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