java_godot_lib_jni.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. /*************************************************************************/
  2. /* java_godot_lib_jni.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "java_godot_lib_jni.h"
  31. #include "java_godot_io_wrapper.h"
  32. #include "java_godot_wrapper.h"
  33. #include "android/asset_manager_jni.h"
  34. #include "android_input_handler.h"
  35. #include "api/java_class_wrapper.h"
  36. #include "api/jni_singleton.h"
  37. #include "core/engine.h"
  38. #include "core/project_settings.h"
  39. #include "dir_access_jandroid.h"
  40. #include "file_access_android.h"
  41. #include "file_access_filesystem_jandroid.h"
  42. #include "jni_utils.h"
  43. #include "main/input_default.h"
  44. #include "main/main.h"
  45. #include "net_socket_android.h"
  46. #include "os_android.h"
  47. #include "string_android.h"
  48. #include "thread_jandroid.h"
  49. #include "tts_android.h"
  50. #include <android/input.h>
  51. #include <unistd.h>
  52. static JavaClassWrapper *java_class_wrapper = nullptr;
  53. static OS_Android *os_android = nullptr;
  54. static AndroidInputHandler *input_handler = nullptr;
  55. static GodotJavaWrapper *godot_java = nullptr;
  56. static GodotIOJavaWrapper *godot_io_java = nullptr;
  57. static SafeNumeric<int> step; // Shared between UI and render threads
  58. static Size2 new_size;
  59. static Vector3 accelerometer;
  60. static Vector3 gravity;
  61. static Vector3 magnetometer;
  62. static Vector3 gyroscope;
  63. static void _initialize_java_modules() {
  64. if (!ProjectSettings::get_singleton()->has_setting("android/modules")) {
  65. return;
  66. }
  67. String modules = ProjectSettings::get_singleton()->get("android/modules");
  68. modules = modules.strip_edges();
  69. if (modules == String()) {
  70. return;
  71. }
  72. Vector<String> mods = modules.split(",", false);
  73. if (mods.size()) {
  74. jobject cls = godot_java->get_class_loader();
  75. // TODO create wrapper for class loader
  76. JNIEnv *env = get_jni_env();
  77. jclass classLoader = env->FindClass("java/lang/ClassLoader");
  78. jmethodID findClass = env->GetMethodID(classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
  79. for (int i = 0; i < mods.size(); i++) {
  80. String m = mods[i];
  81. // Deprecated in Godot 3.2.2, it's now a plugin to enable in export preset.
  82. if (m == "org/godotengine/godot/GodotPaymentV3") {
  83. WARN_PRINT("GodotPaymentV3 is deprecated and is replaced by the 'GodotPayment' plugin, which should be enabled in the Android export preset.");
  84. print_line("Skipping Android module: " + m);
  85. continue;
  86. }
  87. print_line("Loading Android module: " + m);
  88. jstring strClassName = env->NewStringUTF(m.utf8().get_data());
  89. jclass singletonClass = (jclass)env->CallObjectMethod(cls, findClass, strClassName);
  90. ERR_CONTINUE_MSG(!singletonClass, "Couldn't find singleton for class: " + m + ".");
  91. jmethodID initialize = env->GetStaticMethodID(singletonClass, "initialize", "(Landroid/app/Activity;)Lorg/godotengine/godot/Godot$SingletonBase;");
  92. ERR_CONTINUE_MSG(!initialize, "Couldn't find proper initialize function 'public static Godot.SingletonBase Class::initialize(Activity p_activity)' initializer for singleton class: " + m + ".");
  93. jobject obj = env->CallStaticObjectMethod(singletonClass, initialize, godot_java->get_activity());
  94. env->NewGlobalRef(obj);
  95. }
  96. }
  97. }
  98. static void _terminate(JNIEnv *env, bool p_restart = false) {
  99. step.set(-1); // Ensure no further steps are attempted and no further events are sent
  100. // lets cleanup
  101. if (java_class_wrapper) {
  102. memdelete(java_class_wrapper);
  103. }
  104. if (input_handler) {
  105. delete input_handler;
  106. }
  107. // Whether restarting is handled by 'Main::cleanup()'
  108. bool restart_on_cleanup = false;
  109. if (os_android) {
  110. restart_on_cleanup = os_android->is_restart_on_exit_set();
  111. os_android->main_loop_end();
  112. Main::cleanup();
  113. delete os_android;
  114. }
  115. if (godot_io_java) {
  116. delete godot_io_java;
  117. }
  118. if (godot_java) {
  119. godot_java->destroy_offscreen_gl(env);
  120. if (!restart_on_cleanup) {
  121. if (p_restart) {
  122. godot_java->restart(env);
  123. } else {
  124. godot_java->force_quit(env);
  125. }
  126. }
  127. delete godot_java;
  128. }
  129. }
  130. extern "C" {
  131. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setVirtualKeyboardHeight(JNIEnv *env, jclass clazz, jint p_height) {
  132. if (godot_io_java) {
  133. godot_io_java->set_vk_height(p_height);
  134. }
  135. }
  136. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *env, jclass clazz, jobject p_activity, 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, jobject p_godot_tts) {
  137. JavaVM *jvm;
  138. env->GetJavaVM(&jvm);
  139. // create our wrapper classes
  140. godot_java = new GodotJavaWrapper(env, p_activity, p_godot_instance);
  141. godot_io_java = new GodotIOJavaWrapper(env, p_godot_io);
  142. init_thread_jandroid(jvm, env);
  143. jobject amgr = env->NewGlobalRef(p_asset_manager);
  144. FileAccessAndroid::asset_manager = AAssetManager_fromJava(env, amgr);
  145. DirAccessJAndroid::setup(p_directory_access_handler);
  146. FileAccessFilesystemJAndroid::setup(p_file_access_handler);
  147. NetSocketAndroid::setup(p_net_utils);
  148. TTS_Android::setup(p_godot_tts);
  149. os_android = new OS_Android(godot_java, godot_io_java, p_use_apk_expansion);
  150. godot_java->on_video_init(env);
  151. }
  152. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_ondestroy(JNIEnv *env, jclass clazz) {
  153. _terminate(env, false);
  154. }
  155. JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jclass clazz, jobjectArray p_cmdline) {
  156. setup_android_thread();
  157. const char **cmdline = nullptr;
  158. jstring *j_cmdline = nullptr;
  159. int cmdlen = 0;
  160. if (p_cmdline) {
  161. cmdlen = env->GetArrayLength(p_cmdline);
  162. if (cmdlen) {
  163. cmdline = (const char **)memalloc((cmdlen + 1) * sizeof(const char *));
  164. ERR_FAIL_NULL_V_MSG(cmdline, false, "Out of memory.");
  165. cmdline[cmdlen] = nullptr;
  166. j_cmdline = (jstring *)memalloc(cmdlen * sizeof(jstring));
  167. ERR_FAIL_NULL_V_MSG(j_cmdline, false, "Out of memory.");
  168. for (int i = 0; i < cmdlen; i++) {
  169. jstring string = (jstring)env->GetObjectArrayElement(p_cmdline, i);
  170. const char *rawString = env->GetStringUTFChars(string, nullptr);
  171. cmdline[i] = rawString;
  172. j_cmdline[i] = string;
  173. }
  174. }
  175. }
  176. Error err = Main::setup(OS_Android::ANDROID_EXEC_PATH, cmdlen, (char **)cmdline, false);
  177. if (cmdline) {
  178. if (j_cmdline) {
  179. for (int i = 0; i < cmdlen; ++i) {
  180. env->ReleaseStringUTFChars(j_cmdline[i], cmdline[i]);
  181. }
  182. memfree(j_cmdline);
  183. }
  184. memfree(cmdline);
  185. }
  186. // Note: --help and --version return ERR_HELP, but this should be translated to 0 if exit codes are propagated.
  187. if (err != OK) {
  188. return false;
  189. }
  190. java_class_wrapper = memnew(JavaClassWrapper(godot_java->get_activity()));
  191. ClassDB::register_class<JNISingleton>();
  192. _initialize_java_modules();
  193. return true;
  194. }
  195. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_resize(JNIEnv *env, jclass clazz, jint width, jint height) {
  196. if (os_android) {
  197. os_android->set_display_size(Size2(width, height));
  198. }
  199. }
  200. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *env, jclass clazz) {
  201. if (os_android) {
  202. if (step.get() == 0) {
  203. // During startup
  204. os_android->set_offscreen_gl_available(godot_java->create_offscreen_gl(env));
  205. } else {
  206. // GL context recreated because it was lost; restart app to let it reload everything
  207. _terminate(env, true);
  208. }
  209. }
  210. }
  211. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jclass clazz) {
  212. if (step.get() == 0) {
  213. return;
  214. }
  215. if (os_android->get_main_loop()) {
  216. os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_GO_BACK_REQUEST);
  217. }
  218. }
  219. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_ttsCallback(JNIEnv *env, jclass clazz, jint event, jint id, jint pos) {
  220. TTS_Android::_java_utterance_callback(event, id, pos);
  221. }
  222. JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jclass clazz) {
  223. if (step.get() == -1) {
  224. return true;
  225. }
  226. if (step.get() == 0) {
  227. // Since Godot is initialized on the UI thread, _main_thread_id was set to that thread's id,
  228. // but for Godot purposes, the main thread is the one running the game loop
  229. Main::setup2(Thread::get_caller_id());
  230. input_handler = new AndroidInputHandler();
  231. step.increment();
  232. return true;
  233. }
  234. if (step.get() == 1) {
  235. if (!Main::start()) {
  236. return true; // should exit instead and print the error
  237. }
  238. godot_java->on_godot_setup_completed(env);
  239. os_android->main_loop_begin();
  240. godot_java->on_godot_main_loop_started(env);
  241. step.increment();
  242. }
  243. os_android->process_accelerometer(accelerometer);
  244. os_android->process_gravity(gravity);
  245. os_android->process_magnetometer(magnetometer);
  246. os_android->process_gyroscope(gyroscope);
  247. bool should_swap_buffers = false;
  248. if (os_android->main_loop_iterate(&should_swap_buffers)) {
  249. _terminate(env, false);
  250. }
  251. return should_swap_buffers;
  252. }
  253. // Called on the UI thread
  254. JNIEXPORT 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) {
  255. if (step.get() <= 0) {
  256. return;
  257. }
  258. input_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);
  259. }
  260. // Called on the UI thread
  261. JNIEXPORT 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) {
  262. if (step.get() <= 0) {
  263. return;
  264. }
  265. Vector<AndroidInputHandler::TouchPos> points;
  266. for (int i = 0; i < pointer_count; i++) {
  267. jfloat p[3];
  268. env->GetFloatArrayRegion(position, i * 3, 3, p);
  269. AndroidInputHandler::TouchPos tp;
  270. tp.pos = Point2(p[1], p[2]);
  271. tp.id = (int)p[0];
  272. points.push_back(tp);
  273. }
  274. input_handler->process_touch_event(ev, pointer, points, p_double_tap);
  275. }
  276. // Called on the UI thread
  277. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnify(JNIEnv *env, jclass clazz, jfloat p_x, jfloat p_y, jfloat p_factor) {
  278. if (step.get() <= 0) {
  279. return;
  280. }
  281. input_handler->process_magnify(Point2(p_x, p_y), p_factor);
  282. }
  283. // Called on the UI thread
  284. JNIEXPORT 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) {
  285. if (step.get() <= 0) {
  286. return;
  287. }
  288. input_handler->process_pan(Point2(p_x, p_y), Vector2(p_delta_x, p_delta_y));
  289. }
  290. // Called on the UI thread
  291. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jclass clazz, jint p_device, jint p_button, jboolean p_pressed) {
  292. if (step.get() <= 0) {
  293. return;
  294. }
  295. AndroidInputHandler::JoypadEvent jevent;
  296. jevent.device = p_device;
  297. jevent.type = AndroidInputHandler::JOY_EVENT_BUTTON;
  298. jevent.index = p_button;
  299. jevent.pressed = p_pressed;
  300. input_handler->process_joy_event(jevent);
  301. }
  302. // Called on the UI thread
  303. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jclass clazz, jint p_device, jint p_axis, jfloat p_value) {
  304. if (step.get() <= 0) {
  305. return;
  306. }
  307. AndroidInputHandler::JoypadEvent jevent;
  308. jevent.device = p_device;
  309. jevent.type = AndroidInputHandler::JOY_EVENT_AXIS;
  310. jevent.index = p_axis;
  311. jevent.value = p_value;
  312. input_handler->process_joy_event(jevent);
  313. }
  314. // Called on the UI thread
  315. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, jclass clazz, jint p_device, jint p_hat_x, jint p_hat_y) {
  316. if (step.get() <= 0) {
  317. return;
  318. }
  319. AndroidInputHandler::JoypadEvent jevent;
  320. jevent.device = p_device;
  321. jevent.type = AndroidInputHandler::JOY_EVENT_HAT;
  322. int hat = 0;
  323. if (p_hat_x != 0) {
  324. if (p_hat_x < 0) {
  325. hat |= InputDefault::HAT_MASK_LEFT;
  326. } else {
  327. hat |= InputDefault::HAT_MASK_RIGHT;
  328. }
  329. }
  330. if (p_hat_y != 0) {
  331. if (p_hat_y < 0) {
  332. hat |= InputDefault::HAT_MASK_UP;
  333. } else {
  334. hat |= InputDefault::HAT_MASK_DOWN;
  335. }
  336. }
  337. jevent.hat = hat;
  338. input_handler->process_joy_event(jevent);
  339. }
  340. // Called on the UI thread
  341. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(JNIEnv *env, jclass clazz, jint p_device, jboolean p_connected, jstring p_name) {
  342. if (step.get() <= 0) {
  343. return;
  344. }
  345. String name = jstring_to_string(p_name, env);
  346. input_handler->joy_connection_changed(p_device, p_connected, name);
  347. }
  348. // Called on the UI thread
  349. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_scancode, jint p_physical_scancode, jint p_unicode, jboolean p_pressed) {
  350. if (step.get() <= 0) {
  351. return;
  352. }
  353. input_handler->process_key_event(p_scancode, p_physical_scancode, p_unicode, p_pressed);
  354. }
  355. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_accelerometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {
  356. accelerometer = Vector3(x, y, z);
  357. }
  358. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gravity(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {
  359. gravity = Vector3(x, y, z);
  360. }
  361. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnetometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {
  362. magnetometer = Vector3(x, y, z);
  363. }
  364. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gyroscope(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {
  365. gyroscope = Vector3(x, y, z);
  366. }
  367. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env, jclass clazz) {
  368. if (step.get() <= 0) {
  369. return;
  370. }
  371. os_android->main_loop_focusin();
  372. }
  373. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv *env, jclass clazz) {
  374. if (step.get() <= 0) {
  375. return;
  376. }
  377. os_android->main_loop_focusout();
  378. }
  379. JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getGlobal(JNIEnv *env, jclass clazz, jstring path) {
  380. String js = jstring_to_string(path, env);
  381. return env->NewStringUTF(ProjectSettings::get_singleton()->get(js).operator String().utf8().get_data());
  382. }
  383. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_callobject(JNIEnv *env, jclass clazz, jlong ID, jstring method, jobjectArray params) {
  384. Object *obj = ObjectDB::get_instance(ID);
  385. ERR_FAIL_NULL(obj);
  386. int res = env->PushLocalFrame(16);
  387. ERR_FAIL_COND(res != 0);
  388. String str_method = jstring_to_string(method, env);
  389. int count = env->GetArrayLength(params);
  390. Variant *vlist = (Variant *)alloca(sizeof(Variant) * count);
  391. Variant **vptr = (Variant **)alloca(sizeof(Variant *) * count);
  392. for (int i = 0; i < count; i++) {
  393. jobject jobj = env->GetObjectArrayElement(params, i);
  394. Variant v;
  395. if (jobj) {
  396. v = _jobject_to_variant(env, jobj);
  397. }
  398. memnew_placement(&vlist[i], Variant);
  399. vlist[i] = v;
  400. vptr[i] = &vlist[i];
  401. env->DeleteLocalRef(jobj);
  402. }
  403. Variant::CallError err;
  404. obj->call(str_method, (const Variant **)vptr, count, err);
  405. env->PopLocalFrame(nullptr);
  406. }
  407. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_calldeferred(JNIEnv *env, jclass clazz, jlong ID, jstring method, jobjectArray params) {
  408. Object *obj = ObjectDB::get_instance(ID);
  409. ERR_FAIL_NULL(obj);
  410. int res = env->PushLocalFrame(16);
  411. ERR_FAIL_COND(res != 0);
  412. String str_method = jstring_to_string(method, env);
  413. int count = env->GetArrayLength(params);
  414. Variant args[VARIANT_ARG_MAX];
  415. for (int i = 0; i < MIN(count, VARIANT_ARG_MAX); i++) {
  416. jobject jobj = env->GetObjectArrayElement(params, i);
  417. if (jobj) {
  418. args[i] = _jobject_to_variant(env, jobj);
  419. }
  420. env->DeleteLocalRef(jobj);
  421. }
  422. static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8");
  423. obj->call_deferred(str_method, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
  424. env->PopLocalFrame(nullptr);
  425. }
  426. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_requestPermissionResult(JNIEnv *env, jclass clazz, jstring p_permission, jboolean p_result) {
  427. String permission = jstring_to_string(p_permission, env);
  428. if (permission == "android.permission.RECORD_AUDIO" && p_result) {
  429. AudioDriver::get_singleton()->capture_start();
  430. }
  431. if (os_android->get_main_loop()) {
  432. os_android->get_main_loop()->emit_signal("on_request_permissions_result", permission, p_result == JNI_TRUE);
  433. }
  434. }
  435. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererResumed(JNIEnv *env, jclass clazz) {
  436. if (step.get() <= 0) {
  437. return;
  438. }
  439. // We force redraw to ensure we render at least once when resuming the app.
  440. Main::force_redraw();
  441. if (os_android->get_main_loop()) {
  442. os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APP_RESUMED);
  443. }
  444. }
  445. JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererPaused(JNIEnv *env, jclass clazz) {
  446. if (step.get() <= 0) {
  447. return;
  448. }
  449. if (os_android->get_main_loop()) {
  450. os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APP_PAUSED);
  451. }
  452. }
  453. }