| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "audio_driver_opensl.h" |
| 34 |
|
| 35 |
#include "core/os/main_loop.h" |
| 36 |
#include "drivers/unix/os_unix.h" |
| 37 |
#include "servers/audio/audio_server.h" |
| 38 |
|
| 39 |
class GodotJavaWrapper; |
| 40 |
class GodotIOJavaWrapper; |
| 41 |
|
| 42 |
struct ANativeWindow; |
| 43 |
|
| 44 |
class OS_Android : public OS_Unix { |
| 45 |
private: |
| 46 |
Size2i display_size; |
| 47 |
|
| 48 |
bool use_apk_expansion; |
| 49 |
|
| 50 |
#if defined(GLES3_ENABLED) |
| 51 |
const char *gl_extensions; |
| 52 |
#endif |
| 53 |
|
| 54 |
#if defined(VULKAN_ENABLED) |
| 55 |
ANativeWindow *native_window = nullptr; |
| 56 |
#endif |
| 57 |
|
| 58 |
mutable String data_dir_cache; |
| 59 |
mutable String cache_dir_cache; |
| 60 |
mutable String temp_dir_cache; |
| 61 |
mutable String remote_fs_dir; |
| 62 |
|
| 63 |
AudioDriverOpenSL audio_driver_android; |
| 64 |
|
| 65 |
MainLoop *main_loop = nullptr; |
| 66 |
|
| 67 |
struct FontInfo { |
| 68 |
String font_name; |
| 69 |
HashSet<String> lang; |
| 70 |
HashSet<String> script; |
| 71 |
int weight = 400; |
| 72 |
int stretch = 100; |
| 73 |
bool italic = false; |
| 74 |
int priority = 0; |
| 75 |
String filename; |
| 76 |
}; |
| 77 |
|
| 78 |
mutable HashMap<String, String> font_aliases; |
| 79 |
mutable List<FontInfo> fonts; |
| 80 |
mutable HashSet<String> font_names; |
| 81 |
mutable bool font_config_loaded = false; |
| 82 |
|
| 83 |
GodotJavaWrapper *godot_java = nullptr; |
| 84 |
GodotIOJavaWrapper *godot_io_java = nullptr; |
| 85 |
|
| 86 |
void _load_system_font_config() const; |
| 87 |
String get_system_property(const char *key) const; |
| 88 |
|
| 89 |
public: |
| 90 |
static const char *ANDROID_EXEC_PATH; |
| 91 |
static const int DEFAULT_WINDOW_WIDTH = 800; |
| 92 |
static const int DEFAULT_WINDOW_HEIGHT = 600; |
| 93 |
|
| 94 |
#ifdef TOOLS_ENABLED |
| 95 |
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); |
| 96 |
Error verify_apk(const String &p_apk_path); |
| 97 |
#endif |
| 98 |
|
| 99 |
virtual void initialize_core() override; |
| 100 |
virtual void initialize() override; |
| 101 |
|
| 102 |
virtual void initialize_joypads() override; |
| 103 |
|
| 104 |
virtual void set_main_loop(MainLoop *p_main_loop) override; |
| 105 |
virtual void delete_main_loop() override; |
| 106 |
|
| 107 |
virtual void finalize() override; |
| 108 |
|
| 109 |
typedef int64_t ProcessID; |
| 110 |
|
| 111 |
static OS_Android *get_singleton(); |
| 112 |
GodotJavaWrapper *get_godot_java(); |
| 113 |
GodotIOJavaWrapper *get_godot_io_java(); |
| 114 |
|
| 115 |
virtual bool request_permission(const String &p_name) override; |
| 116 |
virtual bool request_permissions() override; |
| 117 |
virtual Vector<String> get_granted_permissions() const override; |
| 118 |
|
| 119 |
virtual void alert(const String &p_alert, const String &p_title) override; |
| 120 |
|
| 121 |
virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, GDExtensionData *p_data = nullptr) override; |
| 122 |
|
| 123 |
virtual String get_name() const override; |
| 124 |
virtual String get_distribution_name() const override; |
| 125 |
virtual String get_version() const override; |
| 126 |
virtual String get_version_alias() const override; |
| 127 |
|
| 128 |
virtual MainLoop *get_main_loop() const override; |
| 129 |
|
| 130 |
void main_loop_begin(); |
| 131 |
bool main_loop_iterate(bool *r_should_swap_buffers = nullptr); |
| 132 |
void main_loop_end(); |
| 133 |
void main_loop_focusout(); |
| 134 |
void main_loop_focusin(); |
| 135 |
|
| 136 |
void set_display_size(const Size2i &p_size); |
| 137 |
Size2i get_display_size() const; |
| 138 |
|
| 139 |
void set_opengl_extensions(const char *p_gl_extensions); |
| 140 |
|
| 141 |
void set_native_window(ANativeWindow *p_native_window); |
| 142 |
ANativeWindow *get_native_window() const; |
| 143 |
|
| 144 |
virtual Error shell_open(const String &p_uri) override; |
| 145 |
|
| 146 |
virtual Vector<String> get_system_fonts() const override; |
| 147 |
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; |
| 148 |
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; |
| 149 |
virtual String get_executable_path() const override; |
| 150 |
virtual String get_user_data_dir(const String &p_user_dir) const override; |
| 151 |
virtual String get_data_path() const override; |
| 152 |
virtual String get_cache_path() const override; |
| 153 |
virtual String get_temp_path() const override; |
| 154 |
virtual String get_resource_dir() const override; |
| 155 |
virtual String get_locale() const override; |
| 156 |
virtual String get_model_name() const override; |
| 157 |
|
| 158 |
virtual String get_unique_id() const override; |
| 159 |
|
| 160 |
virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const override; |
| 161 |
|
| 162 |
virtual Error move_to_trash(const String &p_path) override; |
| 163 |
|
| 164 |
void vibrate_handheld(int p_duration_ms, float p_amplitude = -1.0) override; |
| 165 |
|
| 166 |
virtual String get_config_path() const override; |
| 167 |
|
| 168 |
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; |
| 169 |
virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override; |
| 170 |
virtual Error create_instance(const List<String> &p_arguments, ProcessID *r_child_id = nullptr) override; |
| 171 |
virtual Error kill(const ProcessID &p_pid) override; |
| 172 |
virtual String get_system_ca_certificates() override; |
| 173 |
|
| 174 |
virtual Error setup_remote_filesystem(const String &p_server_host, int p_port, const String &p_password, String &r_project_path) override; |
| 175 |
|
| 176 |
virtual void benchmark_begin_measure(const String &p_context, const String &p_what) override; |
| 177 |
virtual void benchmark_end_measure(const String &p_context, const String &p_what) override; |
| 178 |
virtual void benchmark_dump() override; |
| 179 |
|
| 180 |
virtual void load_platform_gdextensions() const override; |
| 181 |
|
| 182 |
virtual bool _check_internal_feature_support(const String &p_feature) override; |
| 183 |
OS_Android(GodotJavaWrapper *p_godot_java, GodotIOJavaWrapper *p_godot_io_java, bool p_use_apk_expansion); |
| 184 |
~OS_Android(); |
| 185 |
|
| 186 |
private: |
| 187 |
|
| 188 |
String get_dynamic_libraries_path() const; |
| 189 |
|
| 190 |
bool copy_dynamic_library(const String &p_library_path, const String &p_target_dir, String *r_copy_path = nullptr); |
| 191 |
|
| 192 |
#ifdef TOOLS_ENABLED |
| 193 |
static void _on_main_screen_changed(const String &p_screen_name); |
| 194 |
#endif |
| 195 |
}; |