summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/android/SCsub1
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/Godot.java3
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/utils/GodotNetUtils.java84
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/utils/PermissionsUtil.java18
-rw-r--r--platform/android/java_godot_lib_jni.cpp2
-rw-r--r--platform/android/net_socket_android.cpp136
-rw-r--r--platform/android/net_socket_android.h78
-rw-r--r--platform/android/os_android.cpp3
-rw-r--r--platform/iphone/export/export.cpp42
-rw-r--r--platform/osx/export/export.cpp9
10 files changed, 335 insertions, 41 deletions
diff --git a/platform/android/SCsub b/platform/android/SCsub
index 65172a12c0..3ff5b8278a 100644
--- a/platform/android/SCsub
+++ b/platform/android/SCsub
@@ -12,6 +12,7 @@ android_files = [
'file_access_jandroid.cpp',
'dir_access_jandroid.cpp',
'thread_jandroid.cpp',
+ 'net_socket_android.cpp',
'audio_driver_jandroid.cpp',
'java_godot_lib_jni.cpp',
'java_class_wrapper.cpp',
diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.java b/platform/android/java/lib/src/org/godotengine/godot/Godot.java
index 4dae2dcc53..d951998632 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/Godot.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.java
@@ -96,6 +96,7 @@ import java.util.Locale;
import javax.microedition.khronos.opengles.GL10;
import org.godotengine.godot.input.GodotEditText;
import org.godotengine.godot.payments.PaymentsManager;
+import org.godotengine.godot.utils.GodotNetUtils;
import org.godotengine.godot.utils.PermissionsUtil;
import org.godotengine.godot.xr.XRMode;
@@ -243,6 +244,7 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
private Sensor mGyroscope;
public static GodotIO io;
+ public static GodotNetUtils netUtils;
static SingletonBase[] singletons = new SingletonBase[MAX_SINGLETONS];
static int singleton_count = 0;
@@ -502,6 +504,7 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
io = new GodotIO(this);
io.unique_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
GodotLib.io = io;
+ netUtils = new GodotNetUtils(this);
mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
diff --git a/platform/android/java/lib/src/org/godotengine/godot/utils/GodotNetUtils.java b/platform/android/java/lib/src/org/godotengine/godot/utils/GodotNetUtils.java
new file mode 100644
index 0000000000..0dc6962ca6
--- /dev/null
+++ b/platform/android/java/lib/src/org/godotengine/godot/utils/GodotNetUtils.java
@@ -0,0 +1,84 @@
+/*************************************************************************/
+/* GodotNetUtils.java */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+package org.godotengine.godot.utils;
+
+import android.content.Context;
+import android.net.wifi.WifiManager;
+import android.util.Log;
+
+import org.godotengine.godot.Godot;
+
+/**
+ * This class handles Android-specific networking functions.
+ * For now, it only provides access to WifiManager.MulticastLock, which is needed on some devices
+ * to receive broadcast and multicast packets.
+ */
+public class GodotNetUtils {
+
+ /* A single, reference counted, multicast lock, or null if permission CHANGE_WIFI_MULTICAST_STATE is missing */
+ private WifiManager.MulticastLock multicastLock;
+
+ public GodotNetUtils(Godot p_activity) {
+ if (PermissionsUtil.hasManifestPermission(p_activity, "android.permission.CHANGE_WIFI_MULTICAST_STATE")) {
+ WifiManager wifi = (WifiManager)p_activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
+ multicastLock = wifi.createMulticastLock("GodotMulticastLock");
+ multicastLock.setReferenceCounted(true);
+ }
+ }
+
+ /**
+ * Acquire the multicast lock. This is required on some devices to receive broadcast/multicast packets.
+ * This is done automatically by Godot when enabling broadcast or joining a multicast group on a socket.
+ */
+ public void multicastLockAcquire() {
+ if (multicastLock == null)
+ return;
+ try {
+ multicastLock.acquire();
+ } catch (RuntimeException e) {
+ Log.e("Godot", "Exception during multicast lock acquire: " + e);
+ }
+ }
+
+ /**
+ * Release the multicast lock.
+ * This is done automatically by Godot when the lock is no longer needed by a socket.
+ */
+ public void multicastLockRelease() {
+ if (multicastLock == null)
+ return;
+ try {
+ multicastLock.release();
+ } catch (RuntimeException e) {
+ Log.e("Godot", "Exception during multicast lock release: " + e);
+ }
+ }
+}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/utils/PermissionsUtil.java b/platform/android/java/lib/src/org/godotengine/godot/utils/PermissionsUtil.java
index 21df5a91b0..7e35417c6a 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/utils/PermissionsUtil.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/utils/PermissionsUtil.java
@@ -162,6 +162,24 @@ public final class PermissionsUtil {
}
/**
+ * Check if the given permission is in the AndroidManifest.xml file.
+ * @param activity the caller activity for this method.
+ * @param permission the permession to look for in the manifest file.
+ * @return "true" if the permission is in the manifest file of the activity, "false" otherwise.
+ */
+ public static boolean hasManifestPermission(Godot activity, String permission) {
+ try {
+ for (String p : getManifestPermissions(activity)) {
+ if (permission.equals(p))
+ return true;
+ }
+ } catch (PackageManager.NameNotFoundException e) {
+ }
+
+ return false;
+ }
+
+ /**
* Returns the permissions defined in the AndroidManifest.xml file.
* @param activity the caller activity for this method.
* @return manifest permissions list
diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp
index a14e0a1960..1ad1fb0afe 100644
--- a/platform/android/java_godot_lib_jni.cpp
+++ b/platform/android/java_godot_lib_jni.cpp
@@ -43,6 +43,7 @@
#include "java_class_wrapper.h"
#include "main/input_default.h"
#include "main/main.h"
+#include "net_socket_android.h"
#include "os_android.h"
#include "string_android.h"
#include "thread_jandroid.h"
@@ -635,6 +636,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *en
DirAccessJAndroid::setup(godot_io_java->get_instance());
AudioDriverAndroid::setup(godot_io_java->get_instance());
+ NetSocketAndroid::setup(godot_java->get_member_object("netUtils", "Lorg/godotengine/godot/utils/GodotNetUtils;", env));
os_android = new OS_Android(godot_java, godot_io_java, p_use_apk_expansion);
diff --git a/platform/android/net_socket_android.cpp b/platform/android/net_socket_android.cpp
new file mode 100644
index 0000000000..78ef354c21
--- /dev/null
+++ b/platform/android/net_socket_android.cpp
@@ -0,0 +1,136 @@
+/*************************************************************************/
+/* net_socket_android.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "net_socket_android.h"
+
+#include "thread_jandroid.h"
+
+jobject NetSocketAndroid::net_utils = 0;
+jclass NetSocketAndroid::cls = 0;
+jmethodID NetSocketAndroid::_multicast_lock_acquire = 0;
+jmethodID NetSocketAndroid::_multicast_lock_release = 0;
+
+void NetSocketAndroid::setup(jobject p_net_utils) {
+
+ JNIEnv *env = ThreadAndroid::get_env();
+
+ net_utils = env->NewGlobalRef(p_net_utils);
+
+ jclass c = env->GetObjectClass(net_utils);
+ cls = (jclass)env->NewGlobalRef(c);
+
+ _multicast_lock_acquire = env->GetMethodID(cls, "multicastLockAcquire", "()V");
+ _multicast_lock_release = env->GetMethodID(cls, "multicastLockRelease", "()V");
+}
+
+void NetSocketAndroid::multicast_lock_acquire() {
+ if (_multicast_lock_acquire) {
+ JNIEnv *env = ThreadAndroid::get_env();
+ env->CallVoidMethod(net_utils, _multicast_lock_acquire);
+ }
+}
+
+void NetSocketAndroid::multicast_lock_release() {
+ if (_multicast_lock_release) {
+ JNIEnv *env = ThreadAndroid::get_env();
+ env->CallVoidMethod(net_utils, _multicast_lock_release);
+ }
+}
+
+NetSocket *NetSocketAndroid::_create_func() {
+ return memnew(NetSocketAndroid);
+}
+
+void NetSocketAndroid::make_default() {
+ _create = _create_func;
+}
+
+NetSocketAndroid::NetSocketAndroid() :
+ wants_broadcast(false),
+ multicast_groups(0) {
+}
+
+NetSocketAndroid::~NetSocketAndroid() {
+ close();
+}
+
+void NetSocketAndroid::close() {
+ NetSocketPosix::close();
+ if (wants_broadcast)
+ multicast_lock_release();
+ if (multicast_groups)
+ multicast_lock_release();
+ wants_broadcast = false;
+ multicast_groups = 0;
+}
+
+Error NetSocketAndroid::set_broadcasting_enabled(bool p_enabled) {
+ Error err = NetSocketPosix::set_broadcasting_enabled(p_enabled);
+ if (err != OK)
+ return err;
+
+ if (p_enabled != wants_broadcast) {
+ if (p_enabled) {
+ multicast_lock_acquire();
+ } else {
+ multicast_lock_release();
+ }
+
+ wants_broadcast = p_enabled;
+ }
+
+ return OK;
+}
+
+Error NetSocketAndroid::join_multicast_group(const IP_Address &p_multi_address, String p_if_name) {
+ Error err = NetSocketPosix::join_multicast_group(p_multi_address, p_if_name);
+ if (err != OK)
+ return err;
+
+ if (!multicast_groups)
+ multicast_lock_acquire();
+ multicast_groups++;
+
+ return OK;
+}
+
+Error NetSocketAndroid::leave_multicast_group(const IP_Address &p_multi_address, String p_if_name) {
+ Error err = NetSocketPosix::leave_multicast_group(p_multi_address, p_if_name);
+ if (err != OK)
+ return err;
+
+ ERR_FAIL_COND_V(multicast_groups == 0, ERR_BUG);
+
+ multicast_groups--;
+ if (!multicast_groups)
+ multicast_lock_release();
+
+ return OK;
+}
diff --git a/platform/android/net_socket_android.h b/platform/android/net_socket_android.h
new file mode 100644
index 0000000000..1ecbac0c1a
--- /dev/null
+++ b/platform/android/net_socket_android.h
@@ -0,0 +1,78 @@
+/*************************************************************************/
+/* net_socket_android.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef NET_SOCKET_ANDROID_H
+#define NET_SOCKET_ANDROID_H
+
+#include "drivers/unix/net_socket_posix.h"
+
+#include <jni.h>
+
+/**
+ * Specialized NetSocket implementation for Android.
+ *
+ * Some devices requires Android-specific code to acquire a MulticastLock
+ * before sockets are allowed to receive broadcast and multicast packets.
+ * This implementation calls into Java code and automatically acquire/release
+ * the lock when broadcasting is enabled/disabled on a socket, or that socket
+ * joins/leaves a multicast group.
+ */
+class NetSocketAndroid : public NetSocketPosix {
+
+private:
+ static jobject net_utils;
+ static jclass cls;
+ static jmethodID _multicast_lock_acquire;
+ static jmethodID _multicast_lock_release;
+
+ bool wants_broadcast;
+ int multicast_groups;
+
+ static void multicast_lock_acquire();
+ static void multicast_lock_release();
+
+protected:
+ static NetSocket *_create_func();
+
+public:
+ static void make_default();
+ static void setup(jobject p_net_utils);
+
+ virtual void close();
+
+ virtual Error set_broadcasting_enabled(bool p_enabled);
+ virtual Error join_multicast_group(const IP_Address &p_multi_address, String p_if_name);
+ virtual Error leave_multicast_group(const IP_Address &p_multi_address, String p_if_name);
+
+ NetSocketAndroid();
+ ~NetSocketAndroid();
+};
+
+#endif
diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp
index 9068b76cfb..f08dcc449e 100644
--- a/platform/android/os_android.cpp
+++ b/platform/android/os_android.cpp
@@ -43,6 +43,7 @@
#include "dir_access_jandroid.h"
#include "file_access_jandroid.h"
+#include "net_socket_android.h"
#include <dlfcn.h>
@@ -106,6 +107,8 @@ void OS_Android::initialize_core() {
DirAccess::make_default<DirAccessJAndroid>(DirAccess::ACCESS_RESOURCES);
DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_USERDATA);
DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_FILESYSTEM);
+
+ NetSocketAndroid::make_default();
}
void OS_Android::set_opengl_extensions(const char *p_gl_extensions) {
diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp
index 4f4439bc60..8eac120939 100644
--- a/platform/iphone/export/export.cpp
+++ b/platform/iphone/export/export.cpp
@@ -114,54 +114,14 @@ class EditorExportPlatformIOS : public EditorExportPlatform {
return false;
}
- int segments = 0;
- bool first = true;
for (int i = 0; i < pname.length(); i++) {
CharType c = pname[i];
- if (first && c == '.') {
- if (r_error) {
- *r_error = TTR("Identifier segments must be of non-zero length.");
- }
- return false;
- }
- if (c == '.') {
- segments++;
- first = true;
- continue;
- }
- if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-')) {
+ if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '.')) {
if (r_error) {
*r_error = vformat(TTR("The character '%s' is not allowed in Identifier."), String::chr(c));
}
return false;
}
- if (first && (c >= '0' && c <= '9')) {
- if (r_error) {
- *r_error = TTR("A digit cannot be the first character in a Identifier segment.");
- }
- return false;
- }
- if (first && c == '-') {
- if (r_error) {
- *r_error = vformat(TTR("The character '%s' cannot be the first character in a Identifier segment."), String::chr(c));
- }
- return false;
- }
- first = false;
- }
-
- if (segments == 0) {
- if (r_error) {
- *r_error = TTR("The Identifier must have at least one '.' separator.");
- }
- return false;
- }
-
- if (first) {
- if (r_error) {
- *r_error = TTR("Identifier segments must be of non-zero length.");
- }
- return false;
}
return true;
diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp
index 9226aea369..590858b558 100644
--- a/platform/osx/export/export.cpp
+++ b/platform/osx/export/export.cpp
@@ -130,6 +130,9 @@ void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options)
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), false));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/camera_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the camera"), ""));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/microphone_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the microphone"), ""));
+
#ifdef OSX_ENABLED
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/enable"), false));
@@ -342,6 +345,12 @@ void EditorExportPlatformOSX::_fix_plist(const Ref<EditorExportPreset> &p_preset
strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";
} else if (lines[i].find("$highres") != -1) {
strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "<true/>" : "<false/>") + "\n";
+ } else if (lines[i].find("$camera_usage_description") != -1) {
+ String description = p_preset->get("privacy/camera_usage_description");
+ strnew += lines[i].replace("$camera_usage_description", description) + "\n";
+ } else if (lines[i].find("$microphone_usage_description") != -1) {
+ String description = p_preset->get("privacy/microphone_usage_description");
+ strnew += lines[i].replace("$microphone_usage_description", description) + "\n";
} else {
strnew += lines[i] + "\n";
}