android: Added a Java part to the Android IMC
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "imc_android_state.h"
|
||||
#include "../android_jni.h"
|
||||
|
||||
#include <tnc/tnc.h>
|
||||
#include <libpts.h>
|
||||
@@ -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, "<init>",
|
||||
"(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;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
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;
|
||||
}
|
||||
androidjni_detach_thread();
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user