Fixed bug 3917 - Android, issues with getManifestEnvironmentVariable Sylvain What about getting some return code instead of creating another native function.
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
diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
index be8aecc..a6f6e4e 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
@@ -513,7 +513,6 @@ public class SDLActivity extends Activity {
public static native void onNativeSurfaceDestroyed();
public static native String nativeGetHint(String name);
public static native void nativeSetenv(String name, String value);
- public static native void nativeEnvironmentVariablesSet();
/**
* This method is called by SDL using JNI.
@@ -618,12 +617,12 @@ public class SDLActivity extends Activity {
/**
* This method is called by SDL using JNI.
*/
- public static void getManifestEnvironmentVariables() {
+ public static boolean getManifestEnvironmentVariables() {
try {
ApplicationInfo applicationInfo = getContext().getPackageManager().getApplicationInfo(getContext().getPackageName(), PackageManager.GET_META_DATA);
Bundle bundle = applicationInfo.metaData;
if (bundle == null) {
- return;
+ return false;
}
String prefix = "SDL_ENV.";
final int trimLength = prefix.length();
@@ -634,10 +633,12 @@ public class SDLActivity extends Activity {
nativeSetenv(name, value);
}
}
- nativeEnvironmentVariablesSet();
+ /* environment variables set! */
+ return true;
} catch (Exception e) {
Log.v("SDL", "exception " + e.toString());
}
+ return false;
}
static class ShowTextInputTask implements Runnable {
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index 28f9a19..02afdf1 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -251,7 +251,7 @@ static jfieldID fidSeparateMouseAndTouch;
static float fLastAccelerometer[3];
static SDL_bool bHasNewData;
-static SDL_bool bHasEnvironmentVariables;
+static SDL_bool bHasEnvironmentVariables = SDL_FALSE;
/*******************************************************************************
Functions called by JNI
@@ -324,7 +324,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass c
"openAPKExpansionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
midGetManifestEnvironmentVariables = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
- "getManifestEnvironmentVariables", "()V");
+ "getManifestEnvironmentVariables", "()Z");
midGetDisplayDPI = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;");
@@ -831,12 +831,6 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetenv)(
}
-JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeEnvironmentVariablesSet)(
- JNIEnv* env, jclass cls)
-{
- bHasEnvironmentVariables = SDL_TRUE;
-}
-
/*******************************************************************************
Functions called by SDL into Java
*******************************************************************************/
@@ -2143,7 +2137,10 @@ void Android_JNI_GetManifestEnvironmentVariables(void)
if (!bHasEnvironmentVariables) {
JNIEnv *env = Android_JNI_GetEnv();
- (*env)->CallStaticVoidMethod(env, mActivityClass, midGetManifestEnvironmentVariables);
+ SDL_bool ret = (*env)->CallStaticBooleanMethod(env, mActivityClass, midGetManifestEnvironmentVariables);
+ if (ret) {
+ bHasEnvironmentVariables = SDL_TRUE;
+ }
}
}