From f9c19298ce9ba7a9a9943949b40c757979706a5a Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Sat, 10 Jul 2021 18:39:31 -0700 Subject: Add full support for Android scoped storage. This was done by refactoring directory and file access handling for the Android platform so that any general filesystem access type go through the Android layer. This allows us to validate whether the access is unrestricted, or whether it falls under scoped storage and thus act appropriately. --- platform/android/os_android.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'platform/android/os_android.cpp') diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 6674428de8..0f551e7f4f 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -40,6 +40,7 @@ #include "dir_access_jandroid.h" #include "file_access_android.h" +#include "file_access_filesystem_jandroid.h" #include "net_socket_android.h" #include @@ -93,7 +94,7 @@ void OS_Android::initialize_core() { } #endif FileAccess::make_default(FileAccess::ACCESS_USERDATA); - FileAccess::make_default(FileAccess::ACCESS_FILESYSTEM); + FileAccess::make_default(FileAccess::ACCESS_FILESYSTEM); #ifdef TOOLS_ENABLED DirAccess::make_default(DirAccess::ACCESS_RESOURCES); @@ -105,7 +106,7 @@ void OS_Android::initialize_core() { } #endif DirAccess::make_default(DirAccess::ACCESS_USERDATA); - DirAccess::make_default(DirAccess::ACCESS_FILESYSTEM); + DirAccess::make_default(DirAccess::ACCESS_FILESYSTEM); NetSocketAndroid::make_default(); } @@ -300,6 +301,33 @@ String OS_Android::get_system_dir(SystemDir p_dir, bool p_shared_storage) const return godot_io_java->get_system_dir(p_dir, p_shared_storage); } +Error OS_Android::move_to_trash(const String &p_path) { + Ref da_ref = DirAccess::create_for_path(p_path); + if (da_ref.is_null()) { + return FAILED; + } + + // Check if it's a directory + if (da_ref->dir_exists(p_path)) { + Error err = da_ref->change_dir(p_path); + if (err) { + return err; + } + // This is directory, let's erase its contents + err = da_ref->erase_contents_recursive(); + if (err) { + return err; + } + // Remove the top directory + return da_ref->remove(p_path); + } else if (da_ref->file_exists(p_path)) { + // This is a file, let's remove it. + return da_ref->remove(p_path); + } else { + return FAILED; + } +} + void OS_Android::set_display_size(const Size2i &p_size) { display_size = p_size; } -- cgit v1.2.3