os_android.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /**************************************************************************/
  2. /* os_android.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 OS_ANDROID_H
  31. #define OS_ANDROID_H
  32. #include "audio_driver_opensl.h"
  33. #include "core/os/main_loop.h"
  34. #include "drivers/unix/os_unix.h"
  35. #include "servers/audio_server.h"
  36. class GodotJavaWrapper;
  37. class GodotIOJavaWrapper;
  38. struct ANativeWindow;
  39. class OS_Android : public OS_Unix {
  40. private:
  41. Size2i display_size;
  42. bool use_apk_expansion;
  43. #if defined(GLES3_ENABLED)
  44. const char *gl_extensions;
  45. #endif
  46. #if defined(VULKAN_ENABLED)
  47. ANativeWindow *native_window = nullptr;
  48. #endif
  49. mutable String data_dir_cache;
  50. mutable String cache_dir_cache;
  51. mutable String temp_dir_cache;
  52. mutable String remote_fs_dir;
  53. AudioDriverOpenSL audio_driver_android;
  54. MainLoop *main_loop = nullptr;
  55. struct FontInfo {
  56. String font_name;
  57. HashSet<String> lang;
  58. HashSet<String> script;
  59. int weight = 400;
  60. int stretch = 100;
  61. bool italic = false;
  62. int priority = 0;
  63. String filename;
  64. };
  65. mutable HashMap<String, String> font_aliases;
  66. mutable List<FontInfo> fonts;
  67. mutable HashSet<String> font_names;
  68. mutable bool font_config_loaded = false;
  69. GodotJavaWrapper *godot_java = nullptr;
  70. GodotIOJavaWrapper *godot_io_java = nullptr;
  71. void _load_system_font_config() const;
  72. String get_system_property(const char *key) const;
  73. public:
  74. static const char *ANDROID_EXEC_PATH;
  75. static const int DEFAULT_WINDOW_WIDTH = 800;
  76. static const int DEFAULT_WINDOW_HEIGHT = 600;
  77. #ifdef TOOLS_ENABLED
  78. 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);
  79. Error verify_apk(const String &p_apk_path);
  80. #endif
  81. virtual void initialize_core() override;
  82. virtual void initialize() override;
  83. virtual void initialize_joypads() override;
  84. virtual void set_main_loop(MainLoop *p_main_loop) override;
  85. virtual void delete_main_loop() override;
  86. virtual void finalize() override;
  87. typedef int64_t ProcessID;
  88. static OS_Android *get_singleton();
  89. GodotJavaWrapper *get_godot_java();
  90. GodotIOJavaWrapper *get_godot_io_java();
  91. virtual bool request_permission(const String &p_name) override;
  92. virtual bool request_permissions() override;
  93. virtual Vector<String> get_granted_permissions() const override;
  94. virtual void alert(const String &p_alert, const String &p_title) override;
  95. virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, GDExtensionData *p_data = nullptr) override;
  96. virtual String get_name() const override;
  97. virtual String get_distribution_name() const override;
  98. virtual String get_version() const override;
  99. virtual MainLoop *get_main_loop() const override;
  100. void main_loop_begin();
  101. bool main_loop_iterate(bool *r_should_swap_buffers = nullptr);
  102. void main_loop_end();
  103. void main_loop_focusout();
  104. void main_loop_focusin();
  105. void set_display_size(const Size2i &p_size);
  106. Size2i get_display_size() const;
  107. void set_opengl_extensions(const char *p_gl_extensions);
  108. void set_native_window(ANativeWindow *p_native_window);
  109. ANativeWindow *get_native_window() const;
  110. virtual Error shell_open(const String &p_uri) override;
  111. virtual Vector<String> get_system_fonts() const override;
  112. virtual String get_system_font_path(const String &p_font_name, int p_weight = 400, int p_stretch = 100, bool p_italic = false) const override;
  113. virtual Vector<String> get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale = String(), const String &p_script = String(), int p_weight = 400, int p_stretch = 100, bool p_italic = false) const override;
  114. virtual String get_executable_path() const override;
  115. virtual String get_user_data_dir(const String &p_user_dir) const override;
  116. virtual String get_data_path() const override;
  117. virtual String get_cache_path() const override;
  118. virtual String get_temp_path() const override;
  119. virtual String get_resource_dir() const override;
  120. virtual String get_locale() const override;
  121. virtual String get_model_name() const override;
  122. virtual String get_unique_id() const override;
  123. virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const override;
  124. virtual Error move_to_trash(const String &p_path) override;
  125. void vibrate_handheld(int p_duration_ms, float p_amplitude = -1.0) override;
  126. virtual String get_config_path() const override;
  127. virtual Error execute(const String &p_path, const List<String> &p_arguments, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr, bool p_open_console = false) override;
  128. virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override;
  129. virtual Error create_instance(const List<String> &p_arguments, ProcessID *r_child_id = nullptr) override;
  130. virtual Error kill(const ProcessID &p_pid) override;
  131. virtual String get_system_ca_certificates() override;
  132. virtual Error setup_remote_filesystem(const String &p_server_host, int p_port, const String &p_password, String &r_project_path) override;
  133. virtual void benchmark_begin_measure(const String &p_context, const String &p_what) override;
  134. virtual void benchmark_end_measure(const String &p_context, const String &p_what) override;
  135. virtual void benchmark_dump() override;
  136. virtual void load_platform_gdextensions() const override;
  137. virtual bool _check_internal_feature_support(const String &p_feature) override;
  138. OS_Android(GodotJavaWrapper *p_godot_java, GodotIOJavaWrapper *p_godot_io_java, bool p_use_apk_expansion);
  139. ~OS_Android();
  140. private:
  141. // Location where we relocate external dynamic libraries to make them accessible.
  142. String get_dynamic_libraries_path() const;
  143. // Copy a dynamic library to the given location to make it accessible for loading.
  144. bool copy_dynamic_library(const String &p_library_path, const String &p_target_dir, String *r_copy_path = nullptr);
  145. #ifdef TOOLS_ENABLED
  146. static void _on_main_screen_changed(const String &p_screen_name);
  147. #endif
  148. };
  149. #endif // OS_ANDROID_H