Path: blob/master/platform/android/java_godot_lib_jni.cpp
20843 views
/**************************************************************************/1/* java_godot_lib_jni.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "java_godot_lib_jni.h"3132#include "android_input_handler.h"33#include "api/java_class_wrapper.h"34#include "dir_access_jandroid.h"35#include "display_server_android.h"36#include "file_access_android.h"37#include "file_access_filesystem_jandroid.h"38#include "java_godot_io_wrapper.h"39#include "java_godot_wrapper.h"40#include "jni_utils.h"41#include "net_socket_android.h"42#include "os_android.h"43#include "plugin/godot_plugin_jni.h"44#include "thread_jandroid.h"45#include "tts_android.h"4647#include "core/config/engine.h"48#include "core/config/project_settings.h"49#include "core/input/input.h"50#include "core/os/main_loop.h"51#include "core/profiling/profiling.h"52#include "main/main.h"53#include "servers/rendering/rendering_server.h"5455#include "servers/camera/camera_server.h"5657#ifndef XR_DISABLED58#include "servers/xr/xr_server.h"59#endif // XR_DISABLED6061#ifdef TOOLS_ENABLED62#include "editor/settings/editor_settings.h"63#endif6465#include <android/asset_manager_jni.h>66#include <android/input.h>67#include <android/native_window_jni.h>68#include <unistd.h>6970static JavaClassWrapper *java_class_wrapper = nullptr;71static OS_Android *os_android = nullptr;72static AndroidInputHandler *input_handler = nullptr;73static GodotJavaWrapper *godot_java = nullptr;74static GodotIOJavaWrapper *godot_io_java = nullptr;7576enum StartupStep {77STEP_TERMINATED = -1,78STEP_SETUP,79STEP_SHOW_LOGO,80STEP_STARTED81};8283static SafeNumeric<int> step; // Shared between UI and render threads8485static Vector3 accelerometer;86static Vector3 gravity;87static Vector3 magnetometer;88static Vector3 gyroscope;8990static void _terminate(JNIEnv *env, bool p_restart = false) {91if (step.get() == STEP_TERMINATED) {92return;93}9495step.set(STEP_TERMINATED); // Ensure no further steps are attempted and no further events are sent9697// lets cleanup98// Unregister android plugins99unregister_plugins_singletons();100101if (java_class_wrapper) {102memdelete(java_class_wrapper);103}104if (input_handler) {105delete input_handler;106}107// Whether restarting is handled by 'Main::cleanup()'108bool restart_on_cleanup = false;109if (os_android) {110restart_on_cleanup = os_android->is_restart_on_exit_set();111os_android->main_loop_end();112Main::cleanup();113delete os_android;114}115if (godot_io_java) {116delete godot_io_java;117}118119TTS_Android::terminate();120FileAccessAndroid::terminate();121DirAccessJAndroid::terminate();122FileAccessFilesystemJAndroid::terminate();123NetSocketAndroid::terminate();124125cleanup_android_class_loader();126godot_cleanup_profiler();127128if (godot_java) {129godot_java->on_godot_terminating(env);130if (!restart_on_cleanup) {131if (p_restart) {132godot_java->restart(env);133} else {134godot_java->force_quit(env);135}136}137delete godot_java;138}139}140141static String rendering_source_to_string(OS::RenderingSource p_source) {142switch (p_source) {143case OS::RENDERING_SOURCE_DEFAULT:144return "Default";145case OS::RENDERING_SOURCE_PROJECT_SETTING:146return "ProjectSettings";147case OS::RENDERING_SOURCE_COMMANDLINE:148return "Commandline";149case OS::RENDERING_SOURCE_FALLBACK:150return "Fallback";151default:152return "Unknown";153}154}155156extern "C" {157158JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setVirtualKeyboardHeight(JNIEnv *env, jclass clazz, jint p_height) {159if (godot_io_java) {160godot_io_java->set_vk_height(p_height);161}162}163164JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *env, jclass clazz, jobject p_godot_instance, jobject p_asset_manager, jobject p_godot_io, jobject p_net_utils, jobject p_directory_access_handler, jobject p_file_access_handler, jboolean p_use_apk_expansion) {165godot_init_profiler();166167JavaVM *jvm;168env->GetJavaVM(&jvm);169170init_thread_jandroid(jvm, env);171setup_android_class_loader();172173// create our wrapper classes174godot_java = new GodotJavaWrapper(env, p_godot_instance);175godot_io_java = new GodotIOJavaWrapper(env, p_godot_io);176177FileAccessAndroid::setup(p_asset_manager);178DirAccessJAndroid::setup(p_directory_access_handler);179FileAccessFilesystemJAndroid::setup(p_file_access_handler);180NetSocketAndroid::setup(p_net_utils);181182os_android = new OS_Android(godot_java, godot_io_java, p_use_apk_expansion);183184return true;185}186187JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_ondestroy(JNIEnv *env, jclass clazz) {188_terminate(env, false);189}190191JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jclass clazz, jobjectArray p_cmdline, jobject p_godot_tts) {192setup_android_thread();193194const char **cmdline = nullptr;195jstring *j_cmdline = nullptr;196int cmdlen = 0;197if (p_cmdline) {198cmdlen = env->GetArrayLength(p_cmdline);199if (cmdlen) {200cmdline = (const char **)memalloc((cmdlen + 1) * sizeof(const char *));201ERR_FAIL_NULL_V_MSG(cmdline, false, "Out of memory.");202cmdline[cmdlen] = nullptr;203j_cmdline = (jstring *)memalloc(cmdlen * sizeof(jstring));204ERR_FAIL_NULL_V_MSG(j_cmdline, false, "Out of memory.");205206for (int i = 0; i < cmdlen; i++) {207jstring string = (jstring)env->GetObjectArrayElement(p_cmdline, i);208const char *rawString = env->GetStringUTFChars(string, nullptr);209210cmdline[i] = rawString;211j_cmdline[i] = string;212}213}214}215216Error err = Main::setup(OS_Android::ANDROID_EXEC_PATH, cmdlen, (char **)cmdline, false);217if (cmdline) {218if (j_cmdline) {219for (int i = 0; i < cmdlen; ++i) {220env->ReleaseStringUTFChars(j_cmdline[i], cmdline[i]);221}222memfree(j_cmdline);223}224memfree(cmdline);225}226227// Note: --help and --version return ERR_HELP, but this should be translated to 0 if exit codes are propagated.228if (err != OK) {229return false;230}231232TTS_Android::setup(p_godot_tts);233234java_class_wrapper = memnew(JavaClassWrapper);235return true;236}237238JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_resize(JNIEnv *env, jclass clazz, jobject p_surface, jint p_width, jint p_height) {239if (os_android) {240os_android->set_display_size(Size2i(p_width, p_height));241242// No need to reset the surface during startup243if (step.get() > STEP_SETUP) {244if (p_surface) {245ANativeWindow *native_window = ANativeWindow_fromSurface(env, p_surface);246os_android->set_native_window(native_window);247}248DisplayServerAndroid::get_singleton()->reset_window();249DisplayServerAndroid::get_singleton()->notify_surface_changed(p_width, p_height);250}251}252}253254JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *env, jclass clazz, jobject p_surface) {255if (os_android) {256if (step.get() == STEP_SETUP) {257// During startup258if (p_surface) {259ANativeWindow *native_window = ANativeWindow_fromSurface(env, p_surface);260os_android->set_native_window(native_window);261}262} else {263// Rendering context recreated because it was lost; restart app to let it reload everything264_terminate(env, true);265}266}267}268269JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jclass clazz) {270if (step.get() <= STEP_SETUP) {271return;272}273274if (DisplayServerAndroid *dsa = Object::cast_to<DisplayServerAndroid>(DisplayServer::get_singleton())) {275dsa->send_window_event(DisplayServer::WINDOW_EVENT_GO_BACK_REQUEST);276}277}278279JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_ttsCallback(JNIEnv *env, jclass clazz, jint event, jlong id, jint pos) {280TTS_Android::_java_utterance_callback(event, id, pos);281}282283JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jclass clazz) {284if (step.get() == STEP_TERMINATED) {285return true;286}287288if (step.get() == STEP_SETUP) {289// Since Godot is initialized on the UI thread, main_thread_id was set to that thread's id,290// but for Godot purposes, the main thread is the one running the game loop291Main::setup2(false); // The logo is shown in the next frame otherwise we run into rendering issues292input_handler = new AndroidInputHandler();293step.increment();294return true;295}296297if (step.get() == STEP_SHOW_LOGO) {298bool xr_enabled = false;299#ifndef XR_DISABLED300// Unlike PCVR, there's no additional 2D screen onto which to render the boot logo,301// so we skip this step if xr is enabled.302if (XRServer::get_xr_mode() == XRServer::XRMODE_DEFAULT) {303xr_enabled = GLOBAL_GET_CACHED(bool, "xr/shaders/enabled");304} else {305xr_enabled = XRServer::get_xr_mode() == XRServer::XRMODE_ON;306}307#endif // XR_DISABLED308if (!xr_enabled) {309Main::setup_boot_logo();310}311312step.increment();313return true;314}315316if (step.get() == STEP_STARTED) {317if (Main::start() != EXIT_SUCCESS) {318return true; // should exit instead and print the error319}320321godot_java->on_godot_setup_completed(env);322os_android->main_loop_begin();323godot_java->on_godot_main_loop_started(env);324step.increment();325}326327DisplayServerAndroid::get_singleton()->process_accelerometer(accelerometer);328DisplayServerAndroid::get_singleton()->process_gravity(gravity);329DisplayServerAndroid::get_singleton()->process_magnetometer(magnetometer);330DisplayServerAndroid::get_singleton()->process_gyroscope(gyroscope);331332bool should_swap_buffers = false;333if (os_android->main_loop_iterate(&should_swap_buffers)) {334_terminate(env, false);335}336337return should_swap_buffers;338}339340// Called on the UI thread341JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_dispatchMouseEvent(JNIEnv *env, jclass clazz, jint p_event_type, jint p_button_mask, jfloat p_x, jfloat p_y, jfloat p_delta_x, jfloat p_delta_y, jboolean p_double_click, jboolean p_source_mouse_relative, jfloat p_pressure, jfloat p_tilt_x, jfloat p_tilt_y) {342if (step.get() <= STEP_SETUP) {343return;344}345346input_handler->process_mouse_event(p_event_type, p_button_mask, Point2(p_x, p_y), Vector2(p_delta_x, p_delta_y), p_double_click, p_source_mouse_relative, p_pressure, Vector2(p_tilt_x, p_tilt_y));347}348349// Called on the UI thread350JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_dispatchTouchEvent(JNIEnv *env, jclass clazz, jint ev, jint pointer, jint pointer_count, jfloatArray position, jboolean p_double_tap) {351if (step.get() <= STEP_SETUP) {352return;353}354355Vector<AndroidInputHandler::TouchPos> points;356for (int i = 0; i < pointer_count; i++) {357jfloat p[6];358env->GetFloatArrayRegion(position, i * 6, 6, p);359AndroidInputHandler::TouchPos tp;360tp.id = (int)p[0];361tp.pos = Point2(p[1], p[2]);362tp.pressure = p[3];363tp.tilt = Vector2(p[4], p[5]);364points.push_back(tp);365}366367input_handler->process_touch_event(ev, pointer, points, p_double_tap);368}369370// Called on the UI thread371JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnify(JNIEnv *env, jclass clazz, jfloat p_x, jfloat p_y, jfloat p_factor) {372if (step.get() <= STEP_SETUP) {373return;374}375input_handler->process_magnify(Point2(p_x, p_y), p_factor);376}377378// Called on the UI thread379JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_pan(JNIEnv *env, jclass clazz, jfloat p_x, jfloat p_y, jfloat p_delta_x, jfloat p_delta_y) {380if (step.get() <= STEP_SETUP) {381return;382}383input_handler->process_pan(Point2(p_x, p_y), Vector2(p_delta_x, p_delta_y));384}385386// Called on the UI thread387JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jclass clazz, jint p_device, jint p_button, jboolean p_pressed) {388if (step.get() <= STEP_SETUP) {389return;390}391392AndroidInputHandler::JoypadEvent jevent;393jevent.device = p_device;394jevent.type = AndroidInputHandler::JOY_EVENT_BUTTON;395jevent.index = p_button;396jevent.pressed = p_pressed;397398input_handler->process_joy_event(jevent);399}400401// Called on the UI thread402JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jclass clazz, jint p_device, jint p_axis, jfloat p_value) {403if (step.get() <= STEP_SETUP) {404return;405}406407AndroidInputHandler::JoypadEvent jevent;408jevent.device = p_device;409jevent.type = AndroidInputHandler::JOY_EVENT_AXIS;410jevent.index = p_axis;411jevent.value = p_value;412413input_handler->process_joy_event(jevent);414}415416// Called on the UI thread417JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, jclass clazz, jint p_device, jint p_hat_x, jint p_hat_y) {418if (step.get() <= STEP_SETUP) {419return;420}421422AndroidInputHandler::JoypadEvent jevent;423jevent.device = p_device;424jevent.type = AndroidInputHandler::JOY_EVENT_HAT;425BitField<HatMask> hat = HatMask::CENTER;426if (p_hat_x != 0) {427if (p_hat_x < 0) {428hat.set_flag(HatMask::LEFT);429} else {430hat.set_flag(HatMask::RIGHT);431}432}433if (p_hat_y != 0) {434if (p_hat_y < 0) {435hat.set_flag(HatMask::UP);436} else {437hat.set_flag(HatMask::DOWN);438}439}440jevent.hat = hat;441442input_handler->process_joy_event(jevent);443}444445// Called on the UI thread446JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(JNIEnv *env, jclass clazz, jint p_device, jboolean p_connected, jstring p_name) {447if (os_android) {448String name = jstring_to_string(p_name, env);449Input *input = Input::get_singleton();450if (input) {451input->joy_connection_changed(p_device, p_connected, name);452}453}454}455456// Called on the UI thread457JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_physical_keycode, jint p_unicode, jint p_key_label, jboolean p_pressed, jboolean p_echo) {458if (step.get() <= STEP_SETUP) {459return;460}461input_handler->process_key_event(p_physical_keycode, p_unicode, p_key_label, p_pressed, p_echo);462}463464JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_accelerometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {465accelerometer = Vector3(x, y, z);466}467468JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gravity(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {469gravity = Vector3(x, y, z);470}471472JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnetometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {473magnetometer = Vector3(x, y, z);474}475476JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gyroscope(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {477gyroscope = Vector3(x, y, z);478}479480JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env, jclass clazz) {481if (step.get() <= STEP_SETUP) {482return;483}484485os_android->main_loop_focusin();486}487488JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv *env, jclass clazz) {489if (step.get() <= STEP_SETUP) {490return;491}492493os_android->main_loop_focusout();494}495496JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getGlobal(JNIEnv *env, jclass clazz, jstring path) {497String js = jstring_to_string(path, env);498499Variant setting_with_override = GLOBAL_GET(js);500String setting_value = (setting_with_override.get_type() == Variant::NIL) ? "" : setting_with_override;501return env->NewStringUTF(setting_value.utf8().get_data());502}503504JNIEXPORT jobjectArray JNICALL Java_org_godotengine_godot_GodotLib_getRendererInfo(JNIEnv *env, jclass clazz, jboolean p_vulkan_requirements_met) {505String rendering_driver_original = RenderingServer::get_singleton()->get_current_rendering_driver_name();506String rendering_driver_chosen = rendering_driver_original;507String rendering_method = RenderingServer::get_singleton()->get_current_rendering_method();508509#ifdef VULKAN_ENABLED510if (rendering_driver_original == "vulkan" && !DisplayServerAndroid::check_vulkan_global_context(p_vulkan_requirements_met)) {511// The Android display server only gets created after this step, so a static check must be used to check for Vulkan512// availability instead. If the check fails, it'll fall back to OpenGL3 accordingly if the relevant project setting513// is enabled. The Vulkan context created by this check will be reused by the DisplayServer afterwards.514rendering_driver_chosen = RenderingServer::get_singleton()->get_current_rendering_driver_name();515rendering_method = RenderingServer::get_singleton()->get_current_rendering_method();516}517#endif518519String rendering_driver_source = rendering_source_to_string(OS::get_singleton()->get_current_rendering_driver_name_source());520String rendering_method_source = rendering_source_to_string(OS::get_singleton()->get_current_rendering_method_source());521522jobjectArray result = env->NewObjectArray(5, jni_find_class(env, "java/lang/String"), nullptr);523env->SetObjectArrayElement(result, 0, env->NewStringUTF(rendering_driver_chosen.utf8().get_data()));524env->SetObjectArrayElement(result, 1, env->NewStringUTF(rendering_driver_original.utf8().get_data()));525env->SetObjectArrayElement(result, 2, env->NewStringUTF(rendering_method.utf8().get_data()));526env->SetObjectArrayElement(result, 3, env->NewStringUTF(rendering_driver_source.utf8().get_data()));527env->SetObjectArrayElement(result, 4, env->NewStringUTF(rendering_method_source.utf8().get_data()));528529return result;530}531532JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getEditorSetting(JNIEnv *env, jclass clazz, jstring p_setting_key) {533String editor_setting_value = "";534#ifdef TOOLS_ENABLED535String godot_setting_key = jstring_to_string(p_setting_key, env);536Variant editor_setting = EDITOR_GET(godot_setting_key);537editor_setting_value = (editor_setting.get_type() == Variant::NIL) ? "" : editor_setting;538#else539WARN_PRINT("Access to the Editor Settings in only available on Editor builds");540#endif541542return env->NewStringUTF(editor_setting_value.utf8().get_data());543}544545JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setEditorSetting(JNIEnv *env, jclass clazz, jstring p_key, jobject p_data) {546#ifdef TOOLS_ENABLED547if (EditorSettings::get_singleton() != nullptr) {548String key = jstring_to_string(p_key, env);549Variant data = _jobject_to_variant(env, p_data);550EditorSettings::get_singleton()->set(key, data);551}552#else553WARN_PRINT("Access to the Editor Settings in only available on Editor builds");554#endif555}556557JNIEXPORT jobject JNICALL Java_org_godotengine_godot_GodotLib_getEditorProjectMetadata(JNIEnv *env, jclass clazz, jstring p_section, jstring p_key, jobject p_default_value) {558jvalue result;559560#ifdef TOOLS_ENABLED561if (EditorSettings::get_singleton() != nullptr) {562String section = jstring_to_string(p_section, env);563String key = jstring_to_string(p_key, env);564Variant default_value = _jobject_to_variant(env, p_default_value);565Variant data = EditorSettings::get_singleton()->get_project_metadata(section, key, default_value);566result.l = _variant_to_jobject(env, data.get_type(), &data);567}568#else569WARN_PRINT("Access to the Editor Settings Project Metadata is only available on Editor builds");570#endif571572return result.l;573}574575JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setEditorProjectMetadata(JNIEnv *env, jclass clazz, jstring p_section, jstring p_key, jobject p_data) {576#ifdef TOOLS_ENABLED577if (EditorSettings::get_singleton() != nullptr) {578String section = jstring_to_string(p_section, env);579String key = jstring_to_string(p_key, env);580Variant data = _jobject_to_variant(env, p_data);581EditorSettings::get_singleton()->set_project_metadata(section, key, data);582}583#else584WARN_PRINT("Access to the Editor Settings Project Metadata is only available on Editor builds");585#endif586}587588JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onNightModeChanged(JNIEnv *env, jclass clazz) {589DisplayServerAndroid *ds = (DisplayServerAndroid *)DisplayServer::get_singleton();590if (ds) {591ds->emit_system_theme_changed();592}593}594595JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hardwareKeyboardConnected(JNIEnv *env, jclass clazz, jboolean p_connected) {596DisplayServerAndroid *ds = (DisplayServerAndroid *)DisplayServer::get_singleton();597if (ds) {598ds->emit_hardware_keyboard_connection_changed(p_connected);599}600}601602JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_filePickerCallback(JNIEnv *env, jclass clazz, jboolean p_ok, jobjectArray p_selected_paths) {603DisplayServerAndroid *ds = (DisplayServerAndroid *)DisplayServer::get_singleton();604if (ds) {605Vector<String> selected_paths;606607jint length = env->GetArrayLength(p_selected_paths);608for (jint i = 0; i < length; ++i) {609jstring java_string = (jstring)env->GetObjectArrayElement(p_selected_paths, i);610String path = jstring_to_string(java_string, env);611selected_paths.push_back(path);612env->DeleteLocalRef(java_string);613}614ds->emit_file_picker_callback(p_ok, selected_paths);615}616}617618JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_requestPermissionResult(JNIEnv *env, jclass clazz, jstring p_permission, jboolean p_result) {619String permission = jstring_to_string(p_permission, env);620if (permission == "android.permission.RECORD_AUDIO" && p_result) {621AudioDriver::get_singleton()->input_start();622}623624if (os_android->get_main_loop()) {625os_android->get_main_loop()->emit_signal(SNAME("on_request_permissions_result"), permission, p_result == JNI_TRUE);626}627}628629JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererResumed(JNIEnv *env, jclass clazz) {630if (step.get() <= STEP_SETUP) {631return;632}633634// We force redraw to ensure we render at least once when resuming the app.635Main::force_redraw();636CameraServer *camera_server = CameraServer::get_singleton();637if (camera_server) {638camera_server->handle_application_resume();639}640if (os_android->get_main_loop()) {641os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_RESUMED);642}643}644645JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererPaused(JNIEnv *env, jclass clazz) {646if (step.get() <= STEP_SETUP) {647return;648}649650CameraServer *camera_server = CameraServer::get_singleton();651if (camera_server) {652camera_server->handle_application_pause();653}654655if (os_android->get_main_loop()) {656os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_PAUSED);657}658659if (DisplayServerAndroid *dsa = Object::cast_to<DisplayServerAndroid>(DisplayServer::get_singleton())) {660dsa->notify_application_paused();661}662}663664JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onOrientationChange(JNIEnv *env, jclass clazz, jint p_orientation) {665if (step.get() <= STEP_SETUP) {666return;667}668669CameraServer *camera_server = CameraServer::get_singleton();670if (camera_server) {671camera_server->handle_display_rotation_change(p_orientation);672}673674DisplayServer *display_server = DisplayServer::get_singleton();675if (display_server) {676display_server->emit_signal("orientation_changed", p_orientation);677}678}679680JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_shouldDispatchInputToRenderThread(JNIEnv *env, jclass clazz) {681Input *input = Input::get_singleton();682if (input) {683return !input->is_agile_input_event_flushing();684}685return false;686}687688JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getProjectResourceDir(JNIEnv *env, jclass clazz) {689const String resource_dir = OS::get_singleton()->get_resource_dir();690return env->NewStringUTF(resource_dir.utf8().get_data());691}692JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_isEditorHint(JNIEnv *env, jclass clazz) {693Engine *engine = Engine::get_singleton();694if (engine) {695return engine->is_editor_hint();696}697return false;698}699700JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_isProjectManagerHint(JNIEnv *env, jclass clazz) {701Engine *engine = Engine::get_singleton();702if (engine) {703return engine->is_project_manager_hint();704}705return false;706}707708JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_hasFeature(JNIEnv *env, jclass clazz, jstring p_feature) {709OS *os = OS::get_singleton();710if (os) {711String feature = jstring_to_string(p_feature, env);712return os->has_feature(feature);713}714return false;715}716}717718719