From: Tobias Brunner Date: Wed, 24 Apr 2013 14:24:14 +0000 (+0200) Subject: android: Added a Java part to the Android IMC X-Git-Tag: 5.1.0dr2~2^2~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa4ff3b2111d5d24d9356b6590b5cf29ad710feb;p=thirdparty%2Fstrongswan.git android: Added a Java part to the Android IMC --- diff --git a/src/frontends/android/jni/libandroidbridge/byod/imc_android.c b/src/frontends/android/jni/libandroidbridge/byod/imc_android.c index 06edf359aa..f648456f78 100644 --- a/src/frontends/android/jni/libandroidbridge/byod/imc_android.c +++ b/src/frontends/android/jni/libandroidbridge/byod/imc_android.c @@ -15,6 +15,7 @@ */ #include "imc_android_state.h" +#include "../android_jni.h" #include #include @@ -45,6 +46,16 @@ static pen_type_t msg_types[] = { static imc_agent_t *imc_android; +/** + * AndroidImc object accessed via JNI + */ +static jobject android_imc; + +/** + * AndroidImc class object + */ +static jclass android_imc_cls; + /** * see section 3.8.1 of TCG TNC IF-IMC Specification 1.3 */ @@ -382,13 +393,59 @@ TNC_Result TNC_IMC_ProvideBindFunction(TNC_IMCID imc_id, bool imc_android_register(plugin_t *plugin, plugin_feature_t *feature, bool reg, void *data) { + JNIEnv *env; + jmethodID method_id; + jobject obj, context = (jobject)data; + jclass cls; + bool success = TRUE; + + androidjni_attach_thread(&env); if (reg) { - return tnc->imcs->load_from_functions(tnc->imcs, "android", + cls = (*env)->FindClass(env, JNI_PACKAGE_STRING "/imc/AndroidImc"); + if (!cls) + { + goto failed; + } + android_imc_cls = (*env)->NewGlobalRef(env, cls); + method_id = (*env)->GetMethodID(env, cls, "", + "(Landroid/content/Context;)V"); + if (!method_id) + { + goto failed; + } + obj = (*env)->NewObject(env, cls, method_id, context); + if (!obj) + { + goto failed; + } + android_imc = (*env)->NewGlobalRef(env, obj); + androidjni_detach_thread(); + + if (tnc->imcs->load_from_functions(tnc->imcs, "Android", TNC_IMC_Initialize, TNC_IMC_NotifyConnectionChange, TNC_IMC_BeginHandshake, TNC_IMC_ReceiveMessage, TNC_IMC_ReceiveMessageLong, TNC_IMC_BatchEnding, - TNC_IMC_Terminate, TNC_IMC_ProvideBindFunction); + TNC_IMC_Terminate, TNC_IMC_ProvideBindFunction)) + { + return TRUE; + } +failed: + DBG1(DBG_IMC, "initialization of Android IMC failed"); + androidjni_exception_occurred(env); + success = FALSE; + } + + if (android_imc) + { + (*env)->DeleteGlobalRef(env, android_imc); + android_imc = NULL; + } + if (android_imc_cls) + { + (*env)->DeleteGlobalRef(env, android_imc_cls); + android_imc_cls = NULL; } - return TRUE; + androidjni_detach_thread(); + return success; } diff --git a/src/frontends/android/jni/libandroidbridge/charonservice.c b/src/frontends/android/jni/libandroidbridge/charonservice.c index fbbda55a9d..1c62e282c4 100644 --- a/src/frontends/android/jni/libandroidbridge/charonservice.c +++ b/src/frontends/android/jni/libandroidbridge/charonservice.c @@ -462,14 +462,6 @@ static void charonservice_init(JNIEnv *env, jobject service, jobject builder) PLUGIN_PROVIDE(CUSTOM, "android-backend"), PLUGIN_DEPENDS(CUSTOM, "libcharon"), }; -#ifdef USE_BYOD - static plugin_feature_t byod_features[] = { - PLUGIN_CALLBACK(imc_android_register, NULL), - PLUGIN_PROVIDE(CUSTOM, "android-imc"), - PLUGIN_DEPENDS(CUSTOM, "android-backend"), - PLUGIN_DEPENDS(CUSTOM, "imc-manager"), - }; -#endif INIT(this, .public = { @@ -494,8 +486,17 @@ static void charonservice_init(JNIEnv *env, jobject service, jobject builder) countof(features), TRUE); #ifdef USE_BYOD - lib->plugins->add_static_features(lib->plugins, "android-byod", + { + plugin_feature_t byod_features[] = { + PLUGIN_CALLBACK(imc_android_register, this->vpn_service), + PLUGIN_PROVIDE(CUSTOM, "android-imc"), + PLUGIN_DEPENDS(CUSTOM, "android-backend"), + PLUGIN_DEPENDS(CUSTOM, "imc-manager"), + }; + + lib->plugins->add_static_features(lib->plugins, "android-byod", byod_features, countof(byod_features), TRUE); + } #endif } diff --git a/src/frontends/android/src/org/strongswan/android/logic/imc/AndroidImc.java b/src/frontends/android/src/org/strongswan/android/logic/imc/AndroidImc.java new file mode 100644 index 0000000000..3067707d13 --- /dev/null +++ b/src/frontends/android/src/org/strongswan/android/logic/imc/AndroidImc.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2013 Tobias Brunner + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +package org.strongswan.android.logic.imc; + +import android.content.Context; + +public class AndroidImc +{ + private final Context mContext; + + public AndroidImc(Context context) + { + mContext = context; + } +}