java_godot_wrapper.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. /**************************************************************************/
  2. /* java_godot_wrapper.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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_wrapper.h"
  31. // JNIEnv is only valid within the thread it belongs to, in a multi threading environment
  32. // we can't cache it.
  33. // For Godot we call most access methods from our thread and we thus get a valid JNIEnv
  34. // from get_jni_env(). For one or two we expect to pass the environment
  35. // TODO we could probably create a base class for this...
  36. GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_activity, jobject p_godot_instance) {
  37. godot_instance = p_env->NewGlobalRef(p_godot_instance);
  38. activity = p_env->NewGlobalRef(p_activity);
  39. // get info about our Godot class so we can get pointers and stuff...
  40. godot_class = p_env->FindClass("org/godotengine/godot/Godot");
  41. if (godot_class) {
  42. godot_class = (jclass)p_env->NewGlobalRef(godot_class);
  43. } else {
  44. // this is a pretty serious fail.. bail... pointers will stay 0
  45. return;
  46. }
  47. activity_class = p_env->FindClass("android/app/Activity");
  48. if (activity_class) {
  49. activity_class = (jclass)p_env->NewGlobalRef(activity_class);
  50. } else {
  51. // this is a pretty serious fail.. bail... pointers will stay 0
  52. return;
  53. }
  54. // get some Godot method pointers...
  55. _restart = p_env->GetMethodID(godot_class, "restart", "()V");
  56. _finish = p_env->GetMethodID(godot_class, "forceQuit", "(I)Z");
  57. _set_keep_screen_on = p_env->GetMethodID(godot_class, "setKeepScreenOn", "(Z)V");
  58. _alert = p_env->GetMethodID(godot_class, "alert", "(Ljava/lang/String;Ljava/lang/String;)V");
  59. _is_dark_mode_supported = p_env->GetMethodID(godot_class, "isDarkModeSupported", "()Z");
  60. _is_dark_mode = p_env->GetMethodID(godot_class, "isDarkMode", "()Z");
  61. _get_accent_color = p_env->GetMethodID(godot_class, "getAccentColor", "()I");
  62. _get_clipboard = p_env->GetMethodID(godot_class, "getClipboard", "()Ljava/lang/String;");
  63. _set_clipboard = p_env->GetMethodID(godot_class, "setClipboard", "(Ljava/lang/String;)V");
  64. _has_clipboard = p_env->GetMethodID(godot_class, "hasClipboard", "()Z");
  65. _show_input_dialog = p_env->GetMethodID(godot_class, "showInputDialog", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
  66. _show_file_picker = p_env->GetMethodID(godot_class, "showFilePicker", "(Ljava/lang/String;Ljava/lang/String;I[Ljava/lang/String;)V");
  67. _request_permission = p_env->GetMethodID(godot_class, "requestPermission", "(Ljava/lang/String;)Z");
  68. _request_permissions = p_env->GetMethodID(godot_class, "requestPermissions", "()Z");
  69. _get_granted_permissions = p_env->GetMethodID(godot_class, "getGrantedPermissions", "()[Ljava/lang/String;");
  70. _get_ca_certificates = p_env->GetMethodID(godot_class, "getCACertificates", "()Ljava/lang/String;");
  71. _init_input_devices = p_env->GetMethodID(godot_class, "initInputDevices", "()V");
  72. _vibrate = p_env->GetMethodID(godot_class, "vibrate", "(II)V");
  73. _get_input_fallback_mapping = p_env->GetMethodID(godot_class, "getInputFallbackMapping", "()Ljava/lang/String;");
  74. _on_godot_setup_completed = p_env->GetMethodID(godot_class, "onGodotSetupCompleted", "()V");
  75. _on_godot_main_loop_started = p_env->GetMethodID(godot_class, "onGodotMainLoopStarted", "()V");
  76. _on_godot_terminating = p_env->GetMethodID(godot_class, "onGodotTerminating", "()V");
  77. _create_new_godot_instance = p_env->GetMethodID(godot_class, "createNewGodotInstance", "([Ljava/lang/String;)I");
  78. _get_render_view = p_env->GetMethodID(godot_class, "getRenderView", "()Lorg/godotengine/godot/GodotRenderView;");
  79. _begin_benchmark_measure = p_env->GetMethodID(godot_class, "nativeBeginBenchmarkMeasure", "(Ljava/lang/String;Ljava/lang/String;)V");
  80. _end_benchmark_measure = p_env->GetMethodID(godot_class, "nativeEndBenchmarkMeasure", "(Ljava/lang/String;Ljava/lang/String;)V");
  81. _dump_benchmark = p_env->GetMethodID(godot_class, "nativeDumpBenchmark", "(Ljava/lang/String;)V");
  82. _get_gdextension_list_config_file = p_env->GetMethodID(godot_class, "getGDExtensionConfigFiles", "()[Ljava/lang/String;");
  83. _has_feature = p_env->GetMethodID(godot_class, "hasFeature", "(Ljava/lang/String;)Z");
  84. _sign_apk = p_env->GetMethodID(godot_class, "nativeSignApk", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I");
  85. _verify_apk = p_env->GetMethodID(godot_class, "nativeVerifyApk", "(Ljava/lang/String;)I");
  86. _enable_immersive_mode = p_env->GetMethodID(godot_class, "nativeEnableImmersiveMode", "(Z)V");
  87. _is_in_immersive_mode = p_env->GetMethodID(godot_class, "isInImmersiveMode", "()Z");
  88. }
  89. GodotJavaWrapper::~GodotJavaWrapper() {
  90. if (godot_view) {
  91. delete godot_view;
  92. }
  93. JNIEnv *env = get_jni_env();
  94. ERR_FAIL_NULL(env);
  95. env->DeleteGlobalRef(godot_instance);
  96. env->DeleteGlobalRef(godot_class);
  97. env->DeleteGlobalRef(activity);
  98. env->DeleteGlobalRef(activity_class);
  99. }
  100. jobject GodotJavaWrapper::get_activity() {
  101. return activity;
  102. }
  103. GodotJavaViewWrapper *GodotJavaWrapper::get_godot_view() {
  104. if (godot_view != nullptr) {
  105. return godot_view;
  106. }
  107. if (_get_render_view) {
  108. JNIEnv *env = get_jni_env();
  109. ERR_FAIL_NULL_V(env, nullptr);
  110. jobject godot_render_view = env->CallObjectMethod(godot_instance, _get_render_view);
  111. if (!env->IsSameObject(godot_render_view, nullptr)) {
  112. godot_view = new GodotJavaViewWrapper(godot_render_view);
  113. }
  114. }
  115. return godot_view;
  116. }
  117. void GodotJavaWrapper::on_godot_setup_completed(JNIEnv *p_env) {
  118. if (_on_godot_setup_completed) {
  119. if (p_env == nullptr) {
  120. p_env = get_jni_env();
  121. }
  122. p_env->CallVoidMethod(godot_instance, _on_godot_setup_completed);
  123. }
  124. }
  125. void GodotJavaWrapper::on_godot_main_loop_started(JNIEnv *p_env) {
  126. if (_on_godot_main_loop_started) {
  127. if (p_env == nullptr) {
  128. p_env = get_jni_env();
  129. }
  130. ERR_FAIL_NULL(p_env);
  131. p_env->CallVoidMethod(godot_instance, _on_godot_main_loop_started);
  132. }
  133. }
  134. void GodotJavaWrapper::on_godot_terminating(JNIEnv *p_env) {
  135. if (_on_godot_terminating) {
  136. if (p_env == nullptr) {
  137. p_env = get_jni_env();
  138. }
  139. ERR_FAIL_NULL(p_env);
  140. p_env->CallVoidMethod(godot_instance, _on_godot_terminating);
  141. }
  142. }
  143. void GodotJavaWrapper::restart(JNIEnv *p_env) {
  144. if (_restart) {
  145. if (p_env == nullptr) {
  146. p_env = get_jni_env();
  147. }
  148. ERR_FAIL_NULL(p_env);
  149. p_env->CallVoidMethod(godot_instance, _restart);
  150. }
  151. }
  152. bool GodotJavaWrapper::force_quit(JNIEnv *p_env, int p_instance_id) {
  153. if (_finish) {
  154. if (p_env == nullptr) {
  155. p_env = get_jni_env();
  156. }
  157. ERR_FAIL_NULL_V(p_env, false);
  158. return p_env->CallBooleanMethod(godot_instance, _finish, p_instance_id);
  159. }
  160. return false;
  161. }
  162. void GodotJavaWrapper::set_keep_screen_on(bool p_enabled) {
  163. if (_set_keep_screen_on) {
  164. JNIEnv *env = get_jni_env();
  165. ERR_FAIL_NULL(env);
  166. env->CallVoidMethod(godot_instance, _set_keep_screen_on, p_enabled);
  167. }
  168. }
  169. void GodotJavaWrapper::alert(const String &p_message, const String &p_title) {
  170. if (_alert) {
  171. JNIEnv *env = get_jni_env();
  172. ERR_FAIL_NULL(env);
  173. jstring jStrMessage = env->NewStringUTF(p_message.utf8().get_data());
  174. jstring jStrTitle = env->NewStringUTF(p_title.utf8().get_data());
  175. env->CallVoidMethod(godot_instance, _alert, jStrMessage, jStrTitle);
  176. env->DeleteLocalRef(jStrMessage);
  177. env->DeleteLocalRef(jStrTitle);
  178. }
  179. }
  180. bool GodotJavaWrapper::is_dark_mode_supported() {
  181. if (_is_dark_mode_supported) {
  182. JNIEnv *env = get_jni_env();
  183. ERR_FAIL_NULL_V(env, false);
  184. return env->CallBooleanMethod(godot_instance, _is_dark_mode_supported);
  185. } else {
  186. return false;
  187. }
  188. }
  189. bool GodotJavaWrapper::is_dark_mode() {
  190. if (_is_dark_mode) {
  191. JNIEnv *env = get_jni_env();
  192. ERR_FAIL_NULL_V(env, false);
  193. return env->CallBooleanMethod(godot_instance, _is_dark_mode);
  194. } else {
  195. return false;
  196. }
  197. }
  198. Color GodotJavaWrapper::get_accent_color() {
  199. if (_get_accent_color) {
  200. JNIEnv *env = get_jni_env();
  201. ERR_FAIL_NULL_V(env, Color(0, 0, 0, 0));
  202. int accent_color = env->CallIntMethod(godot_instance, _get_accent_color);
  203. // Convert ARGB to RGBA.
  204. int alpha = (accent_color >> 24) & 0xFF;
  205. int red = (accent_color >> 16) & 0xFF;
  206. int green = (accent_color >> 8) & 0xFF;
  207. int blue = accent_color & 0xFF;
  208. return Color(red / 255.0f, green / 255.0f, blue / 255.0f, alpha / 255.0f);
  209. } else {
  210. return Color(0, 0, 0, 0);
  211. }
  212. }
  213. bool GodotJavaWrapper::has_get_clipboard() {
  214. return _get_clipboard != nullptr;
  215. }
  216. String GodotJavaWrapper::get_clipboard() {
  217. String clipboard;
  218. if (_get_clipboard) {
  219. JNIEnv *env = get_jni_env();
  220. ERR_FAIL_NULL_V(env, String());
  221. jstring s = (jstring)env->CallObjectMethod(godot_instance, _get_clipboard);
  222. clipboard = jstring_to_string(s, env);
  223. env->DeleteLocalRef(s);
  224. }
  225. return clipboard;
  226. }
  227. String GodotJavaWrapper::get_input_fallback_mapping() {
  228. String input_fallback_mapping;
  229. if (_get_input_fallback_mapping) {
  230. JNIEnv *env = get_jni_env();
  231. ERR_FAIL_NULL_V(env, String());
  232. jstring fallback_mapping = (jstring)env->CallObjectMethod(godot_instance, _get_input_fallback_mapping);
  233. input_fallback_mapping = jstring_to_string(fallback_mapping, env);
  234. env->DeleteLocalRef(fallback_mapping);
  235. }
  236. return input_fallback_mapping;
  237. }
  238. bool GodotJavaWrapper::has_set_clipboard() {
  239. return _set_clipboard != nullptr;
  240. }
  241. void GodotJavaWrapper::set_clipboard(const String &p_text) {
  242. if (_set_clipboard) {
  243. JNIEnv *env = get_jni_env();
  244. ERR_FAIL_NULL(env);
  245. jstring jStr = env->NewStringUTF(p_text.utf8().get_data());
  246. env->CallVoidMethod(godot_instance, _set_clipboard, jStr);
  247. env->DeleteLocalRef(jStr);
  248. }
  249. }
  250. bool GodotJavaWrapper::has_has_clipboard() {
  251. return _has_clipboard != nullptr;
  252. }
  253. bool GodotJavaWrapper::has_clipboard() {
  254. if (_has_clipboard) {
  255. JNIEnv *env = get_jni_env();
  256. ERR_FAIL_NULL_V(env, false);
  257. return env->CallBooleanMethod(godot_instance, _has_clipboard);
  258. } else {
  259. return false;
  260. }
  261. }
  262. Error GodotJavaWrapper::show_input_dialog(const String &p_title, const String &p_message, const String &p_existing_text) {
  263. if (_show_input_dialog) {
  264. JNIEnv *env = get_jni_env();
  265. ERR_FAIL_NULL_V(env, ERR_UNCONFIGURED);
  266. jstring jStrTitle = env->NewStringUTF(p_title.utf8().get_data());
  267. jstring jStrMessage = env->NewStringUTF(p_message.utf8().get_data());
  268. jstring jStrExistingText = env->NewStringUTF(p_existing_text.utf8().get_data());
  269. env->CallVoidMethod(godot_instance, _show_input_dialog, jStrTitle, jStrMessage, jStrExistingText);
  270. env->DeleteLocalRef(jStrTitle);
  271. env->DeleteLocalRef(jStrMessage);
  272. env->DeleteLocalRef(jStrExistingText);
  273. return OK;
  274. } else {
  275. return ERR_UNCONFIGURED;
  276. }
  277. }
  278. Error GodotJavaWrapper::show_file_picker(const String &p_current_directory, const String &p_filename, int p_mode, const Vector<String> &p_filters) {
  279. if (_show_file_picker) {
  280. JNIEnv *env = get_jni_env();
  281. ERR_FAIL_NULL_V(env, ERR_UNCONFIGURED);
  282. jstring j_current_directory = env->NewStringUTF(p_current_directory.utf8().get_data());
  283. jstring j_filename = env->NewStringUTF(p_filename.utf8().get_data());
  284. jint j_mode = p_mode;
  285. jobjectArray j_filters = env->NewObjectArray(p_filters.size(), env->FindClass("java/lang/String"), nullptr);
  286. for (int i = 0; i < p_filters.size(); ++i) {
  287. jstring j_filter = env->NewStringUTF(p_filters[i].utf8().get_data());
  288. env->SetObjectArrayElement(j_filters, i, j_filter);
  289. env->DeleteLocalRef(j_filter);
  290. }
  291. env->CallVoidMethod(godot_instance, _show_file_picker, j_current_directory, j_filename, j_mode, j_filters);
  292. env->DeleteLocalRef(j_current_directory);
  293. env->DeleteLocalRef(j_filename);
  294. env->DeleteLocalRef(j_filters);
  295. return OK;
  296. } else {
  297. return ERR_UNCONFIGURED;
  298. }
  299. }
  300. bool GodotJavaWrapper::request_permission(const String &p_name) {
  301. if (_request_permission) {
  302. JNIEnv *env = get_jni_env();
  303. ERR_FAIL_NULL_V(env, false);
  304. jstring jStrName = env->NewStringUTF(p_name.utf8().get_data());
  305. bool result = env->CallBooleanMethod(godot_instance, _request_permission, jStrName);
  306. env->DeleteLocalRef(jStrName);
  307. return result;
  308. } else {
  309. return false;
  310. }
  311. }
  312. bool GodotJavaWrapper::request_permissions() {
  313. if (_request_permissions) {
  314. JNIEnv *env = get_jni_env();
  315. ERR_FAIL_NULL_V(env, false);
  316. return env->CallBooleanMethod(godot_instance, _request_permissions);
  317. } else {
  318. return false;
  319. }
  320. }
  321. Vector<String> GodotJavaWrapper::get_granted_permissions() const {
  322. Vector<String> permissions_list;
  323. if (_get_granted_permissions) {
  324. JNIEnv *env = get_jni_env();
  325. ERR_FAIL_NULL_V(env, permissions_list);
  326. jobject permissions_object = env->CallObjectMethod(godot_instance, _get_granted_permissions);
  327. jobjectArray *arr = reinterpret_cast<jobjectArray *>(&permissions_object);
  328. jsize len = env->GetArrayLength(*arr);
  329. for (int i = 0; i < len; i++) {
  330. jstring jstr = (jstring)env->GetObjectArrayElement(*arr, i);
  331. String str = jstring_to_string(jstr, env);
  332. permissions_list.push_back(str);
  333. env->DeleteLocalRef(jstr);
  334. }
  335. }
  336. return permissions_list;
  337. }
  338. Vector<String> GodotJavaWrapper::get_gdextension_list_config_file() const {
  339. Vector<String> config_file_list;
  340. if (_get_gdextension_list_config_file) {
  341. JNIEnv *env = get_jni_env();
  342. ERR_FAIL_NULL_V(env, config_file_list);
  343. jobject config_file_list_object = env->CallObjectMethod(godot_instance, _get_gdextension_list_config_file);
  344. jobjectArray *arr = reinterpret_cast<jobjectArray *>(&config_file_list_object);
  345. jsize len = env->GetArrayLength(*arr);
  346. for (int i = 0; i < len; i++) {
  347. jstring j_config_file = (jstring)env->GetObjectArrayElement(*arr, i);
  348. String config_file = jstring_to_string(j_config_file, env);
  349. config_file_list.push_back(config_file);
  350. env->DeleteLocalRef(j_config_file);
  351. }
  352. }
  353. return config_file_list;
  354. }
  355. String GodotJavaWrapper::get_ca_certificates() const {
  356. String ca_certificates;
  357. if (_get_ca_certificates) {
  358. JNIEnv *env = get_jni_env();
  359. ERR_FAIL_NULL_V(env, String());
  360. jstring s = (jstring)env->CallObjectMethod(godot_instance, _get_ca_certificates);
  361. ca_certificates = jstring_to_string(s, env);
  362. env->DeleteLocalRef(s);
  363. }
  364. return ca_certificates;
  365. }
  366. void GodotJavaWrapper::init_input_devices() {
  367. if (_init_input_devices) {
  368. JNIEnv *env = get_jni_env();
  369. ERR_FAIL_NULL(env);
  370. env->CallVoidMethod(godot_instance, _init_input_devices);
  371. }
  372. }
  373. void GodotJavaWrapper::vibrate(int p_duration_ms, float p_amplitude) {
  374. if (_vibrate) {
  375. JNIEnv *env = get_jni_env();
  376. ERR_FAIL_NULL(env);
  377. int j_amplitude = -1.0;
  378. if (p_amplitude != -1.0) {
  379. j_amplitude = CLAMP(int(p_amplitude * 255), 1, 255);
  380. }
  381. env->CallVoidMethod(godot_instance, _vibrate, p_duration_ms, j_amplitude);
  382. }
  383. }
  384. int GodotJavaWrapper::create_new_godot_instance(const List<String> &args) {
  385. if (_create_new_godot_instance) {
  386. JNIEnv *env = get_jni_env();
  387. ERR_FAIL_NULL_V(env, 0);
  388. jobjectArray jargs = env->NewObjectArray(args.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));
  389. int i = 0;
  390. for (List<String>::ConstIterator itr = args.begin(); itr != args.end(); ++itr, ++i) {
  391. jstring j_arg = env->NewStringUTF(itr->utf8().get_data());
  392. env->SetObjectArrayElement(jargs, i, j_arg);
  393. env->DeleteLocalRef(j_arg);
  394. }
  395. return env->CallIntMethod(godot_instance, _create_new_godot_instance, jargs);
  396. } else {
  397. return 0;
  398. }
  399. }
  400. void GodotJavaWrapper::begin_benchmark_measure(const String &p_context, const String &p_label) {
  401. if (_begin_benchmark_measure) {
  402. JNIEnv *env = get_jni_env();
  403. ERR_FAIL_NULL(env);
  404. jstring j_context = env->NewStringUTF(p_context.utf8().get_data());
  405. jstring j_label = env->NewStringUTF(p_label.utf8().get_data());
  406. env->CallVoidMethod(godot_instance, _begin_benchmark_measure, j_context, j_label);
  407. env->DeleteLocalRef(j_context);
  408. env->DeleteLocalRef(j_label);
  409. }
  410. }
  411. void GodotJavaWrapper::end_benchmark_measure(const String &p_context, const String &p_label) {
  412. if (_end_benchmark_measure) {
  413. JNIEnv *env = get_jni_env();
  414. ERR_FAIL_NULL(env);
  415. jstring j_context = env->NewStringUTF(p_context.utf8().get_data());
  416. jstring j_label = env->NewStringUTF(p_label.utf8().get_data());
  417. env->CallVoidMethod(godot_instance, _end_benchmark_measure, j_context, j_label);
  418. env->DeleteLocalRef(j_context);
  419. env->DeleteLocalRef(j_label);
  420. }
  421. }
  422. void GodotJavaWrapper::dump_benchmark(const String &benchmark_file) {
  423. if (_dump_benchmark) {
  424. JNIEnv *env = get_jni_env();
  425. ERR_FAIL_NULL(env);
  426. jstring j_benchmark_file = env->NewStringUTF(benchmark_file.utf8().get_data());
  427. env->CallVoidMethod(godot_instance, _dump_benchmark, j_benchmark_file);
  428. env->DeleteLocalRef(j_benchmark_file);
  429. }
  430. }
  431. bool GodotJavaWrapper::has_feature(const String &p_feature) const {
  432. if (_has_feature) {
  433. JNIEnv *env = get_jni_env();
  434. ERR_FAIL_NULL_V(env, false);
  435. jstring j_feature = env->NewStringUTF(p_feature.utf8().get_data());
  436. bool result = env->CallBooleanMethod(godot_instance, _has_feature, j_feature);
  437. env->DeleteLocalRef(j_feature);
  438. return result;
  439. } else {
  440. return false;
  441. }
  442. }
  443. Error GodotJavaWrapper::sign_apk(const String &p_input_path, const String &p_output_path, const String &p_keystore_path, const String &p_keystore_user, const String &p_keystore_password) {
  444. if (_sign_apk) {
  445. JNIEnv *env = get_jni_env();
  446. ERR_FAIL_NULL_V(env, ERR_UNCONFIGURED);
  447. jstring j_input_path = env->NewStringUTF(p_input_path.utf8().get_data());
  448. jstring j_output_path = env->NewStringUTF(p_output_path.utf8().get_data());
  449. jstring j_keystore_path = env->NewStringUTF(p_keystore_path.utf8().get_data());
  450. jstring j_keystore_user = env->NewStringUTF(p_keystore_user.utf8().get_data());
  451. jstring j_keystore_password = env->NewStringUTF(p_keystore_password.utf8().get_data());
  452. int result = env->CallIntMethod(godot_instance, _sign_apk, j_input_path, j_output_path, j_keystore_path, j_keystore_user, j_keystore_password);
  453. env->DeleteLocalRef(j_input_path);
  454. env->DeleteLocalRef(j_output_path);
  455. env->DeleteLocalRef(j_keystore_path);
  456. env->DeleteLocalRef(j_keystore_user);
  457. env->DeleteLocalRef(j_keystore_password);
  458. return static_cast<Error>(result);
  459. } else {
  460. return ERR_UNCONFIGURED;
  461. }
  462. }
  463. Error GodotJavaWrapper::verify_apk(const String &p_apk_path) {
  464. if (_verify_apk) {
  465. JNIEnv *env = get_jni_env();
  466. ERR_FAIL_NULL_V(env, ERR_UNCONFIGURED);
  467. jstring j_apk_path = env->NewStringUTF(p_apk_path.utf8().get_data());
  468. int result = env->CallIntMethod(godot_instance, _verify_apk, j_apk_path);
  469. env->DeleteLocalRef(j_apk_path);
  470. return static_cast<Error>(result);
  471. } else {
  472. return ERR_UNCONFIGURED;
  473. }
  474. }
  475. void GodotJavaWrapper::enable_immersive_mode(bool p_enabled) {
  476. if (_enable_immersive_mode) {
  477. JNIEnv *env = get_jni_env();
  478. ERR_FAIL_NULL(env);
  479. env->CallVoidMethod(godot_instance, _enable_immersive_mode, p_enabled);
  480. }
  481. }
  482. bool GodotJavaWrapper::is_in_immersive_mode() {
  483. if (_is_in_immersive_mode) {
  484. JNIEnv *env = get_jni_env();
  485. ERR_FAIL_NULL_V(env, false);
  486. return env->CallBooleanMethod(godot_instance, _is_in_immersive_mode);
  487. } else {
  488. return false;
  489. }
  490. }