src/core/android/SDL_android.c
changeset 11653 4130b92b6be4
parent 11531 84793b17a0d2
child 11655 ccf47d584003
     1.1 --- a/src/core/android/SDL_android.c	Tue Oct 24 00:04:40 2017 -0700
     1.2 +++ b/src/core/android/SDL_android.c	Tue Oct 24 00:17:07 2017 -0700
     1.3 @@ -211,6 +211,7 @@
     1.4  static jmethodID midClipboardGetText;
     1.5  static jmethodID midClipboardHasText;
     1.6  static jmethodID midOpenAPKExpansionInputStream;
     1.7 +static jmethodID midGetManifestEnvironmentVariable;
     1.8  
     1.9  /* audio manager */
    1.10  static jclass mAudioManagerClass;
    1.11 @@ -310,11 +311,14 @@
    1.12      midOpenAPKExpansionInputStream = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.13                                  "openAPKExpansionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
    1.14  
    1.15 +    midGetManifestEnvironmentVariable = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.16 +                                "getManifestEnvironmentVariable", "(Ljava/lang/String;)Ljava/lang/String;");
    1.17 +
    1.18      if (!midGetNativeSurface ||
    1.19         !midSetActivityTitle || !midSetOrientation || !midGetContext || !midInputGetInputDeviceIds ||
    1.20         !midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown || 
    1.21         !midClipboardSetText || !midClipboardGetText || !midClipboardHasText ||
    1.22 -       !midOpenAPKExpansionInputStream) {
    1.23 +       !midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariable) {
    1.24          __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?");
    1.25      }
    1.26  
    1.27 @@ -2034,6 +2038,41 @@
    1.28      return s_AndroidExternalFilesPath;
    1.29  }
    1.30  
    1.31 +// Ugh, but we have to SDL_strdup() our result to pass it safely back
    1.32 +// out into normal SDL_getenv flow.  So we'll just do the same sort
    1.33 +// of trick as on Win32 over in SDL_getenv.c.
    1.34 +char *SDL_AndroidEnvMem;
    1.35 +
    1.36 +char *SDL_AndroidGetManifestEnvironmentVariable(const char *variableName)
    1.37 +{
    1.38 +    if ((mActivityClass == NULL) || (midGetManifestEnvironmentVariable == 0)) {
    1.39 +        __android_log_print(ANDROID_LOG_WARN, "SDL", "request to get environment variable before JNI is ready: %s", variableName);
    1.40 +        return NULL;
    1.41 +    }
    1.42 +
    1.43 +    JNIEnv *env = Android_JNI_GetEnv();
    1.44 +
    1.45 +    jstring jVariableName = (*env)->NewStringUTF(env, variableName);
    1.46 +    jstring jResult = (jstring)((*env)->CallStaticObjectMethod(env, mActivityClass, midGetManifestEnvironmentVariable, jVariableName));
    1.47 +
    1.48 +    if (jResult == NULL) {
    1.49 +        return NULL;        
    1.50 +    }
    1.51 +
    1.52 +    if (SDL_AndroidEnvMem) {
    1.53 +        SDL_free(SDL_AndroidEnvMem);
    1.54 +        SDL_AndroidEnvMem = NULL;
    1.55 +    }
    1.56 +
    1.57 +    const char *result = (*env)->GetStringUTFChars(env, jResult, NULL);
    1.58 +    SDL_AndroidEnvMem = SDL_strdup(result);
    1.59 +    (*env)->ReleaseStringUTFChars(env, jResult, result);
    1.60 +    (*env)->DeleteLocalRef(env, jResult);
    1.61 +
    1.62 +    __android_log_print(ANDROID_LOG_INFO, "SDL", "environment variable in metadata: %s = %s", variableName, SDL_AndroidEnvMem);
    1.63 +    return SDL_AndroidEnvMem;
    1.64 +}
    1.65 +
    1.66  #endif /* __ANDROID__ */
    1.67  
    1.68  /* vi: set ts=4 sw=4 expandtab: */