aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMax Liu <maliu@mozilla.com>2019-10-08 17:16:00 +0800
committerRoger Chuang <lchuang@mozilla.com>2019-11-26 19:12:58 +0800
commitd23f5bc665d3db912a5158944ec6740bd2aecf2c (patch)
tree2b15b1bf57994ddf111cda158f1726ec500f82a1
parentAdd libwg gradle module (diff)
downloadwireguard-android-d23f5bc665d3db912a5158944ec6740bd2aecf2c.tar.xz
wireguard-android-d23f5bc665d3db912a5158944ec6740bd2aecf2c.zip
Import libwg and redirect dependency to it
Signed-off-by: Roger Chuang <lchuang@mozilla.com>
-rw-r--r--app/build.gradle7
-rw-r--r--app/src/main/java/com/wireguard/android/backend/GoBackend.java16
-rw-r--r--app/tools/libwg-go/jni.c12
-rw-r--r--build.gradle5
-rw-r--r--libwg/build.gradle2
-rw-r--r--libwg/src/main/java/com/wireguard/android/backend/BackendNative.kt2
-rw-r--r--settings.gradle1
7 files changed, 17 insertions, 28 deletions
diff --git a/app/build.gradle b/app/build.gradle
index d16f0c95..c4c465de 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -59,11 +59,6 @@ android {
}
}
}
- externalNativeBuild {
- cmake {
- path 'tools/CMakeLists.txt'
- }
- }
}
ext {
@@ -84,6 +79,8 @@ ext {
}
dependencies {
+ implementation project(':libwg')
+
implementation "androidx.annotation:annotation:$annotationsVersion"
implementation "androidx.appcompat:appcompat:$appcompatVersion"
implementation "androidx.cardview:cardview:$cardviewVersion"
diff --git a/app/src/main/java/com/wireguard/android/backend/GoBackend.java b/app/src/main/java/com/wireguard/android/backend/GoBackend.java
index 3e8e1ec9..1727ad17 100644
--- a/app/src/main/java/com/wireguard/android/backend/GoBackend.java
+++ b/app/src/main/java/com/wireguard/android/backend/GoBackend.java
@@ -20,7 +20,6 @@ import com.wireguard.android.model.Tunnel;
import com.wireguard.android.model.Tunnel.State;
import com.wireguard.android.model.Tunnel.Statistics;
import com.wireguard.android.util.ExceptionLoggers;
-import com.wireguard.android.util.SharedLibraryLoader;
import com.wireguard.config.Config;
import com.wireguard.config.InetNetwork;
import com.wireguard.config.Peer;
@@ -36,7 +35,7 @@ import java.util.concurrent.TimeoutException;
import java9.util.concurrent.CompletableFuture;
-public final class GoBackend implements Backend {
+public final class GoBackend extends BackendNative implements Backend {
private static final String TAG = "WireGuard/" + GoBackend.class.getSimpleName();
private static CompletableFuture<VpnService> vpnService = new CompletableFuture<>();
@@ -45,22 +44,9 @@ public final class GoBackend implements Backend {
private int currentTunnelHandle = -1;
public GoBackend(final Context context) {
- SharedLibraryLoader.loadSharedLibrary(context, "wg-go");
this.context = context;
}
- private static native String wgGetConfig(int handle);
-
- private static native int wgGetSocketV4(int handle);
-
- private static native int wgGetSocketV6(int handle);
-
- private static native void wgTurnOff(int handle);
-
- private static native int wgTurnOn(String ifName, int tunFd, String settings);
-
- private static native String wgVersion();
-
@Override
public Config applyConfig(final Tunnel tunnel, final Config config) throws Exception {
if (tunnel.getState() == State.UP) {
diff --git a/app/tools/libwg-go/jni.c b/app/tools/libwg-go/jni.c
index 3f877d47..74226a2b 100644
--- a/app/tools/libwg-go/jni.c
+++ b/app/tools/libwg-go/jni.c
@@ -15,7 +15,7 @@ extern int wgGetSocketV6(int handle);
extern char *wgGetConfig(int handle);
extern char *wgVersion();
-JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_GoBackend_wgTurnOn(JNIEnv *env, jclass c, jstring ifname, jint tun_fd, jstring settings)
+JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_BackendNative_wgTurnOn(JNIEnv *env, jclass c, jstring ifname, jint tun_fd, jstring settings)
{
const char *ifname_str = (*env)->GetStringUTFChars(env, ifname, 0);
size_t ifname_len = (*env)->GetStringUTFLength(env, ifname);
@@ -33,22 +33,22 @@ JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_GoBackend_wgTurnOn(JNI
return ret;
}
-JNIEXPORT void JNICALL Java_com_wireguard_android_backend_GoBackend_wgTurnOff(JNIEnv *env, jclass c, jint handle)
+JNIEXPORT void JNICALL Java_com_wireguard_android_backend_BackendNative_wgTurnOff(JNIEnv *env, jclass c, jint handle)
{
wgTurnOff(handle);
}
-JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_GoBackend_wgGetSocketV4(JNIEnv *env, jclass c, jint handle)
+JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_BackendNative_wgGetSocketV4(JNIEnv *env, jclass c, jint handle)
{
return wgGetSocketV4(handle);
}
-JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_GoBackend_wgGetSocketV6(JNIEnv *env, jclass c, jint handle)
+JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_BackendNative_wgGetSocketV6(JNIEnv *env, jclass c, jint handle)
{
return wgGetSocketV6(handle);
}
-JNIEXPORT jstring JNICALL Java_com_wireguard_android_backend_GoBackend_wgGetConfig(JNIEnv *env, jclass c, jint handle)
+JNIEXPORT jstring JNICALL Java_com_wireguard_android_backend_BackendNative_wgGetConfig(JNIEnv *env, jclass c, jint handle)
{
jstring ret;
char *config = wgGetConfig(handle);
@@ -59,7 +59,7 @@ JNIEXPORT jstring JNICALL Java_com_wireguard_android_backend_GoBackend_wgGetConf
return ret;
}
-JNIEXPORT jstring JNICALL Java_com_wireguard_android_backend_GoBackend_wgVersion(JNIEnv *env, jclass c)
+JNIEXPORT jstring JNICALL Java_com_wireguard_android_backend_BackendNative_wgVersion(JNIEnv *env, jclass c)
{
jstring ret;
char *version = wgVersion();
diff --git a/build.gradle b/build.gradle
index aa7a4692..125c4525 100644
--- a/build.gradle
+++ b/build.gradle
@@ -6,8 +6,11 @@ allprojects {
}
buildscript {
+ ext.kotlin_version = '1.3.50'
+
dependencies {
- classpath 'com.android.tools.build:gradle:3.5.1'
+ classpath 'com.android.tools.build:gradle:3.5.2'
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
repositories {
google()
diff --git a/libwg/build.gradle b/libwg/build.gradle
index 3bd71511..7457573c 100644
--- a/libwg/build.gradle
+++ b/libwg/build.gradle
@@ -26,7 +26,7 @@ android {
}
externalNativeBuild {
cmake {
- path rootDir.path + '/app/tools/CMakeLists.txt'
+ path projectDir.path + '/../app/tools/CMakeLists.txt'
}
}
}
diff --git a/libwg/src/main/java/com/wireguard/android/backend/BackendNative.kt b/libwg/src/main/java/com/wireguard/android/backend/BackendNative.kt
index 59e9a653..a7fd236e 100644
--- a/libwg/src/main/java/com/wireguard/android/backend/BackendNative.kt
+++ b/libwg/src/main/java/com/wireguard/android/backend/BackendNative.kt
@@ -7,6 +7,8 @@ package com.wireguard.android.backend
public open class BackendNative {
+ public external fun wgGetConfig(handle: Int): String
+
public external fun wgGetSocketV4(handle: Int): Int
public external fun wgGetSocketV6(handle: Int): Int
diff --git a/settings.gradle b/settings.gradle
index e7b4def4..ba5f5dd7 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1 +1,2 @@
include ':app'
+include ':libwg'