diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java index f060c7aaffb..2c1a81babbf 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java @@ -131,6 +131,18 @@ public class GodotIO { return activity.getCacheDir().getAbsolutePath(); } + public String getTmpDir() { + File tmpDir = new File(getCacheDir() + "/tmp"); + + if (!tmpDir.exists()) { + if (!tmpDir.mkdirs()) { + Log.e(TAG, "Unable to create tmp dir"); + } + } + + return tmpDir.getAbsolutePath(); + } + public String getDataDir() { return activity.getFilesDir().getAbsolutePath(); } diff --git a/platform/android/java_godot_io_wrapper.cpp b/platform/android/java_godot_io_wrapper.cpp index 623db39985f..aa55339d1e3 100644 --- a/platform/android/java_godot_io_wrapper.cpp +++ b/platform/android/java_godot_io_wrapper.cpp @@ -52,6 +52,7 @@ GodotIOJavaWrapper::GodotIOJavaWrapper(JNIEnv *p_env, jobject p_godot_io_instanc _open_URI = p_env->GetMethodID(cls, "openURI", "(Ljava/lang/String;)I"); _get_cache_dir = p_env->GetMethodID(cls, "getCacheDir", "()Ljava/lang/String;"); + _get_tmp_dir = p_env->GetMethodID(cls, "getTmpDir", "()Ljava/lang/String;"); _get_data_dir = p_env->GetMethodID(cls, "getDataDir", "()Ljava/lang/String;"); _get_display_cutouts = p_env->GetMethodID(cls, "getDisplayCutouts", "()[I"), _get_display_safe_area = p_env->GetMethodID(cls, "getDisplaySafeArea", "()[I"), @@ -106,6 +107,17 @@ String GodotIOJavaWrapper::get_cache_dir() { } } +String GodotIOJavaWrapper::get_tmp_dir() { + if (_get_tmp_dir) { + JNIEnv *env = get_jni_env(); + ERR_FAIL_NULL_V(env, String()); + jstring s = (jstring)env->CallObjectMethod(godot_io_instance, _get_tmp_dir); + return jstring_to_string(s, env); + } else { + return String(); + } +} + String GodotIOJavaWrapper::get_user_data_dir() { if (_get_data_dir) { JNIEnv *env = get_jni_env(); diff --git a/platform/android/java_godot_io_wrapper.h b/platform/android/java_godot_io_wrapper.h index 0a372641cbb..b9a24b6d5ac 100644 --- a/platform/android/java_godot_io_wrapper.h +++ b/platform/android/java_godot_io_wrapper.h @@ -48,6 +48,7 @@ private: jmethodID _open_URI = 0; jmethodID _get_cache_dir = 0; jmethodID _get_data_dir = 0; + jmethodID _get_tmp_dir = 0; jmethodID _get_display_cutouts = 0; jmethodID _get_display_safe_area = 0; jmethodID _get_locale = 0; @@ -71,6 +72,7 @@ public: Error open_uri(const String &p_uri); String get_cache_dir(); + String get_tmp_dir(); String get_user_data_dir(); String get_locale(); String get_model(); diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 7b0d3a29e90..4ef4fa69fab 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -677,6 +677,19 @@ String OS_Android::get_cache_path() const { return "."; } +String OS_Android::get_tmp_path() const { + if (!tmp_dir_cache.is_empty()) { + return tmp_dir_cache; + } + + String tmp_dir = godot_io_java->get_tmp_dir(); + if (!tmp_dir.is_empty()) { + tmp_dir_cache = _remove_symlink(tmp_dir); + return tmp_dir_cache; + } + return "."; +} + String OS_Android::get_unique_id() const { String unique_id = godot_io_java->get_unique_id(); if (!unique_id.is_empty()) { diff --git a/platform/android/os_android.h b/platform/android/os_android.h index fb3cdf0d4c0..62247895a20 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -58,6 +58,7 @@ private: mutable String data_dir_cache; mutable String cache_dir_cache; + mutable String tmp_dir_cache; mutable String remote_fs_dir; AudioDriverOpenSL audio_driver_android; @@ -148,6 +149,7 @@ public: virtual String get_user_data_dir() const override; virtual String get_data_path() const override; virtual String get_cache_path() const override; + virtual String get_tmp_path() const override; virtual String get_resource_dir() const override; virtual String get_locale() const override; virtual String get_model_name() const override;