src/core/android/SDL_android.c
changeset 11292 df399ea01ee5
parent 11271 ab3f2402a777
child 11355 6185fb86f046
     1.1 --- a/src/core/android/SDL_android.c	Mon Aug 14 14:10:48 2017 -0700
     1.2 +++ b/src/core/android/SDL_android.c	Mon Aug 14 14:14:45 2017 -0700
     1.3 @@ -84,7 +84,7 @@
     1.4  
     1.5  JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeAddJoystick)(
     1.6          JNIEnv* env, jclass jcls,
     1.7 -        jint device_id, jstring device_name, jint is_accelerometer, 
     1.8 +        jint device_id, jstring device_name, jint is_accelerometer,
     1.9          jint nbuttons, jint naxes, jint nhats, jint nballs);
    1.10  
    1.11  JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeRemoveJoystick)(
    1.12 @@ -180,6 +180,14 @@
    1.13  static jmethodID midPollInputDevices;
    1.14  static jmethodID midPollHapticDevices;
    1.15  static jmethodID midHapticRun;
    1.16 +static jmethodID midSetActivityTitle;
    1.17 +static jmethodID midSetOrientation;
    1.18 +static jmethodID midGetContext;
    1.19 +static jmethodID midInputGetInputDeviceIds;
    1.20 +static jmethodID midSendMessage;
    1.21 +static jmethodID midShowTextInput;
    1.22 +static jmethodID midIsScreenKeyboardShown;
    1.23 +static jmethodID midGetSystemServiceFromUiThread;
    1.24  
    1.25  /* static fields */
    1.26  static jfieldID fidSeparateMouseAndTouch;
    1.27 @@ -247,18 +255,36 @@
    1.28                                  "pollHapticDevices", "()V");
    1.29      midHapticRun = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.30                                  "hapticRun", "(II)V");
    1.31 +    midSetActivityTitle = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.32 +                                "setActivityTitle","(Ljava/lang/String;)Z");
    1.33 +    midSetOrientation = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.34 +                                "setOrientation","(IIZLjava/lang/String;)V");
    1.35 +    midGetContext = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.36 +                                "getContext","()Landroid/content/Context;");
    1.37 +    midInputGetInputDeviceIds = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.38 +                                "inputGetInputDeviceIds", "(I)[I");
    1.39 +    midSendMessage = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.40 +                                "sendMessage", "(II)Z");
    1.41 +    midShowTextInput =  (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.42 +                                "showTextInput", "(IIII)Z");
    1.43 +    midIsScreenKeyboardShown = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
    1.44 +                                "isScreenKeyboardShown","()Z");
    1.45 +    midGetSystemServiceFromUiThread = (*mEnv)->GetMethodID(mEnv, mActivityClass,
    1.46 +                                "getSystemServiceFromUiThread", "(Ljava/lang/String;)Ljava/lang/Object;");
    1.47  
    1.48      bHasNewData = SDL_FALSE;
    1.49  
    1.50      if (!midGetNativeSurface ||
    1.51         !midAudioOpen || !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioClose ||
    1.52         !midCaptureOpen || !midCaptureReadShortBuffer || !midCaptureReadByteBuffer || !midCaptureClose ||
    1.53 -       !midPollInputDevices || !midPollHapticDevices || !midHapticRun) {
    1.54 +       !midPollInputDevices || !midPollHapticDevices || !midHapticRun ||
    1.55 +       !midSetActivityTitle || !midSetOrientation || !midGetContext || !midInputGetInputDeviceIds ||
    1.56 +       !midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown || !midGetSystemServiceFromUiThread) {
    1.57          __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly");
    1.58      }
    1.59  
    1.60      fidSeparateMouseAndTouch = (*mEnv)->GetStaticFieldID(mEnv, mActivityClass, "mSeparateMouseAndTouch", "Z");
    1.61 -    
    1.62 +
    1.63      if (!fidSeparateMouseAndTouch) {
    1.64          __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java static fields, check that they're named and typed correctly");
    1.65      }
    1.66 @@ -320,7 +346,7 @@
    1.67  
    1.68  JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeAddJoystick)(
    1.69                                      JNIEnv* env, jclass jcls,
    1.70 -                                    jint device_id, jstring device_name, jint is_accelerometer, 
    1.71 +                                    jint device_id, jstring device_name, jint is_accelerometer,
    1.72                                      jint nbuttons, jint naxes, jint nhats, jint nballs)
    1.73  {
    1.74      int retval;
    1.75 @@ -329,7 +355,7 @@
    1.76      retval = Android_AddJoystick(device_id, name, (SDL_bool) is_accelerometer, nbuttons, naxes, nhats, nballs);
    1.77  
    1.78      (*env)->ReleaseStringUTFChars(env, device_name, name);
    1.79 -    
    1.80 +
    1.81      return retval;
    1.82  }
    1.83  
    1.84 @@ -369,10 +395,10 @@
    1.85      if (Android_Window == NULL || Android_Window->driverdata == NULL ) {
    1.86          return;
    1.87      }
    1.88 -    
    1.89 +
    1.90      _this =  SDL_GetVideoDevice();
    1.91      data =  (SDL_WindowData *) Android_Window->driverdata;
    1.92 -    
    1.93 +
    1.94      /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
    1.95      if (data->egl_surface == EGL_NO_SURFACE) {
    1.96          if(data->native_window) {
    1.97 @@ -381,9 +407,9 @@
    1.98          data->native_window = Android_JNI_GetNativeWindow();
    1.99          data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
   1.100      }
   1.101 -    
   1.102 +
   1.103      /* GL Context handling is done in the event loop because this function is run from the Java thread */
   1.104 -    
   1.105 +
   1.106  }
   1.107  
   1.108  /* Surface Destroyed */
   1.109 @@ -395,20 +421,20 @@
   1.110       */
   1.111      SDL_WindowData *data;
   1.112      SDL_VideoDevice *_this;
   1.113 -    
   1.114 +
   1.115      if (Android_Window == NULL || Android_Window->driverdata == NULL ) {
   1.116          return;
   1.117      }
   1.118 -    
   1.119 +
   1.120      _this =  SDL_GetVideoDevice();
   1.121      data = (SDL_WindowData *) Android_Window->driverdata;
   1.122 -    
   1.123 +
   1.124      if (data->egl_surface != EGL_NO_SURFACE) {
   1.125          SDL_EGL_MakeCurrent(_this, NULL, NULL);
   1.126          SDL_EGL_DestroySurface(_this, data->egl_surface);
   1.127          data->egl_surface = EGL_NO_SURFACE;
   1.128      }
   1.129 -    
   1.130 +
   1.131      /* GL Context handling is done in the event loop because this function is run from the Java thread */
   1.132  
   1.133  }
   1.134 @@ -499,8 +525,8 @@
   1.135          SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
   1.136          SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
   1.137          SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
   1.138 -    
   1.139 -        /* *After* sending the relevant events, signal the pause semaphore 
   1.140 +
   1.141 +        /* *After* sending the relevant events, signal the pause semaphore
   1.142           * so the event loop knows to pause and (optionally) block itself */
   1.143          if (!SDL_SemValue(Android_PauseSem)) SDL_SemPost(Android_PauseSem);
   1.144      }
   1.145 @@ -620,32 +646,26 @@
   1.146      s = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetNativeSurface);
   1.147      anw = ANativeWindow_fromSurface(env, s);
   1.148      (*env)->DeleteLocalRef(env, s);
   1.149 -  
   1.150 +
   1.151      return anw;
   1.152  }
   1.153  
   1.154  void Android_JNI_SetActivityTitle(const char *title)
   1.155  {
   1.156 -    jmethodID mid;
   1.157      JNIEnv *mEnv = Android_JNI_GetEnv();
   1.158 -    mid = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,"setActivityTitle","(Ljava/lang/String;)Z");
   1.159 -    if (mid) {
   1.160 -        jstring jtitle = (jstring)((*mEnv)->NewStringUTF(mEnv, title));
   1.161 -        (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, mid, jtitle);
   1.162 -        (*mEnv)->DeleteLocalRef(mEnv, jtitle);
   1.163 -    }
   1.164 +
   1.165 +    jstring jtitle = (jstring)((*mEnv)->NewStringUTF(mEnv, title));
   1.166 +    (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, midSetActivityTitle, jtitle);
   1.167 +    (*mEnv)->DeleteLocalRef(mEnv, jtitle);
   1.168  }
   1.169  
   1.170  void Android_JNI_SetOrientation(int w, int h, int resizable, const char *hint)
   1.171  {
   1.172 -    jmethodID mid;
   1.173      JNIEnv *mEnv = Android_JNI_GetEnv();
   1.174 -    mid = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,"setOrientation","(IIZLjava/lang/String;)V");
   1.175 -    if (mid) {
   1.176 -        jstring jhint = (jstring)((*mEnv)->NewStringUTF(mEnv, (hint ? hint : "")));
   1.177 -        (*mEnv)->CallStaticVoidMethod(mEnv, mActivityClass, mid, w, h, (resizable? 1 : 0), jhint);
   1.178 -        (*mEnv)->DeleteLocalRef(mEnv, jhint);
   1.179 -    }
   1.180 +
   1.181 +    jstring jhint = (jstring)((*mEnv)->NewStringUTF(mEnv, (hint ? hint : "")));
   1.182 +    (*mEnv)->CallStaticVoidMethod(mEnv, mActivityClass, midSetOrientation, w, h, (resizable? 1 : 0), jhint);
   1.183 +    (*mEnv)->DeleteLocalRef(mEnv, jhint);
   1.184  }
   1.185  
   1.186  SDL_bool Android_JNI_GetAccelerometerValues(float values[3])
   1.187 @@ -859,7 +879,7 @@
   1.188  void Android_JNI_FlushCapturedAudio(void)
   1.189  {
   1.190      JNIEnv *env = Android_JNI_GetEnv();
   1.191 -    #if 0  /* !!! FIXME: this needs API 23, or it'll do blocking reads and never end. */
   1.192 +#if 0  /* !!! FIXME: this needs API 23, or it'll do blocking reads and never end. */
   1.193      if (captureBuffer16Bit) {
   1.194          const jint len = (*env)->GetArrayLength(env, (jshortArray)captureBuffer);
   1.195          while ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_FALSE) == len) { /* spin */ }
   1.196 @@ -867,13 +887,13 @@
   1.197          const jint len = (*env)->GetArrayLength(env, (jbyteArray)captureBuffer);
   1.198          while ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_FALSE) == len) { /* spin */ }
   1.199      }
   1.200 -    #else
   1.201 +#else
   1.202      if (captureBuffer16Bit) {
   1.203          (*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_FALSE);
   1.204      } else {
   1.205          (*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_FALSE);
   1.206      }
   1.207 -    #endif
   1.208 +#endif
   1.209  }
   1.210  
   1.211  void Android_JNI_CloseAudioDevice(const int iscapture)
   1.212 @@ -969,10 +989,7 @@
   1.213      ctx->hidden.androidio.position = 0;
   1.214  
   1.215      /* context = SDLActivity.getContext(); */
   1.216 -    mid = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
   1.217 -            "getContext","()Landroid/content/Context;");
   1.218 -    context = (*mEnv)->CallStaticObjectMethod(mEnv, mActivityClass, mid);
   1.219 -
   1.220 +    context = (*mEnv)->CallStaticObjectMethod(mEnv, mActivityClass, midGetContext);
   1.221  
   1.222      /* assetManager = context.getAssets(); */
   1.223      mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, context),
   1.224 @@ -1048,7 +1065,7 @@
   1.225           * android/apis/content/ReadAsset.java imply that Android's
   1.226           * AssetInputStream.available() /will/ always return the total file size
   1.227          */
   1.228 -        
   1.229 +
   1.230          /* size = inputStream.available(); */
   1.231          mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream),
   1.232                  "available", "()I");
   1.233 @@ -1096,7 +1113,7 @@
   1.234          }
   1.235  
   1.236      }
   1.237 -    
   1.238 +
   1.239      LocalReferenceHolder_Cleanup(&refs);
   1.240      return result;
   1.241  }
   1.242 @@ -1110,7 +1127,7 @@
   1.243      jstring fileNameJString;
   1.244  
   1.245      if (!LocalReferenceHolder_Init(&refs, mEnv)) {
   1.246 -        LocalReferenceHolder_Cleanup(&refs);        
   1.247 +        LocalReferenceHolder_Cleanup(&refs);
   1.248          return -1;
   1.249      }
   1.250  
   1.251 @@ -1164,7 +1181,7 @@
   1.252  
   1.253          mEnv = Android_JNI_GetEnv();
   1.254          if (!LocalReferenceHolder_Init(&refs, mEnv)) {
   1.255 -            LocalReferenceHolder_Cleanup(&refs);            
   1.256 +            LocalReferenceHolder_Cleanup(&refs);
   1.257              return 0;
   1.258          }
   1.259  
   1.260 @@ -1177,7 +1194,7 @@
   1.261              int result = (*mEnv)->CallIntMethod(mEnv, readableByteChannel, readMethod, byteBuffer);
   1.262  
   1.263              if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
   1.264 -                LocalReferenceHolder_Cleanup(&refs);            
   1.265 +                LocalReferenceHolder_Cleanup(&refs);
   1.266                  return 0;
   1.267              }
   1.268  
   1.269 @@ -1189,7 +1206,7 @@
   1.270              bytesRead += result;
   1.271              ctx->hidden.androidio.position += result;
   1.272          }
   1.273 -        LocalReferenceHolder_Cleanup(&refs);                    
   1.274 +        LocalReferenceHolder_Cleanup(&refs);
   1.275          return bytesRead / size;
   1.276      }
   1.277  }
   1.278 @@ -1353,7 +1370,6 @@
   1.279      JNIEnv* env = Android_JNI_GetEnv();
   1.280      jobject retval = NULL;
   1.281      jstring service;
   1.282 -    jmethodID mid;
   1.283      jobject context;
   1.284      jobject manager;
   1.285  
   1.286 @@ -1364,11 +1380,10 @@
   1.287  
   1.288      service = (*env)->NewStringUTF(env, name);
   1.289  
   1.290 -    mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext", "()Landroid/content/Context;");
   1.291 -    context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
   1.292 +    /* context = SDLActivity.getContext(); */
   1.293 +    context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
   1.294  
   1.295 -    mid = (*env)->GetMethodID(env, mActivityClass, "getSystemServiceFromUiThread", "(Ljava/lang/String;)Ljava/lang/Object;");
   1.296 -    manager = (*env)->CallObjectMethod(env, context, mid, service);
   1.297 +    manager = (*env)->CallObjectMethod(env, context, midGetSystemServiceFromUiThread, service);
   1.298  
   1.299      (*env)->DeleteLocalRef(env, service);
   1.300  
   1.301 @@ -1438,7 +1453,7 @@
   1.302              }
   1.303          }
   1.304      }
   1.305 -    CLEANUP_CLIPBOARD();    
   1.306 +    CLEANUP_CLIPBOARD();
   1.307  
   1.308      return SDL_strdup("");
   1.309  }
   1.310 @@ -1455,7 +1470,7 @@
   1.311      (*env)->DeleteGlobalRef(env, clipboard);
   1.312  
   1.313      CLEANUP_CLIPBOARD();
   1.314 -    
   1.315 +
   1.316      return has ? SDL_TRUE : SDL_FALSE;
   1.317  }
   1.318  
   1.319 @@ -1484,8 +1499,8 @@
   1.320      }
   1.321  
   1.322  
   1.323 -    mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext", "()Landroid/content/Context;");
   1.324 -    context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
   1.325 +    /* context = SDLActivity.getContext(); */
   1.326 +    context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
   1.327  
   1.328      action = (*env)->NewStringUTF(env, "android.intent.action.BATTERY_CHANGED");
   1.329  
   1.330 @@ -1556,7 +1571,7 @@
   1.331      if (percent) {
   1.332          int level;
   1.333          int scale;
   1.334 -        
   1.335 +
   1.336          /* Watch out for C89 scoping rules because of the macro */
   1.337          {
   1.338              GET_INT_EXTRA(level_temp, "level") /* == BatteryManager.EXTRA_LEVEL (API 5) */
   1.339 @@ -1567,7 +1582,7 @@
   1.340              GET_INT_EXTRA(scale_temp, "scale") /* == BatteryManager.EXTRA_SCALE (API 5) */
   1.341              scale = scale_temp;
   1.342          }
   1.343 -        
   1.344 +
   1.345          if ((level == -1) || (scale == -1)) {
   1.346              LocalReferenceHolder_Cleanup(&refs);
   1.347              return -1;
   1.348 @@ -1585,8 +1600,7 @@
   1.349  int Android_JNI_GetTouchDeviceIds(int **ids) {
   1.350      JNIEnv *env = Android_JNI_GetEnv();
   1.351      jint sources = 4098; /* == InputDevice.SOURCE_TOUCHSCREEN */
   1.352 -    jmethodID mid = (*env)->GetStaticMethodID(env, mActivityClass, "inputGetInputDeviceIds", "(I)[I");
   1.353 -    jintArray array = (jintArray) (*env)->CallStaticObjectMethod(env, mActivityClass, mid, sources);
   1.354 +    jintArray array = (jintArray) (*env)->CallStaticObjectMethod(env, mActivityClass, midInputGetInputDeviceIds, sources);
   1.355      int number = 0;
   1.356      *ids = NULL;
   1.357      if (array) {
   1.358 @@ -1617,7 +1631,7 @@
   1.359  void Android_JNI_PollInputDevices(void)
   1.360  {
   1.361      JNIEnv *env = Android_JNI_GetEnv();
   1.362 -    (*env)->CallStaticVoidMethod(env, mActivityClass, midPollInputDevices);    
   1.363 +    (*env)->CallStaticVoidMethod(env, mActivityClass, midPollInputDevices);
   1.364  }
   1.365  
   1.366  void Android_JNI_PollHapticDevices(void)
   1.367 @@ -1625,7 +1639,7 @@
   1.368      JNIEnv *env = Android_JNI_GetEnv();
   1.369      (*env)->CallStaticVoidMethod(env, mActivityClass, midPollHapticDevices);
   1.370  }
   1.371 -    
   1.372 +
   1.373  void Android_JNI_HapticRun(int device_id, int length)
   1.374  {
   1.375      JNIEnv *env = Android_JNI_GetEnv();
   1.376 @@ -1640,16 +1654,8 @@
   1.377  int Android_JNI_SendMessage(int command, int param)
   1.378  {
   1.379      JNIEnv *env = Android_JNI_GetEnv();
   1.380 -    jmethodID mid;
   1.381      jboolean success;
   1.382 -    if (!env) {
   1.383 -        return -1;
   1.384 -    }
   1.385 -    mid = (*env)->GetStaticMethodID(env, mActivityClass, "sendMessage", "(II)Z");
   1.386 -    if (!mid) {
   1.387 -        return -1;
   1.388 -    }
   1.389 -    success = (*env)->CallStaticBooleanMethod(env, mActivityClass, mid, command, param);
   1.390 +    success = (*env)->CallStaticBooleanMethod(env, mActivityClass, midSendMessage, command, param);
   1.391      return success ? 0 : -1;
   1.392  }
   1.393  
   1.394 @@ -1661,16 +1667,7 @@
   1.395  void Android_JNI_ShowTextInput(SDL_Rect *inputRect)
   1.396  {
   1.397      JNIEnv *env = Android_JNI_GetEnv();
   1.398 -    jmethodID mid;
   1.399 -    if (!env) {
   1.400 -        return;
   1.401 -    }
   1.402 -
   1.403 -    mid = (*env)->GetStaticMethodID(env, mActivityClass, "showTextInput", "(IIII)Z");
   1.404 -    if (!mid) {
   1.405 -        return;
   1.406 -    }
   1.407 -    (*env)->CallStaticBooleanMethod(env, mActivityClass, mid,
   1.408 +    (*env)->CallStaticBooleanMethod(env, mActivityClass, midShowTextInput,
   1.409                                 inputRect->x,
   1.410                                 inputRect->y,
   1.411                                 inputRect->w,
   1.412 @@ -1686,14 +1683,9 @@
   1.413  
   1.414  SDL_bool Android_JNI_IsScreenKeyboardShown()
   1.415  {
   1.416 -    jmethodID mid;
   1.417 +    JNIEnv *mEnv = Android_JNI_GetEnv();
   1.418      jboolean is_shown = 0;
   1.419 -    JNIEnv *mEnv = Android_JNI_GetEnv();
   1.420 -    mid = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,"isScreenKeyboardShown","()Z");
   1.421 -    if (mid) {
   1.422 -        is_shown = (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, mid);
   1.423 -    }
   1.424 -
   1.425 +    is_shown = (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, midIsScreenKeyboardShown);
   1.426      return is_shown;
   1.427  }
   1.428  
   1.429 @@ -1752,11 +1744,8 @@
   1.430  
   1.431      (*env)->DeleteLocalRef(env, clazz);
   1.432  
   1.433 -    /* call function */
   1.434 -
   1.435 -    mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext","()Landroid/content/Context;");
   1.436 -
   1.437 -    context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
   1.438 +    /* context = SDLActivity.getContext(); */
   1.439 +    context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
   1.440  
   1.441      clazz = (*env)->GetObjectClass(env, context);
   1.442  
   1.443 @@ -1802,17 +1791,13 @@
   1.444  {
   1.445      /* See SDL_system.h for caveats on using this function. */
   1.446  
   1.447 -    jmethodID mid;
   1.448 -
   1.449      JNIEnv *env = Android_JNI_GetEnv();
   1.450      if (!env) {
   1.451          return NULL;
   1.452      }
   1.453  
   1.454      /* return SDLActivity.getContext(); */
   1.455 -    mid = (*env)->GetStaticMethodID(env, mActivityClass,
   1.456 -            "getContext","()Landroid/content/Context;");
   1.457 -    return (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
   1.458 +    return (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
   1.459  }
   1.460  
   1.461  const char * SDL_AndroidGetInternalStoragePath(void)
   1.462 @@ -1834,9 +1819,7 @@
   1.463          }
   1.464  
   1.465          /* context = SDLActivity.getContext(); */
   1.466 -        mid = (*env)->GetStaticMethodID(env, mActivityClass,
   1.467 -                "getContext","()Landroid/content/Context;");
   1.468 -        context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
   1.469 +        context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
   1.470  
   1.471          /* fileObj = context.getFilesDir(); */
   1.472          mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
   1.473 @@ -1920,9 +1903,7 @@
   1.474          }
   1.475  
   1.476          /* context = SDLActivity.getContext(); */
   1.477 -        mid = (*env)->GetStaticMethodID(env, mActivityClass,
   1.478 -                "getContext","()Landroid/content/Context;");
   1.479 -        context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
   1.480 +        context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
   1.481  
   1.482          /* fileObj = context.getExternalFilesDir(); */
   1.483          mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),