Fixed bug 3917 - Android, issues with getManifestEnvironmentVariable
authorSam Lantinga <slouken@libsdl.org>
Sat, 04 Nov 2017 22:03:28 -0700
changeset 11688e4d90d54cb01
parent 11687 e968d755a760
child 11689 64ec7aae69e3
Fixed bug 3917 - Android, issues with getManifestEnvironmentVariable

Sylvain

What about getting some return code instead of creating another native function.
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
src/core/android/SDL_android.c
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Sat Nov 04 21:58:48 2017 -0700
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Sat Nov 04 22:03:28 2017 -0700
     1.3 @@ -513,7 +513,6 @@
     1.4      public static native void onNativeSurfaceDestroyed();
     1.5      public static native String nativeGetHint(String name);
     1.6      public static native void nativeSetenv(String name, String value);
     1.7 -    public static native void nativeEnvironmentVariablesSet();
     1.8  
     1.9      /**
    1.10       * This method is called by SDL using JNI.
    1.11 @@ -618,12 +617,12 @@
    1.12      /**
    1.13       * This method is called by SDL using JNI.
    1.14       */
    1.15 -    public static void getManifestEnvironmentVariables() {
    1.16 +    public static boolean getManifestEnvironmentVariables() {
    1.17          try {
    1.18              ApplicationInfo applicationInfo = getContext().getPackageManager().getApplicationInfo(getContext().getPackageName(), PackageManager.GET_META_DATA);
    1.19              Bundle bundle = applicationInfo.metaData;
    1.20              if (bundle == null) {
    1.21 -                return;
    1.22 +                return false;
    1.23              }
    1.24  			String prefix = "SDL_ENV.";
    1.25              final int trimLength = prefix.length();
    1.26 @@ -634,10 +633,12 @@
    1.27                      nativeSetenv(name, value);
    1.28                  }
    1.29              }
    1.30 -			nativeEnvironmentVariablesSet();
    1.31 +            /* environment variables set! */
    1.32 +            return true; 
    1.33          } catch (Exception e) {
    1.34             Log.v("SDL", "exception " + e.toString());
    1.35          }
    1.36 +        return false;
    1.37      }
    1.38  
    1.39      static class ShowTextInputTask implements Runnable {
     2.1 --- a/src/core/android/SDL_android.c	Sat Nov 04 21:58:48 2017 -0700
     2.2 +++ b/src/core/android/SDL_android.c	Sat Nov 04 22:03:28 2017 -0700
     2.3 @@ -251,7 +251,7 @@
     2.4  static float fLastAccelerometer[3];
     2.5  static SDL_bool bHasNewData;
     2.6  
     2.7 -static SDL_bool bHasEnvironmentVariables;
     2.8 +static SDL_bool bHasEnvironmentVariables = SDL_FALSE;
     2.9  
    2.10  /*******************************************************************************
    2.11                   Functions called by JNI
    2.12 @@ -324,7 +324,7 @@
    2.13                                  "openAPKExpansionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
    2.14  
    2.15      midGetManifestEnvironmentVariables = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    2.16 -                                "getManifestEnvironmentVariables", "()V");
    2.17 +                                "getManifestEnvironmentVariables", "()Z");
    2.18  
    2.19      midGetDisplayDPI = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;");
    2.20  
    2.21 @@ -831,12 +831,6 @@
    2.22  
    2.23  }
    2.24  
    2.25 -JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeEnvironmentVariablesSet)(
    2.26 -        JNIEnv* env, jclass cls)
    2.27 -{
    2.28 -    bHasEnvironmentVariables = SDL_TRUE;
    2.29 -}
    2.30 -
    2.31  /*******************************************************************************
    2.32               Functions called by SDL into Java
    2.33  *******************************************************************************/
    2.34 @@ -2143,7 +2137,10 @@
    2.35  
    2.36      if (!bHasEnvironmentVariables) {
    2.37          JNIEnv *env = Android_JNI_GetEnv();
    2.38 -        (*env)->CallStaticVoidMethod(env, mActivityClass, midGetManifestEnvironmentVariables);
    2.39 +        SDL_bool ret = (*env)->CallStaticBooleanMethod(env, mActivityClass, midGetManifestEnvironmentVariables);
    2.40 +        if (ret) {
    2.41 +            bHasEnvironmentVariables = SDL_TRUE;
    2.42 +        }
    2.43      }
    2.44  }
    2.45