You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-29 16:16:38 +00:00
Android port of the Godot Editor
These set of changes focus primarily on getting the core logic and overall Godot Editor UI and functionality up and running natively on Android devices. UI tweaks / cleanup / polish, as well configuration for Android specific functionality / restrictions will be addressed in follow-up PRs iteratively based on feedback. Co-authored-by: thebestnom <shoval.arad@gmail.com>
This commit is contained in:
committed by
Fredia Huya-Kouadio
parent
0c7a15d777
commit
5711037bf6
@@ -35,6 +35,7 @@
|
||||
#include "drivers/unix/file_access_unix.h"
|
||||
#include "main/main.h"
|
||||
#include "platform/android/display_server_android.h"
|
||||
#include "scene/main/scene_tree.h"
|
||||
|
||||
#include "dir_access_jandroid.h"
|
||||
#include "file_access_android.h"
|
||||
@@ -45,6 +46,8 @@
|
||||
#include "java_godot_io_wrapper.h"
|
||||
#include "java_godot_wrapper.h"
|
||||
|
||||
const char *OS_Android::ANDROID_EXEC_PATH = "apk";
|
||||
|
||||
String _remove_symlink(const String &dir) {
|
||||
// Workaround for Android 6.0+ using a symlink.
|
||||
// Save the current directory.
|
||||
@@ -81,18 +84,28 @@ void OS_Android::alert(const String &p_alert, const String &p_title) {
|
||||
void OS_Android::initialize_core() {
|
||||
OS_Unix::initialize_core();
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
|
||||
#else
|
||||
if (use_apk_expansion) {
|
||||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
|
||||
} else {
|
||||
FileAccess::make_default<FileAccessAndroid>(FileAccess::ACCESS_RESOURCES);
|
||||
}
|
||||
#endif
|
||||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA);
|
||||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_FILESYSTEM);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_RESOURCES);
|
||||
#else
|
||||
if (use_apk_expansion) {
|
||||
DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_RESOURCES);
|
||||
} else {
|
||||
DirAccess::make_default<DirAccessJAndroid>(DirAccess::ACCESS_RESOURCES);
|
||||
}
|
||||
#endif
|
||||
|
||||
DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_USERDATA);
|
||||
DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_FILESYSTEM);
|
||||
|
||||
@@ -178,6 +191,10 @@ bool OS_Android::main_loop_iterate() {
|
||||
|
||||
void OS_Android::main_loop_end() {
|
||||
if (main_loop) {
|
||||
SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop);
|
||||
if (scene_tree) {
|
||||
scene_tree->quit();
|
||||
}
|
||||
main_loop->finalize();
|
||||
}
|
||||
}
|
||||
@@ -197,7 +214,11 @@ Error OS_Android::shell_open(String p_uri) {
|
||||
}
|
||||
|
||||
String OS_Android::get_resource_dir() const {
|
||||
#ifdef TOOLS_ENABLED
|
||||
return OS_Unix::get_resource_dir();
|
||||
#else
|
||||
return "/"; //android has its own filesystem for resources inside the APK
|
||||
#endif
|
||||
}
|
||||
|
||||
String OS_Android::get_locale() const {
|
||||
@@ -222,6 +243,14 @@ String OS_Android::get_data_path() const {
|
||||
return get_user_data_dir();
|
||||
}
|
||||
|
||||
String OS_Android::get_executable_path() const {
|
||||
// Since unix process creation is restricted on Android, we bypass
|
||||
// OS_Unix::get_executable_path() so we can return ANDROID_EXEC_PATH.
|
||||
// Detection of ANDROID_EXEC_PATH allows to handle process creation in an Android compliant
|
||||
// manner.
|
||||
return OS::get_executable_path();
|
||||
}
|
||||
|
||||
String OS_Android::get_user_data_dir() const {
|
||||
if (!data_dir_cache.is_empty()) {
|
||||
return data_dir_cache;
|
||||
@@ -294,6 +323,10 @@ void OS_Android::vibrate_handheld(int p_duration_ms) {
|
||||
godot_java->vibrate(p_duration_ms);
|
||||
}
|
||||
|
||||
String OS_Android::get_config_path() const {
|
||||
return get_user_data_dir().plus_file("config");
|
||||
}
|
||||
|
||||
bool OS_Android::_check_internal_feature_support(const String &p_feature) {
|
||||
if (p_feature == "mobile") {
|
||||
return true;
|
||||
@@ -343,5 +376,26 @@ OS_Android::OS_Android(GodotJavaWrapper *p_godot_java, GodotIOJavaWrapper *p_god
|
||||
DisplayServerAndroid::register_android_driver();
|
||||
}
|
||||
|
||||
Error OS_Android::execute(const String &p_path, const List<String> &p_arguments, String *r_pipe, int *r_exitcode, bool read_stderr, Mutex *p_pipe_mutex, bool p_open_console) {
|
||||
if (p_path == ANDROID_EXEC_PATH) {
|
||||
return create_instance(p_arguments);
|
||||
} else {
|
||||
return OS_Unix::execute(p_path, p_arguments, r_pipe, r_exitcode, read_stderr, p_pipe_mutex, p_open_console);
|
||||
}
|
||||
}
|
||||
|
||||
Error OS_Android::create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id, bool p_open_console) {
|
||||
if (p_path == ANDROID_EXEC_PATH) {
|
||||
return create_instance(p_arguments, r_child_id);
|
||||
} else {
|
||||
return OS_Unix::create_process(p_path, p_arguments, r_child_id, p_open_console);
|
||||
}
|
||||
}
|
||||
|
||||
Error OS_Android::create_instance(const List<String> &p_arguments, ProcessID *r_child_id) {
|
||||
godot_java->create_new_godot_instance(p_arguments);
|
||||
return OK;
|
||||
}
|
||||
|
||||
OS_Android::~OS_Android() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user