From 008838555620261b25a4df7a814cc789ec4a4ad3 Mon Sep 17 00:00:00 2001 From: Cagdas Date: Sun, 6 Oct 2019 21:17:44 +0300 Subject: [PATCH] Add request permission automatically at android --- core/bind/core_bind.cpp | 12 ++ core/bind/core_bind.h | 2 + core/os/main_loop.cpp | 2 + core/os/os.h | 2 + doc/classes/MainLoop.xml | 11 ++ doc/classes/OS.xml | 14 ++ .../lib/src/org/godotengine/godot/Godot.java | 37 +---- .../godot/utils/PermissionsUtil.java | 157 ++++++++++++++++++ platform/android/java_godot_lib_jni.cpp | 4 + platform/android/java_godot_wrapper.cpp | 30 ++++ platform/android/java_godot_wrapper.h | 4 + platform/android/os_android.cpp | 10 ++ platform/android/os_android.h | 2 + 13 files changed, 258 insertions(+), 29 deletions(-) create mode 100644 platform/android/java/lib/src/org/godotengine/godot/utils/PermissionsUtil.java diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index d07ba447883..1d451b2982f 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -1136,6 +1136,16 @@ bool _OS::request_permission(const String &p_name) { return OS::get_singleton()->request_permission(p_name); } +bool _OS::request_permissions() { + + return OS::get_singleton()->request_permissions(); +} + +Vector _OS::get_granted_permissions() const { + + return OS::get_singleton()->get_granted_permissions(); +} + _OS *_OS::singleton = NULL; void _OS::_bind_methods() { @@ -1319,6 +1329,8 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_power_percent_left"), &_OS::get_power_percent_left); ClassDB::bind_method(D_METHOD("request_permission", "name"), &_OS::request_permission); + ClassDB::bind_method(D_METHOD("request_permissions"), &_OS::request_permissions); + ClassDB::bind_method(D_METHOD("get_granted_permissions"), &_OS::get_granted_permissions); ADD_PROPERTY(PropertyInfo(Variant::STRING, "clipboard"), "set_clipboard", "get_clipboard"); ADD_PROPERTY(PropertyInfo(Variant::INT, "current_screen"), "set_current_screen", "get_current_screen"); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 693b85710a7..1a4fd1d5cb0 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -349,6 +349,8 @@ public: bool has_feature(const String &p_feature) const; bool request_permission(const String &p_name); + bool request_permissions(); + Vector get_granted_permissions() const; static _OS *get_singleton() { return singleton; } diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index 5587e827baa..146a3019950 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -65,6 +65,8 @@ void MainLoop::_bind_methods() { BIND_CONSTANT(NOTIFICATION_OS_IME_UPDATE); BIND_CONSTANT(NOTIFICATION_APP_RESUMED); BIND_CONSTANT(NOTIFICATION_APP_PAUSED); + + ADD_SIGNAL(MethodInfo("on_request_permissions_result", PropertyInfo(Variant::STRING, "permission"), PropertyInfo(Variant::BOOL, "granted"))); }; void MainLoop::set_init_script(const Ref