os_android.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. /*************************************************************************/
  2. /* os_android.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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 "os_android.h"
  31. #include "core/io/file_access_buffered_fa.h"
  32. #include "core/project_settings.h"
  33. #include "drivers/gles2/rasterizer_gles2.h"
  34. #include "drivers/gles3/rasterizer_gles3.h"
  35. #include "drivers/unix/dir_access_unix.h"
  36. #include "drivers/unix/file_access_unix.h"
  37. #include "file_access_android.h"
  38. #include "main/main.h"
  39. #include "servers/visual/visual_server_raster.h"
  40. #include "servers/visual/visual_server_wrap_mt.h"
  41. #include "dir_access_jandroid.h"
  42. #include "file_access_jandroid.h"
  43. #include "net_socket_android.h"
  44. #include <dlfcn.h>
  45. #include "java_godot_io_wrapper.h"
  46. #include "java_godot_wrapper.h"
  47. class AndroidLogger : public Logger {
  48. public:
  49. virtual void logv(const char *p_format, va_list p_list, bool p_err) {
  50. __android_log_vprint(p_err ? ANDROID_LOG_ERROR : ANDROID_LOG_INFO, "godot", p_format, p_list);
  51. }
  52. virtual ~AndroidLogger() {}
  53. };
  54. int OS_Android::get_video_driver_count() const {
  55. return 2;
  56. }
  57. const char *OS_Android::get_video_driver_name(int p_driver) const {
  58. switch (p_driver) {
  59. case VIDEO_DRIVER_GLES3:
  60. return "GLES3";
  61. case VIDEO_DRIVER_GLES2:
  62. return "GLES2";
  63. }
  64. ERR_FAIL_V_MSG(NULL, "Invalid video driver index: " + itos(p_driver) + ".");
  65. }
  66. int OS_Android::get_audio_driver_count() const {
  67. return 1;
  68. }
  69. const char *OS_Android::get_audio_driver_name(int p_driver) const {
  70. return "Android";
  71. }
  72. void OS_Android::initialize_core() {
  73. OS_Unix::initialize_core();
  74. if (use_apk_expansion)
  75. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
  76. else {
  77. #ifdef USE_JAVA_FILE_ACCESS
  78. FileAccess::make_default<FileAccessBufferedFA<FileAccessJAndroid> >(FileAccess::ACCESS_RESOURCES);
  79. #else
  80. //FileAccess::make_default<FileAccessBufferedFA<FileAccessAndroid> >(FileAccess::ACCESS_RESOURCES);
  81. FileAccess::make_default<FileAccessAndroid>(FileAccess::ACCESS_RESOURCES);
  82. #endif
  83. }
  84. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA);
  85. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_FILESYSTEM);
  86. //FileAccessBufferedFA<FileAccessUnix>::make_default();
  87. if (use_apk_expansion)
  88. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_RESOURCES);
  89. else
  90. DirAccess::make_default<DirAccessJAndroid>(DirAccess::ACCESS_RESOURCES);
  91. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_USERDATA);
  92. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_FILESYSTEM);
  93. NetSocketAndroid::make_default();
  94. }
  95. void OS_Android::set_opengl_extensions(const char *p_gl_extensions) {
  96. ERR_FAIL_COND(!p_gl_extensions);
  97. gl_extensions = p_gl_extensions;
  98. }
  99. int OS_Android::get_current_video_driver() const {
  100. return video_driver_index;
  101. }
  102. Error OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
  103. bool use_gl3 = godot_java->get_gles_version_code() >= 0x00030000;
  104. use_gl3 = use_gl3 && (GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES3");
  105. bool gl_initialization_error = false;
  106. while (true) {
  107. if (use_gl3) {
  108. if (RasterizerGLES3::is_viable() == OK) {
  109. godot_java->gfx_init(false);
  110. RasterizerGLES3::register_config();
  111. RasterizerGLES3::make_current();
  112. break;
  113. } else {
  114. if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2")) {
  115. p_video_driver = VIDEO_DRIVER_GLES2;
  116. use_gl3 = false;
  117. continue;
  118. } else {
  119. gl_initialization_error = true;
  120. break;
  121. }
  122. }
  123. } else {
  124. if (RasterizerGLES2::is_viable() == OK) {
  125. godot_java->gfx_init(true);
  126. RasterizerGLES2::register_config();
  127. RasterizerGLES2::make_current();
  128. break;
  129. } else {
  130. gl_initialization_error = true;
  131. break;
  132. }
  133. }
  134. }
  135. if (gl_initialization_error) {
  136. OS::get_singleton()->alert("Your device does not support any of the supported OpenGL versions.\n"
  137. "Please try updating your Android version.",
  138. "Unable to initialize Video driver");
  139. return ERR_UNAVAILABLE;
  140. }
  141. video_driver_index = p_video_driver;
  142. visual_server = memnew(VisualServerRaster);
  143. if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
  144. visual_server = memnew(VisualServerWrapMT(visual_server, false));
  145. }
  146. visual_server->init();
  147. AudioDriverManager::initialize(p_audio_driver);
  148. input = memnew(InputDefault);
  149. input->set_fallback_mapping(godot_java->get_input_fallback_mapping());
  150. //power_manager = memnew(PowerAndroid);
  151. return OK;
  152. }
  153. void OS_Android::set_main_loop(MainLoop *p_main_loop) {
  154. main_loop = p_main_loop;
  155. input->set_main_loop(p_main_loop);
  156. }
  157. void OS_Android::delete_main_loop() {
  158. memdelete(main_loop);
  159. }
  160. void OS_Android::finalize() {
  161. memdelete(input);
  162. }
  163. GodotJavaWrapper *OS_Android::get_godot_java() {
  164. return godot_java;
  165. }
  166. GodotIOJavaWrapper *OS_Android::get_godot_io_java() {
  167. return godot_io_java;
  168. }
  169. void OS_Android::alert(const String &p_alert, const String &p_title) {
  170. //print("ALERT: %s\n", p_alert.utf8().get_data());
  171. godot_java->alert(p_alert, p_title);
  172. }
  173. bool OS_Android::request_permission(const String &p_name) {
  174. return godot_java->request_permission(p_name);
  175. }
  176. bool OS_Android::request_permissions() {
  177. return godot_java->request_permissions();
  178. }
  179. Vector<String> OS_Android::get_granted_permissions() const {
  180. return godot_java->get_granted_permissions();
  181. }
  182. Error OS_Android::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
  183. p_library_handle = dlopen(p_path.utf8().get_data(), RTLD_NOW);
  184. ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + p_path + ", error: " + dlerror() + ".");
  185. return OK;
  186. }
  187. void OS_Android::set_mouse_show(bool p_show) {
  188. //android has no mouse...
  189. }
  190. void OS_Android::set_mouse_grab(bool p_grab) {
  191. //it really has no mouse...!
  192. }
  193. bool OS_Android::is_mouse_grab_enabled() const {
  194. //*sigh* technology has evolved so much since i was a kid..
  195. return false;
  196. }
  197. Point2 OS_Android::get_mouse_position() const {
  198. return Point2();
  199. }
  200. int OS_Android::get_mouse_button_state() const {
  201. return 0;
  202. }
  203. void OS_Android::set_window_title(const String &p_title) {
  204. //This queries/updates the currently connected devices/joypads
  205. //Set_window_title is called when initializing the main loop (main.cpp)
  206. //therefore this place is found to be suitable (I found no better).
  207. godot_java->init_input_devices();
  208. }
  209. void OS_Android::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
  210. }
  211. OS::VideoMode OS_Android::get_video_mode(int p_screen) const {
  212. return default_videomode;
  213. }
  214. void OS_Android::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
  215. p_list->push_back(default_videomode);
  216. }
  217. void OS_Android::set_keep_screen_on(bool p_enabled) {
  218. OS::set_keep_screen_on(p_enabled);
  219. godot_java->set_keep_screen_on(p_enabled);
  220. }
  221. Size2 OS_Android::get_window_size() const {
  222. return Vector2(default_videomode.width, default_videomode.height);
  223. }
  224. String OS_Android::get_name() const {
  225. return "Android";
  226. }
  227. MainLoop *OS_Android::get_main_loop() const {
  228. return main_loop;
  229. }
  230. bool OS_Android::can_draw() const {
  231. return true; //always?
  232. }
  233. void OS_Android::main_loop_begin() {
  234. if (main_loop)
  235. main_loop->init();
  236. }
  237. bool OS_Android::main_loop_iterate() {
  238. if (!main_loop)
  239. return false;
  240. return Main::iteration();
  241. }
  242. void OS_Android::main_loop_end() {
  243. if (main_loop)
  244. main_loop->finish();
  245. }
  246. void OS_Android::main_loop_focusout() {
  247. if (main_loop)
  248. main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
  249. audio_driver_android.set_pause(true);
  250. }
  251. void OS_Android::main_loop_focusin() {
  252. if (main_loop)
  253. main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
  254. audio_driver_android.set_pause(false);
  255. }
  256. void OS_Android::process_joy_event(OS_Android::JoypadEvent p_event) {
  257. switch (p_event.type) {
  258. case JOY_EVENT_BUTTON:
  259. input->joy_button(p_event.device, p_event.index, p_event.pressed);
  260. break;
  261. case JOY_EVENT_AXIS:
  262. InputDefault::JoyAxis value;
  263. value.min = -1;
  264. value.value = p_event.value;
  265. input->joy_axis(p_event.device, p_event.index, value);
  266. break;
  267. case JOY_EVENT_HAT:
  268. input->joy_hat(p_event.device, p_event.hat);
  269. break;
  270. default:
  271. return;
  272. }
  273. }
  274. void OS_Android::process_event(Ref<InputEvent> p_event) {
  275. input->parse_input_event(p_event);
  276. }
  277. void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> &p_points) {
  278. switch (p_what) {
  279. case 0: { //gesture begin
  280. if (touch.size()) {
  281. //end all if exist
  282. for (int i = 0; i < touch.size(); i++) {
  283. Ref<InputEventScreenTouch> ev;
  284. ev.instance();
  285. ev->set_index(touch[i].id);
  286. ev->set_pressed(false);
  287. ev->set_position(touch[i].pos);
  288. input->parse_input_event(ev);
  289. }
  290. }
  291. touch.resize(p_points.size());
  292. for (int i = 0; i < p_points.size(); i++) {
  293. touch.write[i].id = p_points[i].id;
  294. touch.write[i].pos = p_points[i].pos;
  295. }
  296. //send touch
  297. for (int i = 0; i < touch.size(); i++) {
  298. Ref<InputEventScreenTouch> ev;
  299. ev.instance();
  300. ev->set_index(touch[i].id);
  301. ev->set_pressed(true);
  302. ev->set_position(touch[i].pos);
  303. input->parse_input_event(ev);
  304. }
  305. } break;
  306. case 1: { //motion
  307. ERR_FAIL_COND(touch.size() != p_points.size());
  308. for (int i = 0; i < touch.size(); i++) {
  309. int idx = -1;
  310. for (int j = 0; j < p_points.size(); j++) {
  311. if (touch[i].id == p_points[j].id) {
  312. idx = j;
  313. break;
  314. }
  315. }
  316. ERR_CONTINUE(idx == -1);
  317. if (touch[i].pos == p_points[idx].pos)
  318. continue; //no move unncesearily
  319. Ref<InputEventScreenDrag> ev;
  320. ev.instance();
  321. ev->set_index(touch[i].id);
  322. ev->set_position(p_points[idx].pos);
  323. ev->set_relative(p_points[idx].pos - touch[i].pos);
  324. input->parse_input_event(ev);
  325. touch.write[i].pos = p_points[idx].pos;
  326. }
  327. } break;
  328. case 2: { //release
  329. if (touch.size()) {
  330. //end all if exist
  331. for (int i = 0; i < touch.size(); i++) {
  332. Ref<InputEventScreenTouch> ev;
  333. ev.instance();
  334. ev->set_index(touch[i].id);
  335. ev->set_pressed(false);
  336. ev->set_position(touch[i].pos);
  337. input->parse_input_event(ev);
  338. }
  339. touch.clear();
  340. }
  341. } break;
  342. case 3: { // add touch
  343. for (int i = 0; i < p_points.size(); i++) {
  344. if (p_points[i].id == p_pointer) {
  345. TouchPos tp = p_points[i];
  346. touch.push_back(tp);
  347. Ref<InputEventScreenTouch> ev;
  348. ev.instance();
  349. ev->set_index(tp.id);
  350. ev->set_pressed(true);
  351. ev->set_position(tp.pos);
  352. input->parse_input_event(ev);
  353. break;
  354. }
  355. }
  356. } break;
  357. case 4: { // remove touch
  358. for (int i = 0; i < touch.size(); i++) {
  359. if (touch[i].id == p_pointer) {
  360. Ref<InputEventScreenTouch> ev;
  361. ev.instance();
  362. ev->set_index(touch[i].id);
  363. ev->set_pressed(false);
  364. ev->set_position(touch[i].pos);
  365. input->parse_input_event(ev);
  366. touch.remove(i);
  367. break;
  368. }
  369. }
  370. } break;
  371. }
  372. }
  373. void OS_Android::process_hover(int p_type, Point2 p_pos) {
  374. // https://developer.android.com/reference/android/view/MotionEvent.html#ACTION_HOVER_ENTER
  375. switch (p_type) {
  376. case 7: // hover move
  377. case 9: // hover enter
  378. case 10: { // hover exit
  379. Ref<InputEventMouseMotion> ev;
  380. ev.instance();
  381. ev->set_position(p_pos);
  382. ev->set_global_position(p_pos);
  383. ev->set_relative(p_pos - hover_prev_pos);
  384. input->parse_input_event(ev);
  385. hover_prev_pos = p_pos;
  386. } break;
  387. }
  388. }
  389. void OS_Android::process_double_tap(Point2 p_pos) {
  390. Ref<InputEventMouseButton> ev;
  391. ev.instance();
  392. ev->set_position(p_pos);
  393. ev->set_global_position(p_pos);
  394. ev->set_pressed(false);
  395. ev->set_doubleclick(true);
  396. input->parse_input_event(ev);
  397. }
  398. void OS_Android::process_scroll(Point2 p_pos) {
  399. Ref<InputEventPanGesture> ev;
  400. ev.instance();
  401. ev->set_position(p_pos);
  402. ev->set_delta(p_pos - scroll_prev_pos);
  403. input->parse_input_event(ev);
  404. scroll_prev_pos = p_pos;
  405. }
  406. void OS_Android::process_accelerometer(const Vector3 &p_accelerometer) {
  407. input->set_accelerometer(p_accelerometer);
  408. }
  409. void OS_Android::process_gravity(const Vector3 &p_gravity) {
  410. input->set_gravity(p_gravity);
  411. }
  412. void OS_Android::process_magnetometer(const Vector3 &p_magnetometer) {
  413. input->set_magnetometer(p_magnetometer);
  414. }
  415. void OS_Android::process_gyroscope(const Vector3 &p_gyroscope) {
  416. input->set_gyroscope(p_gyroscope);
  417. }
  418. bool OS_Android::has_touchscreen_ui_hint() const {
  419. return true;
  420. }
  421. bool OS_Android::has_virtual_keyboard() const {
  422. return true;
  423. }
  424. int OS_Android::get_virtual_keyboard_height() const {
  425. return godot_io_java->get_vk_height();
  426. // ERR_PRINT("Cannot obtain virtual keyboard height.");
  427. // return 0;
  428. }
  429. void OS_Android::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect, bool p_multiline, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
  430. if (godot_io_java->has_vk()) {
  431. godot_io_java->show_vk(p_existing_text, p_multiline, p_max_input_length, p_cursor_start, p_cursor_end);
  432. } else {
  433. ERR_PRINT("Virtual keyboard not available");
  434. };
  435. }
  436. void OS_Android::hide_virtual_keyboard() {
  437. if (godot_io_java->has_vk()) {
  438. godot_io_java->hide_vk();
  439. } else {
  440. ERR_PRINT("Virtual keyboard not available");
  441. };
  442. }
  443. void OS_Android::init_video_mode(int p_video_width, int p_video_height) {
  444. default_videomode.width = p_video_width;
  445. default_videomode.height = p_video_height;
  446. default_videomode.fullscreen = true;
  447. default_videomode.resizable = false;
  448. }
  449. void OS_Android::main_loop_request_go_back() {
  450. if (main_loop)
  451. main_loop->notification(MainLoop::NOTIFICATION_WM_GO_BACK_REQUEST);
  452. }
  453. void OS_Android::set_display_size(Size2 p_size) {
  454. default_videomode.width = p_size.x;
  455. default_videomode.height = p_size.y;
  456. }
  457. Error OS_Android::shell_open(String p_uri) {
  458. return godot_io_java->open_uri(p_uri);
  459. }
  460. String OS_Android::get_resource_dir() const {
  461. return "/"; //android has its own filesystem for resources inside the APK
  462. }
  463. String OS_Android::get_locale() const {
  464. String locale = godot_io_java->get_locale();
  465. if (locale != "") {
  466. return locale;
  467. }
  468. return OS_Unix::get_locale();
  469. }
  470. void OS_Android::set_clipboard(const String &p_text) {
  471. // DO we really need the fallback to OS_Unix here?!
  472. if (godot_java->has_set_clipboard()) {
  473. godot_java->set_clipboard(p_text);
  474. } else {
  475. OS_Unix::set_clipboard(p_text);
  476. }
  477. }
  478. String OS_Android::get_clipboard() const {
  479. // DO we really need the fallback to OS_Unix here?!
  480. if (godot_java->has_get_clipboard()) {
  481. return godot_java->get_clipboard();
  482. }
  483. return OS_Unix::get_clipboard();
  484. }
  485. String OS_Android::get_model_name() const {
  486. String model = godot_io_java->get_model();
  487. if (model != "")
  488. return model;
  489. return OS_Unix::get_model_name();
  490. }
  491. int OS_Android::get_screen_dpi(int p_screen) const {
  492. return godot_io_java->get_screen_dpi();
  493. }
  494. String OS_Android::get_user_data_dir() const {
  495. if (data_dir_cache != String())
  496. return data_dir_cache;
  497. String data_dir = godot_io_java->get_user_data_dir();
  498. if (data_dir != "") {
  499. //store current dir
  500. char real_current_dir_name[2048];
  501. getcwd(real_current_dir_name, 2048);
  502. //go to data dir
  503. chdir(data_dir.utf8().get_data());
  504. //get actual data dir, so we resolve potential symlink (Android 6.0+ seems to use symlink)
  505. char data_current_dir_name[2048];
  506. getcwd(data_current_dir_name, 2048);
  507. //cache by parsing utf8
  508. data_dir_cache.parse_utf8(data_current_dir_name);
  509. //restore original dir so we don't mess things up
  510. chdir(real_current_dir_name);
  511. return data_dir_cache;
  512. }
  513. return ".";
  514. }
  515. void OS_Android::set_screen_orientation(ScreenOrientation p_orientation) {
  516. godot_io_java->set_screen_orientation(p_orientation);
  517. }
  518. String OS_Android::get_unique_id() const {
  519. String unique_id = godot_io_java->get_unique_id();
  520. if (unique_id != "")
  521. return unique_id;
  522. return OS::get_unique_id();
  523. }
  524. Error OS_Android::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) {
  525. // FIXME: Add support for volume, audio and subtitle tracks
  526. godot_io_java->play_video(p_path);
  527. return OK;
  528. }
  529. bool OS_Android::native_video_is_playing() const {
  530. return godot_io_java->is_video_playing();
  531. }
  532. void OS_Android::native_video_pause() {
  533. godot_io_java->pause_video();
  534. }
  535. String OS_Android::get_system_dir(SystemDir p_dir) const {
  536. return godot_io_java->get_system_dir(p_dir);
  537. }
  538. void OS_Android::native_video_stop() {
  539. godot_io_java->stop_video();
  540. }
  541. void OS_Android::set_context_is_16_bits(bool p_is_16) {
  542. //use_16bits_fbo = p_is_16;
  543. //if (rasterizer)
  544. // rasterizer->set_force_16_bits_fbo(p_is_16);
  545. }
  546. void OS_Android::joy_connection_changed(int p_device, bool p_connected, String p_name) {
  547. return input->joy_connection_changed(p_device, p_connected, p_name, "");
  548. }
  549. bool OS_Android::is_joy_known(int p_device) {
  550. return input->is_joy_mapped(p_device);
  551. }
  552. String OS_Android::get_joy_guid(int p_device) const {
  553. return input->get_joy_guid_remapped(p_device);
  554. }
  555. void OS_Android::vibrate_handheld(int p_duration_ms) {
  556. godot_java->vibrate(p_duration_ms);
  557. }
  558. bool OS_Android::_check_internal_feature_support(const String &p_feature) {
  559. if (p_feature == "mobile") {
  560. //TODO support etc2 only if GLES3 driver is selected
  561. return true;
  562. }
  563. #if defined(__aarch64__)
  564. if (p_feature == "arm64-v8a") {
  565. return true;
  566. }
  567. #elif defined(__ARM_ARCH_7A__)
  568. if (p_feature == "armeabi-v7a" || p_feature == "armeabi") {
  569. return true;
  570. }
  571. #elif defined(__arm__)
  572. if (p_feature == "armeabi") {
  573. return true;
  574. }
  575. #endif
  576. return false;
  577. }
  578. OS_Android::OS_Android(GodotJavaWrapper *p_godot_java, GodotIOJavaWrapper *p_godot_io_java, bool p_use_apk_expansion) {
  579. use_apk_expansion = p_use_apk_expansion;
  580. default_videomode.width = 800;
  581. default_videomode.height = 600;
  582. default_videomode.fullscreen = true;
  583. default_videomode.resizable = false;
  584. main_loop = NULL;
  585. gl_extensions = NULL;
  586. //rasterizer = NULL;
  587. use_gl2 = false;
  588. godot_java = p_godot_java;
  589. godot_io_java = p_godot_io_java;
  590. Vector<Logger *> loggers;
  591. loggers.push_back(memnew(AndroidLogger));
  592. _set_logger(memnew(CompositeLogger(loggers)));
  593. AudioDriverManager::add_driver(&audio_driver_android);
  594. }
  595. OS_Android::~OS_Android() {
  596. }