From 7ed37054872e51f6f94748a91469890d265ae8b1 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 29 Jul 2022 20:15:01 +0200 Subject: [PATCH] Ported: Fix issue causing the Android Editor port to crash when saving a scene In addition: - Disable 'adb devices' query (not supported when running the editor on Android devices - Add `move_to_trash` implementation for Android devices - m4gr3d https://github.com/godotengine/godot/commit/27b63247fda3e32af45c1e7fb1690bd064043a66 --- platform/android/export/export_plugin.cpp | 4 ++++ platform/android/os_android.cpp | 27 +++++++++++++++++++++++ platform/android/os_android.h | 2 ++ 3 files changed, 33 insertions(+) diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index b00b74fda..798a7d75a 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -260,6 +260,7 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) { } } +#ifndef ANDROID_ENABLED // Check for devices updates String adb = get_adb_path(); if (FileAccess::exists(adb)) { @@ -373,6 +374,7 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) { ea->device_lock.unlock(); } +#endif uint64_t sleep = 300'000; uint64_t wait = 3'000'000; @@ -385,6 +387,7 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) { } } +#ifndef ANDROID_ENABLED if (EditorSettings::get_singleton()->get("export/android/shutdown_adb_on_exit")) { String adb = get_adb_path(); if (!FileAccess::exists(adb)) { @@ -395,6 +398,7 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) { args.push_back("kill-server"); OS::get_singleton()->execute(adb, args, true); } +#endif } String EditorExportPlatformAndroid::get_project_name(const String &p_name) const { diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index e5fc2b711..f2f1e89bd 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -533,6 +533,33 @@ String OS_Android::get_system_dir(SystemDir p_dir, bool p_shared_storage) const return pandemonium_io_java->get_system_dir(p_dir, p_shared_storage); } +Error OS_Android::move_to_trash(const String &p_path) { + DirAccessRef da_ref = DirAccess::create_for_path(p_path); + if (!da_ref) { + 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_offscreen_gl_available(bool p_available) { secondary_gl_available = p_available; } diff --git a/platform/android/os_android.h b/platform/android/os_android.h index 3642a6d4b..5f471d188 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -169,6 +169,8 @@ public: virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const; + virtual Error move_to_trash(const String &p_path); + void process_accelerometer(const Vector3 &p_accelerometer); void process_gravity(const Vector3 &p_gravity); void process_magnetometer(const Vector3 &p_magnetometer);