mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Fixes on android:
- checking for validity of ENV in wrapper classes
- fix for access to JavaVM from threads
(cherry picked from commit b3a43430aa)
This commit is contained in:
parent
e97cd3d52d
commit
abaa032fae
4 changed files with 76 additions and 1 deletions
|
|
@ -77,6 +77,7 @@ jobject GodotIOJavaWrapper::get_instance() {
|
|||
Error GodotIOJavaWrapper::open_uri(const String &p_uri) {
|
||||
if (_open_URI) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, ERR_UNAVAILABLE);
|
||||
jstring jStr = env->NewStringUTF(p_uri.utf8().get_data());
|
||||
return env->CallIntMethod(godot_io_instance, _open_URI, jStr) ? ERR_CANT_OPEN : OK;
|
||||
} else {
|
||||
|
|
@ -87,6 +88,7 @@ Error GodotIOJavaWrapper::open_uri(const String &p_uri) {
|
|||
String GodotIOJavaWrapper::get_user_data_dir() {
|
||||
if (_get_data_dir) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, String());
|
||||
jstring s = (jstring)env->CallObjectMethod(godot_io_instance, _get_data_dir);
|
||||
return jstring_to_string(s, env);
|
||||
} else {
|
||||
|
|
@ -97,6 +99,7 @@ String GodotIOJavaWrapper::get_user_data_dir() {
|
|||
String GodotIOJavaWrapper::get_locale() {
|
||||
if (_get_locale) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, String());
|
||||
jstring s = (jstring)env->CallObjectMethod(godot_io_instance, _get_locale);
|
||||
return jstring_to_string(s, env);
|
||||
} else {
|
||||
|
|
@ -107,6 +110,7 @@ String GodotIOJavaWrapper::get_locale() {
|
|||
String GodotIOJavaWrapper::get_model() {
|
||||
if (_get_model) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, String());
|
||||
jstring s = (jstring)env->CallObjectMethod(godot_io_instance, _get_model);
|
||||
return jstring_to_string(s, env);
|
||||
} else {
|
||||
|
|
@ -117,6 +121,7 @@ String GodotIOJavaWrapper::get_model() {
|
|||
int GodotIOJavaWrapper::get_screen_dpi() {
|
||||
if (_get_screen_DPI) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, 160);
|
||||
return env->CallIntMethod(godot_io_instance, _get_screen_DPI);
|
||||
} else {
|
||||
return 160;
|
||||
|
|
@ -126,6 +131,7 @@ int GodotIOJavaWrapper::get_screen_dpi() {
|
|||
void GodotIOJavaWrapper::get_window_safe_area(int (&p_rect_xywh)[4]) {
|
||||
if (_get_window_safe_area) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND(env == nullptr);
|
||||
jintArray returnArray = (jintArray)env->CallObjectMethod(godot_io_instance, _get_window_safe_area);
|
||||
ERR_FAIL_COND(env->GetArrayLength(returnArray) != 4);
|
||||
jint *arrayBody = env->GetIntArrayElements(returnArray, JNI_FALSE);
|
||||
|
|
@ -139,6 +145,7 @@ void GodotIOJavaWrapper::get_window_safe_area(int (&p_rect_xywh)[4]) {
|
|||
String GodotIOJavaWrapper::get_unique_id() {
|
||||
if (_get_unique_id) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, String());
|
||||
jstring s = (jstring)env->CallObjectMethod(godot_io_instance, _get_unique_id);
|
||||
return jstring_to_string(s, env);
|
||||
} else {
|
||||
|
|
@ -153,6 +160,7 @@ bool GodotIOJavaWrapper::has_vk() {
|
|||
void GodotIOJavaWrapper::show_vk(const String &p_existing, bool p_multiline, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
|
||||
if (_show_keyboard) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND(env == nullptr);
|
||||
jstring jStr = env->NewStringUTF(p_existing.utf8().get_data());
|
||||
env->CallVoidMethod(godot_io_instance, _show_keyboard, jStr, p_multiline, p_max_input_length, p_cursor_start, p_cursor_end);
|
||||
}
|
||||
|
|
@ -161,6 +169,7 @@ void GodotIOJavaWrapper::show_vk(const String &p_existing, bool p_multiline, int
|
|||
void GodotIOJavaWrapper::hide_vk() {
|
||||
if (_hide_keyboard) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND(env == nullptr);
|
||||
env->CallVoidMethod(godot_io_instance, _hide_keyboard);
|
||||
}
|
||||
}
|
||||
|
|
@ -168,6 +177,7 @@ void GodotIOJavaWrapper::hide_vk() {
|
|||
void GodotIOJavaWrapper::set_screen_orientation(int p_orient) {
|
||||
if (_set_screen_orientation) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND(env == nullptr);
|
||||
env->CallVoidMethod(godot_io_instance, _set_screen_orientation, p_orient);
|
||||
}
|
||||
}
|
||||
|
|
@ -175,6 +185,7 @@ void GodotIOJavaWrapper::set_screen_orientation(int p_orient) {
|
|||
int GodotIOJavaWrapper::get_screen_orientation() const {
|
||||
if (_get_screen_orientation) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, 0);
|
||||
return env->CallIntMethod(godot_io_instance, _get_screen_orientation);
|
||||
} else {
|
||||
return 0;
|
||||
|
|
@ -184,6 +195,7 @@ int GodotIOJavaWrapper::get_screen_orientation() const {
|
|||
String GodotIOJavaWrapper::get_system_dir(int p_dir) {
|
||||
if (_get_system_dir) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, String("."));
|
||||
jstring s = (jstring)env->CallObjectMethod(godot_io_instance, _get_system_dir, p_dir);
|
||||
return jstring_to_string(s, env);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue