aboutsummaryrefslogtreecommitdiffstats
path: root/src/frontends/android/jni/libandroidbridge
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontends/android/jni/libandroidbridge')
-rw-r--r--src/frontends/android/jni/libandroidbridge/charonservice.c25
-rw-r--r--src/frontends/android/jni/libandroidbridge/charonservice.h22
2 files changed, 47 insertions, 0 deletions
diff --git a/src/frontends/android/jni/libandroidbridge/charonservice.c b/src/frontends/android/jni/libandroidbridge/charonservice.c
index 974875e6e..874258b3b 100644
--- a/src/frontends/android/jni/libandroidbridge/charonservice.c
+++ b/src/frontends/android/jni/libandroidbridge/charonservice.c
@@ -90,6 +90,30 @@ static void dbg_android(debug_t group, level_t level, char *fmt, ...)
}
}
+METHOD(charonservice_t, update_status, bool,
+ private_charonservice_t *this, android_vpn_state_t code)
+{
+ JNIEnv *env;
+ jmethodID method_id;
+ bool success = FALSE;
+
+ androidjni_attach_thread(&env);
+
+ method_id = (*env)->GetMethodID(env, android_charonvpnservice_class,
+ "updateStatus", "(I)V");
+ if (!method_id)
+ {
+ goto failed;
+ }
+ (*env)->CallVoidMethod(env, this->vpn_service, method_id, (jint)code);
+ success = !androidjni_exception_occurred(env);
+
+failed:
+ androidjni_exception_occurred(env);
+ androidjni_detach_thread();
+ return success;
+}
+
METHOD(charonservice_t, bypass_socket, bool,
private_charonservice_t *this, int fd, int family)
{
@@ -133,6 +157,7 @@ static void charonservice_init(JNIEnv *env, jobject service)
INIT(this,
.public = {
+ .update_status = _update_status,
.bypass_socket = _bypass_socket,
},
.vpn_service = (*env)->NewGlobalRef(env, service),
diff --git a/src/frontends/android/jni/libandroidbridge/charonservice.h b/src/frontends/android/jni/libandroidbridge/charonservice.h
index 8bacd0a1d..c53716588 100644
--- a/src/frontends/android/jni/libandroidbridge/charonservice.h
+++ b/src/frontends/android/jni/libandroidbridge/charonservice.h
@@ -30,9 +30,23 @@
#include <library.h>
+typedef enum android_vpn_state_t android_vpn_state_t;
typedef struct charonservice_t charonservice_t;
/**
+ * VPN status codes. As defined in CharonVpnService.java
+ */
+enum android_vpn_state_t {
+ CHARONSERVICE_CHILD_STATE_UP = 1,
+ CHARONSERVICE_CHILD_STATE_DOWN,
+ CHARONSERVICE_AUTH_ERROR,
+ CHARONSERVICE_PEER_AUTH_ERROR,
+ CHARONSERVICE_LOOKUP_ERROR,
+ CHARONSERVICE_UNREACHABLE_ERROR,
+ CHARONSERVICE_GENERIC_ERROR,
+};
+
+/**
* Public interface of charonservice.
*
* Used to communicate with CharonVpnService via JNI
@@ -40,6 +54,14 @@ typedef struct charonservice_t charonservice_t;
struct charonservice_t {
/**
+ * Update the status in the Java domain (UI)
+ *
+ * @param code status code
+ * @return TRUE on success
+ */
+ bool (*update_status)(charonservice_t *this, android_vpn_state_t code);
+
+ /**
* Install a bypass policy for the given socket using the protect() Method
* of the Android VpnService interface
*