Resolved conflict and added Android_JNI_RequestPermission()
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index 7f1955f..9dd961d 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -21,6 +21,7 @@
#include "../../SDL_internal.h"
#include "SDL_stdinc.h"
#include "SDL_assert.h"
+#include "SDL_atomic.h"
#include "SDL_hints.h"
#include "SDL_log.h"
#include "SDL_main.h"
@@ -155,6 +156,10 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeAddTouch)(
JNIEnv* env, jclass cls,
jint touchId, jstring name);
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePermissionResult)(
+ JNIEnv* env, jclass cls,
+ jint requestCode, jboolean result);
+
static JNINativeMethod SDLActivity_tab[] = {
{ "nativeSetupJNI", "()I", SDL_JAVA_INTERFACE(nativeSetupJNI) },
{ "nativeRunMain", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)I", SDL_JAVA_INTERFACE(nativeRunMain) },
@@ -181,7 +186,8 @@ static JNINativeMethod SDLActivity_tab[] = {
{ "nativeGetHint", "(Ljava/lang/String;)Ljava/lang/String;", SDL_JAVA_INTERFACE(nativeGetHint) },
{ "nativeSetenv", "(Ljava/lang/String;Ljava/lang/String;)V", SDL_JAVA_INTERFACE(nativeSetenv) },
{ "onNativeOrientationChanged", "(I)V", SDL_JAVA_INTERFACE(onNativeOrientationChanged) },
- { "nativeAddTouch", "(ILjava/lang/String;)V", SDL_JAVA_INTERFACE(nativeAddTouch) }
+ { "nativeAddTouch", "(ILjava/lang/String;)V", SDL_JAVA_INTERFACE(nativeAddTouch) },
+ { "nativePermissionResult", "(IZ)V", SDL_JAVA_INTERFACE(nativePermissionResult) }
};
/* Java class SDLInputConnection */
@@ -283,34 +289,35 @@ static JavaVM *mJavaVM = NULL;
static jclass mActivityClass;
/* method signatures */
-static jmethodID midGetNativeSurface;
-static jmethodID midSetSurfaceViewFormat;
-static jmethodID midSetActivityTitle;
-static jmethodID midSetWindowStyle;
-static jmethodID midSetOrientation;
-static jmethodID midMinimizeWindow;
-static jmethodID midShouldMinimizeOnFocusLoss;
+static jmethodID midClipboardGetText;
+static jmethodID midClipboardHasText;
+static jmethodID midClipboardSetText;
+static jmethodID midCreateCustomCursor;
static jmethodID midGetContext;
-static jmethodID midIsTablet;
+static jmethodID midGetDisplayDPI;
+static jmethodID midGetManifestEnvironmentVariables;
+static jmethodID midGetNativeSurface;
+static jmethodID midInitTouch;
static jmethodID midIsAndroidTV;
static jmethodID midIsChromebook;
static jmethodID midIsDeXMode;
-static jmethodID midManualBackButton;
-static jmethodID midInitTouch;
-static jmethodID midSendMessage;
-static jmethodID midShowTextInput;
static jmethodID midIsScreenKeyboardShown;
-static jmethodID midClipboardSetText;
-static jmethodID midClipboardGetText;
-static jmethodID midClipboardHasText;
+static jmethodID midIsTablet;
+static jmethodID midManualBackButton;
+static jmethodID midMinimizeWindow;
static jmethodID midOpenAPKExpansionInputStream;
-static jmethodID midGetManifestEnvironmentVariables;
-static jmethodID midGetDisplayDPI;
-static jmethodID midCreateCustomCursor;
+static jmethodID midRequestPermission;
+static jmethodID midSendMessage;
+static jmethodID midSetActivityTitle;
static jmethodID midSetCustomCursor;
+static jmethodID midSetOrientation;
+static jmethodID midSetRelativeMouseEnabled;
+static jmethodID midSetSurfaceViewFormat;
static jmethodID midSetSystemCursor;
+static jmethodID midSetWindowStyle;
+static jmethodID midShouldMinimizeOnFocusLoss;
+static jmethodID midShowTextInput;
static jmethodID midSupportsRelativeMouse;
-static jmethodID midSetRelativeMouseEnabled;
/* audio manager */
static jclass mAudioManagerClass;
@@ -342,7 +349,10 @@ static SDL_DisplayOrientation displayOrientation;
static float fLastAccelerometer[3];
static SDL_bool bHasNewData;
-static SDL_bool bHasEnvironmentVariables = SDL_FALSE;
+static SDL_bool bHasEnvironmentVariables;
+
+static SDL_atomic_t bPermissionRequestPending;
+static SDL_bool bPermissionRequestResult;
/*******************************************************************************
Functions called by JNI
@@ -552,68 +562,65 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
mActivityClass = (jclass)((*env)->NewGlobalRef(env, cls));
- midGetNativeSurface = (*env)->GetStaticMethodID(env, mActivityClass,
- "getNativeSurface","()Landroid/view/Surface;");
- midSetSurfaceViewFormat = (*env)->GetStaticMethodID(env, mActivityClass,
- "setSurfaceViewFormat","(I)V");
- midSetActivityTitle = (*env)->GetStaticMethodID(env, mActivityClass,
- "setActivityTitle","(Ljava/lang/String;)Z");
- midSetWindowStyle = (*env)->GetStaticMethodID(env, mActivityClass,
- "setWindowStyle","(Z)V");
- midSetOrientation = (*env)->GetStaticMethodID(env, mActivityClass,
- "setOrientation","(IIZLjava/lang/String;)V");
- midMinimizeWindow = (*env)->GetStaticMethodID(env, mActivityClass,
- "minimizeWindow","()V");
- midShouldMinimizeOnFocusLoss = (*env)->GetStaticMethodID(env, mActivityClass,
- "shouldMinimizeOnFocusLoss","()Z");
- midGetContext = (*env)->GetStaticMethodID(env, mActivityClass,
- "getContext","()Landroid/content/Context;");
- midIsTablet = (*env)->GetStaticMethodID(env, mActivityClass,
- "isTablet", "()Z");
- midIsAndroidTV = (*env)->GetStaticMethodID(env, mActivityClass,
- "isAndroidTV","()Z");
- midIsChromebook = (*env)->GetStaticMethodID(env, mActivityClass,
- "isChromebook", "()Z");
- midIsDeXMode = (*env)->GetStaticMethodID(env, mActivityClass,
- "isDeXMode", "()Z");
- midManualBackButton = (*env)->GetStaticMethodID(env, mActivityClass,
- "manualBackButton", "()V");
- midInitTouch = (*env)->GetStaticMethodID(env, mActivityClass,
- "initTouch", "()V");
- midSendMessage = (*env)->GetStaticMethodID(env, mActivityClass,
- "sendMessage", "(II)Z");
- midShowTextInput = (*env)->GetStaticMethodID(env, mActivityClass,
- "showTextInput", "(IIII)Z");
- midIsScreenKeyboardShown = (*env)->GetStaticMethodID(env, mActivityClass,
- "isScreenKeyboardShown","()Z");
- midClipboardSetText = (*env)->GetStaticMethodID(env, mActivityClass,
- "clipboardSetText", "(Ljava/lang/String;)V");
- midClipboardGetText = (*env)->GetStaticMethodID(env, mActivityClass,
- "clipboardGetText", "()Ljava/lang/String;");
- midClipboardHasText = (*env)->GetStaticMethodID(env, mActivityClass,
- "clipboardHasText", "()Z");
- midOpenAPKExpansionInputStream = (*env)->GetStaticMethodID(env, mActivityClass,
- "openAPKExpansionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
-
- midGetManifestEnvironmentVariables = (*env)->GetStaticMethodID(env, mActivityClass,
- "getManifestEnvironmentVariables", "()Z");
-
- midGetDisplayDPI = (*env)->GetStaticMethodID(env, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;");
+ midClipboardGetText = (*env)->GetStaticMethodID(env, mActivityClass, "clipboardGetText", "()Ljava/lang/String;");
+ midClipboardHasText = (*env)->GetStaticMethodID(env, mActivityClass, "clipboardHasText", "()Z");
+ midClipboardSetText = (*env)->GetStaticMethodID(env, mActivityClass, "clipboardSetText", "(Ljava/lang/String;)V");
midCreateCustomCursor = (*env)->GetStaticMethodID(env, mActivityClass, "createCustomCursor", "([IIIII)I");
+ midGetContext = (*env)->GetStaticMethodID(env, mActivityClass, "getContext","()Landroid/content/Context;");
+ midGetDisplayDPI = (*env)->GetStaticMethodID(env, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;");
+ midGetManifestEnvironmentVariables = (*env)->GetStaticMethodID(env, mActivityClass, "getManifestEnvironmentVariables", "()Z");
+ midGetNativeSurface = (*env)->GetStaticMethodID(env, mActivityClass, "getNativeSurface","()Landroid/view/Surface;");
+ midInitTouch = (*env)->GetStaticMethodID(env, mActivityClass, "initTouch", "()V");
+ midIsAndroidTV = (*env)->GetStaticMethodID(env, mActivityClass, "isAndroidTV","()Z");
+ midIsChromebook = (*env)->GetStaticMethodID(env, mActivityClass, "isChromebook", "()Z");
+ midIsDeXMode = (*env)->GetStaticMethodID(env, mActivityClass, "isDeXMode", "()Z");
+ midIsScreenKeyboardShown = (*env)->GetStaticMethodID(env, mActivityClass, "isScreenKeyboardShown","()Z");
+ midIsTablet = (*env)->GetStaticMethodID(env, mActivityClass, "isTablet", "()Z");
+ midManualBackButton = (*env)->GetStaticMethodID(env, mActivityClass, "manualBackButton", "()V");
+ midMinimizeWindow = (*env)->GetStaticMethodID(env, mActivityClass, "minimizeWindow","()V");
+ midOpenAPKExpansionInputStream = (*env)->GetStaticMethodID(env, mActivityClass, "openAPKExpansionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
+ midRequestPermission = (*env)->GetStaticMethodID(env, mActivityClass, "requestPermission", "(Ljava/lang/String;I)V");
+ midSendMessage = (*env)->GetStaticMethodID(env, mActivityClass, "sendMessage", "(II)Z");
+ midSetActivityTitle = (*env)->GetStaticMethodID(env, mActivityClass, "setActivityTitle","(Ljava/lang/String;)Z");
midSetCustomCursor = (*env)->GetStaticMethodID(env, mActivityClass, "setCustomCursor", "(I)Z");
+ midSetOrientation = (*env)->GetStaticMethodID(env, mActivityClass, "setOrientation","(IIZLjava/lang/String;)V");
+ midSetRelativeMouseEnabled = (*env)->GetStaticMethodID(env, mActivityClass, "setRelativeMouseEnabled", "(Z)Z");
+ midSetSurfaceViewFormat = (*env)->GetStaticMethodID(env, mActivityClass, "setSurfaceViewFormat","(I)V");
midSetSystemCursor = (*env)->GetStaticMethodID(env, mActivityClass, "setSystemCursor", "(I)Z");
-
+ midSetWindowStyle = (*env)->GetStaticMethodID(env, mActivityClass, "setWindowStyle","(Z)V");
+ midShouldMinimizeOnFocusLoss = (*env)->GetStaticMethodID(env, mActivityClass, "shouldMinimizeOnFocusLoss","()Z");
+ midShowTextInput = (*env)->GetStaticMethodID(env, mActivityClass, "showTextInput", "(IIII)Z");
midSupportsRelativeMouse = (*env)->GetStaticMethodID(env, mActivityClass, "supportsRelativeMouse", "()Z");
- midSetRelativeMouseEnabled = (*env)->GetStaticMethodID(env, mActivityClass, "setRelativeMouseEnabled", "(Z)Z");
-
- if (!midGetNativeSurface || !midSetSurfaceViewFormat ||
- !midSetActivityTitle || !midSetWindowStyle || !midSetOrientation || !midMinimizeWindow || !midShouldMinimizeOnFocusLoss || !midGetContext || !midIsTablet || !midIsAndroidTV || !midInitTouch ||
- !midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown ||
- !midClipboardSetText || !midClipboardGetText || !midClipboardHasText ||
- !midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariables || !midGetDisplayDPI ||
- !midCreateCustomCursor || !midSetCustomCursor || !midSetSystemCursor || !midSupportsRelativeMouse || !midSetRelativeMouseEnabled ||
- !midIsChromebook || !midIsDeXMode || !midManualBackButton) {
+ if (!midClipboardGetText ||
+ !midClipboardHasText ||
+ !midClipboardSetText ||
+ !midCreateCustomCursor ||
+ !midGetContext ||
+ !midGetDisplayDPI ||
+ !midGetManifestEnvironmentVariables ||
+ !midGetNativeSurface ||
+ !midInitTouch ||
+ !midIsAndroidTV ||
+ !midIsChromebook ||
+ !midIsDeXMode ||
+ !midIsScreenKeyboardShown ||
+ !midIsTablet ||
+ !midManualBackButton ||
+ !midMinimizeWindow ||
+ !midOpenAPKExpansionInputStream ||
+ !midRequestPermission ||
+ !midSendMessage ||
+ !midSetActivityTitle ||
+ !midSetCustomCursor ||
+ !midSetOrientation ||
+ !midSetRelativeMouseEnabled ||
+ !midSetSurfaceViewFormat ||
+ !midSetSystemCursor ||
+ !midSetWindowStyle ||
+ !midShouldMinimizeOnFocusLoss ||
+ !midShowTextInput ||
+ !midSupportsRelativeMouse) {
__android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?");
}
@@ -875,6 +882,14 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeAddTouch)(
(*env)->ReleaseStringUTFChars(env, name, utfname);
}
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePermissionResult)(
+ JNIEnv* env, jclass cls,
+ jint requestCode, jboolean result)
+{
+ bPermissionRequestResult = result;
+ SDL_AtomicSet(&bPermissionRequestPending, SDL_FALSE);
+}
+
/* Paddown */
JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadDown)(
JNIEnv *env, jclass jcls,
@@ -2759,6 +2774,27 @@ SDL_bool Android_JNI_SetRelativeMouseEnabled(SDL_bool enabled)
return (*env)->CallStaticBooleanMethod(env, mActivityClass, midSetRelativeMouseEnabled, (enabled == 1));
}
+SDL_bool Android_JNI_RequestPermission(const char *permission)
+{
+ JNIEnv *env = Android_JNI_GetEnv();
+ const int requestCode = 1;
+
+ /* Wait for any pending request on another thread */
+ while (SDL_AtomicGet(&bPermissionRequestPending) == SDL_TRUE) {
+ SDL_Delay(10);
+ }
+ SDL_AtomicSet(&bPermissionRequestPending, SDL_TRUE);
+
+ jstring jpermission = (*env)->NewStringUTF(env, permission);
+ (*env)->CallStaticVoidMethod(env, mActivityClass, midRequestPermission, jpermission, requestCode);
+ (*env)->DeleteLocalRef(env, jpermission);
+
+ /* Wait for the request to complete */
+ while (SDL_AtomicGet(&bPermissionRequestPending) == SDL_TRUE) {
+ SDL_Delay(10);
+ }
+ return bPermissionRequestResult;
+}
#endif /* __ANDROID__ */