java_godot_wrapper.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**************************************************************************/
  2. /* java_godot_wrapper.h */
  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. #ifndef JAVA_GODOT_WRAPPER_H
  31. #define JAVA_GODOT_WRAPPER_H
  32. #include "java_godot_view_wrapper.h"
  33. #include "string_android.h"
  34. #include "core/templates/list.h"
  35. #include <android/log.h>
  36. #include <jni.h>
  37. // Class that makes functions in java/src/org/godotengine/godot/Godot.kt callable from C++
  38. class GodotJavaWrapper {
  39. private:
  40. jobject godot_instance;
  41. jobject activity;
  42. jclass godot_class;
  43. jclass activity_class;
  44. GodotJavaViewWrapper *godot_view = nullptr;
  45. jmethodID _restart = nullptr;
  46. jmethodID _finish = nullptr;
  47. jmethodID _set_keep_screen_on = nullptr;
  48. jmethodID _alert = nullptr;
  49. jmethodID _is_dark_mode_supported = nullptr;
  50. jmethodID _is_dark_mode = nullptr;
  51. jmethodID _get_clipboard = nullptr;
  52. jmethodID _set_clipboard = nullptr;
  53. jmethodID _has_clipboard = nullptr;
  54. jmethodID _show_input_dialog = nullptr;
  55. jmethodID _request_permission = nullptr;
  56. jmethodID _request_permissions = nullptr;
  57. jmethodID _get_granted_permissions = nullptr;
  58. jmethodID _get_gdextension_list_config_file = nullptr;
  59. jmethodID _get_ca_certificates = nullptr;
  60. jmethodID _init_input_devices = nullptr;
  61. jmethodID _vibrate = nullptr;
  62. jmethodID _get_input_fallback_mapping = nullptr;
  63. jmethodID _on_godot_setup_completed = nullptr;
  64. jmethodID _on_godot_main_loop_started = nullptr;
  65. jmethodID _on_godot_terminating = nullptr;
  66. jmethodID _create_new_godot_instance = nullptr;
  67. jmethodID _get_render_view = nullptr;
  68. jmethodID _begin_benchmark_measure = nullptr;
  69. jmethodID _end_benchmark_measure = nullptr;
  70. jmethodID _dump_benchmark = nullptr;
  71. jmethodID _has_feature = nullptr;
  72. jmethodID _sign_apk = nullptr;
  73. jmethodID _verify_apk = nullptr;
  74. jmethodID _enable_immersive_mode = nullptr;
  75. jmethodID _is_in_immersive_mode = nullptr;
  76. public:
  77. GodotJavaWrapper(JNIEnv *p_env, jobject p_activity, jobject p_godot_instance);
  78. ~GodotJavaWrapper();
  79. jobject get_activity();
  80. GodotJavaViewWrapper *get_godot_view();
  81. void on_godot_setup_completed(JNIEnv *p_env = nullptr);
  82. void on_godot_main_loop_started(JNIEnv *p_env = nullptr);
  83. void on_godot_terminating(JNIEnv *p_env = nullptr);
  84. void restart(JNIEnv *p_env = nullptr);
  85. bool force_quit(JNIEnv *p_env = nullptr, int p_instance_id = 0);
  86. void set_keep_screen_on(bool p_enabled);
  87. void alert(const String &p_message, const String &p_title);
  88. bool is_dark_mode_supported();
  89. bool is_dark_mode();
  90. bool has_get_clipboard();
  91. String get_clipboard();
  92. bool has_set_clipboard();
  93. void set_clipboard(const String &p_text);
  94. bool has_has_clipboard();
  95. bool has_clipboard();
  96. Error show_input_dialog(const String &p_title, const String &p_message, const String &p_existing_text);
  97. bool request_permission(const String &p_name);
  98. bool request_permissions();
  99. Vector<String> get_granted_permissions() const;
  100. String get_ca_certificates() const;
  101. void init_input_devices();
  102. void vibrate(int p_duration_ms, float p_amplitude = -1.0);
  103. String get_input_fallback_mapping();
  104. int create_new_godot_instance(const List<String> &args);
  105. void begin_benchmark_measure(const String &p_context, const String &p_label);
  106. void end_benchmark_measure(const String &p_context, const String &p_label);
  107. void dump_benchmark(const String &benchmark_file);
  108. // Return the list of gdextensions config file.
  109. Vector<String> get_gdextension_list_config_file() const;
  110. // Return true if the given feature is supported.
  111. bool has_feature(const String &p_feature) const;
  112. // Sign and verify apks
  113. Error 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);
  114. Error verify_apk(const String &p_apk_path);
  115. void enable_immersive_mode(bool p_enabled);
  116. bool is_in_immersive_mode();
  117. };
  118. #endif // JAVA_GODOT_WRAPPER_H