android: Added a global variable to check the current SDK version
authorTobias Brunner <tobias@strongswan.org>
Mon, 24 Sep 2012 14:54:38 +0000 (16:54 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 24 Sep 2012 15:12:18 +0000 (17:12 +0200)
src/frontends/android/jni/libandroidbridge/android_jni.c
src/frontends/android/jni/libandroidbridge/android_jni.h

index e7cb14f..7ab9a24 100644 (file)
@@ -27,6 +27,7 @@ static JavaVM *android_jvm;
 
 jclass *android_charonvpnservice_class;
 jclass *android_charonvpnservice_builder_class;
+android_sdk_version_t android_sdk_version;
 
 /**
  * Thread-local variable. Only used because of the destructor
@@ -75,7 +76,9 @@ void androidjni_detach_thread()
  */
 jint JNI_OnLoad(JavaVM *vm, void *reserved)
 {
-    JNIEnv *env;
+       JNIEnv *env;
+       jclass jversion;
+       jfieldID jsdk_int;
 
        android_jvm = vm;
 
@@ -93,6 +96,10 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
                                (*env)->NewGlobalRef(env, (*env)->FindClass(env,
                                                JNI_PACKAGE_STRING "/CharonVpnService$BuilderAdapter"));
 
+       jversion = (*env)->FindClass(env, "android/os/Build$VERSION");
+       jsdk_int = (*env)->GetStaticFieldID(env, jversion, "SDK_INT", "I");
+       android_sdk_version = (*env)->GetStaticIntField(env, jversion, jsdk_int);
+
        return JNI_VERSION_1_6;
 }
 
index 943774e..b89fd3a 100644 (file)
@@ -46,6 +46,24 @@ extern jclass *android_charonvpnservice_class;
 extern jclass *android_charonvpnservice_builder_class;
 
 /**
+ * Currently known (supported) SDK versions
+ *
+ * see android.os.Build.VERSION_CODES for definitions
+ */
+typedef enum {
+       ANDROID_ICE_CREAM_SANDWICH = 14,
+       ANDROID_ICE_CREAM_SANDWICH_MR1 = 15,
+       ANDROID_JELLY_BEAN = 16,
+} android_sdk_version_t;
+
+/**
+ * The current SDK version of the Android framework
+ *
+ * see android.os.Build.VERSION.SDK_INT
+ */
+extern android_sdk_version_t android_sdk_version;
+
+/**
  * Attach the current thread to the JVM
  *
  * As local JNI references are not freed until the thread detaches