src/core/android/SDL_android.c
changeset 11653 4130b92b6be4
parent 11531 84793b17a0d2
child 11655 ccf47d584003
equal deleted inserted replaced
11652:c3bf2954de06 11653:4130b92b6be4
   209 static jmethodID midIsScreenKeyboardShown;
   209 static jmethodID midIsScreenKeyboardShown;
   210 static jmethodID midClipboardSetText;
   210 static jmethodID midClipboardSetText;
   211 static jmethodID midClipboardGetText;
   211 static jmethodID midClipboardGetText;
   212 static jmethodID midClipboardHasText;
   212 static jmethodID midClipboardHasText;
   213 static jmethodID midOpenAPKExpansionInputStream;
   213 static jmethodID midOpenAPKExpansionInputStream;
       
   214 static jmethodID midGetManifestEnvironmentVariable;
   214 
   215 
   215 /* audio manager */
   216 /* audio manager */
   216 static jclass mAudioManagerClass;
   217 static jclass mAudioManagerClass;
   217 
   218 
   218 /* method signatures */
   219 /* method signatures */
   308     midClipboardHasText = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
   309     midClipboardHasText = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
   309                                 "clipboardHasText", "()Z");
   310                                 "clipboardHasText", "()Z");
   310     midOpenAPKExpansionInputStream = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
   311     midOpenAPKExpansionInputStream = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
   311                                 "openAPKExpansionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
   312                                 "openAPKExpansionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
   312 
   313 
       
   314     midGetManifestEnvironmentVariable = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
       
   315                                 "getManifestEnvironmentVariable", "(Ljava/lang/String;)Ljava/lang/String;");
       
   316 
   313     if (!midGetNativeSurface ||
   317     if (!midGetNativeSurface ||
   314        !midSetActivityTitle || !midSetOrientation || !midGetContext || !midInputGetInputDeviceIds ||
   318        !midSetActivityTitle || !midSetOrientation || !midGetContext || !midInputGetInputDeviceIds ||
   315        !midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown || 
   319        !midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown || 
   316        !midClipboardSetText || !midClipboardGetText || !midClipboardHasText ||
   320        !midClipboardSetText || !midClipboardGetText || !midClipboardHasText ||
   317        !midOpenAPKExpansionInputStream) {
   321        !midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariable) {
   318         __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?");
   322         __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?");
   319     }
   323     }
   320 
   324 
   321     fidSeparateMouseAndTouch = (*mEnv)->GetStaticFieldID(mEnv, mActivityClass, "mSeparateMouseAndTouch", "Z");
   325     fidSeparateMouseAndTouch = (*mEnv)->GetStaticFieldID(mEnv, mActivityClass, "mSeparateMouseAndTouch", "Z");
   322 
   326 
  2032         LocalReferenceHolder_Cleanup(&refs);
  2036         LocalReferenceHolder_Cleanup(&refs);
  2033     }
  2037     }
  2034     return s_AndroidExternalFilesPath;
  2038     return s_AndroidExternalFilesPath;
  2035 }
  2039 }
  2036 
  2040 
       
  2041 // Ugh, but we have to SDL_strdup() our result to pass it safely back
       
  2042 // out into normal SDL_getenv flow.  So we'll just do the same sort
       
  2043 // of trick as on Win32 over in SDL_getenv.c.
       
  2044 char *SDL_AndroidEnvMem;
       
  2045 
       
  2046 char *SDL_AndroidGetManifestEnvironmentVariable(const char *variableName)
       
  2047 {
       
  2048     if ((mActivityClass == NULL) || (midGetManifestEnvironmentVariable == 0)) {
       
  2049         __android_log_print(ANDROID_LOG_WARN, "SDL", "request to get environment variable before JNI is ready: %s", variableName);
       
  2050         return NULL;
       
  2051     }
       
  2052 
       
  2053     JNIEnv *env = Android_JNI_GetEnv();
       
  2054 
       
  2055     jstring jVariableName = (*env)->NewStringUTF(env, variableName);
       
  2056     jstring jResult = (jstring)((*env)->CallStaticObjectMethod(env, mActivityClass, midGetManifestEnvironmentVariable, jVariableName));
       
  2057 
       
  2058     if (jResult == NULL) {
       
  2059         return NULL;        
       
  2060     }
       
  2061 
       
  2062     if (SDL_AndroidEnvMem) {
       
  2063         SDL_free(SDL_AndroidEnvMem);
       
  2064         SDL_AndroidEnvMem = NULL;
       
  2065     }
       
  2066 
       
  2067     const char *result = (*env)->GetStringUTFChars(env, jResult, NULL);
       
  2068     SDL_AndroidEnvMem = SDL_strdup(result);
       
  2069     (*env)->ReleaseStringUTFChars(env, jResult, result);
       
  2070     (*env)->DeleteLocalRef(env, jResult);
       
  2071 
       
  2072     __android_log_print(ANDROID_LOG_INFO, "SDL", "environment variable in metadata: %s = %s", variableName, SDL_AndroidEnvMem);
       
  2073     return SDL_AndroidEnvMem;
       
  2074 }
       
  2075 
  2037 #endif /* __ANDROID__ */
  2076 #endif /* __ANDROID__ */
  2038 
  2077 
  2039 /* vi: set ts=4 sw=4 expandtab: */
  2078 /* vi: set ts=4 sw=4 expandtab: */