2020-05-22 13:18:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2020, The PurpleI2P Project
|
|
|
|
*
|
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3
|
|
|
|
*
|
|
|
|
* See full license text in LICENSE file at top of project tree
|
|
|
|
*/
|
|
|
|
|
2016-07-09 20:54:11 +00:00
|
|
|
#include <jni.h>
|
|
|
|
#include "org_purplei2p_i2pd_I2PD_JNI.h"
|
|
|
|
#include "DaemonAndroid.h"
|
2017-04-21 10:33:45 +00:00
|
|
|
#include "RouterContext.h"
|
2020-04-11 20:28:45 +00:00
|
|
|
#include "ClientContext.h"
|
2017-04-21 10:33:45 +00:00
|
|
|
#include "Transports.h"
|
2020-04-28 23:11:35 +00:00
|
|
|
#include "Tunnel.h"
|
2016-07-09 20:54:11 +00:00
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_getABICompiledWith
|
2019-04-20 19:47:06 +00:00
|
|
|
(JNIEnv *env, jclass clazz) {
|
2016-07-09 20:54:11 +00:00
|
|
|
#if defined(__arm__)
|
2019-01-18 12:44:30 +00:00
|
|
|
#if defined(__ARM_ARCH_7A__)
|
|
|
|
#if defined(__ARM_NEON__)
|
|
|
|
#if defined(__ARM_PCS_VFP)
|
|
|
|
#define ABI "armeabi-v7a/NEON (hard-float)"
|
|
|
|
#else
|
|
|
|
#define ABI "armeabi-v7a/NEON"
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if defined(__ARM_PCS_VFP)
|
|
|
|
#define ABI "armeabi-v7a (hard-float)"
|
|
|
|
#else
|
|
|
|
#define ABI "armeabi-v7a"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define ABI "armeabi"
|
|
|
|
#endif
|
|
|
|
#elif defined(__i386__)
|
|
|
|
#define ABI "x86"
|
|
|
|
#elif defined(__x86_64__)
|
|
|
|
#define ABI "x86_64"
|
|
|
|
#elif defined(__mips64) /* mips64el-* toolchain defines __mips__ too */
|
|
|
|
#define ABI "mips64"
|
|
|
|
#elif defined(__mips__)
|
|
|
|
#define ABI "mips"
|
|
|
|
#elif defined(__aarch64__)
|
|
|
|
#define ABI "arm64-v8a"
|
|
|
|
#else
|
|
|
|
#define ABI "unknown"
|
2016-07-09 20:54:11 +00:00
|
|
|
#endif
|
|
|
|
|
2019-01-18 12:44:30 +00:00
|
|
|
return env->NewStringUTF(ABI);
|
2016-07-09 20:54:11 +00:00
|
|
|
}
|
|
|
|
|
2016-07-10 01:42:42 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_startDaemon
|
2019-04-20 19:47:06 +00:00
|
|
|
(JNIEnv *env, jclass clazz) {
|
2018-01-22 17:59:34 +00:00
|
|
|
return env->NewStringUTF(i2p::android::start().c_str());
|
2016-07-09 20:54:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_stopDaemon
|
2019-04-20 19:47:06 +00:00
|
|
|
(JNIEnv *env, jclass clazz) {
|
2016-07-09 20:54:11 +00:00
|
|
|
i2p::android::stop();
|
|
|
|
}
|
|
|
|
|
2016-07-10 01:42:42 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_stopAcceptingTunnels
|
2019-04-20 19:47:06 +00:00
|
|
|
(JNIEnv *env, jclass clazz) {
|
2016-07-10 01:42:42 +00:00
|
|
|
i2p::context.SetAcceptsTunnels (false);
|
|
|
|
}
|
|
|
|
|
2018-11-20 17:36:10 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_startAcceptingTunnels
|
2019-04-20 19:47:06 +00:00
|
|
|
(JNIEnv *env, jclass clazz) {
|
2018-11-20 17:36:10 +00:00
|
|
|
i2p::context.SetAcceptsTunnels (true);
|
|
|
|
}
|
|
|
|
|
2020-04-11 20:28:45 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_reloadTunnelsConfigs
|
|
|
|
(JNIEnv *env, jclass clazz) {
|
|
|
|
i2p::client::context.ReloadConfig();
|
|
|
|
}
|
|
|
|
|
2016-07-10 01:42:42 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_onNetworkStateChanged
|
2019-04-20 19:47:06 +00:00
|
|
|
(JNIEnv *env, jclass clazz, jboolean isConnected) {
|
2016-07-10 01:42:42 +00:00
|
|
|
bool isConnectedBool = (bool) isConnected;
|
2017-04-21 10:33:45 +00:00
|
|
|
i2p::transport::transports.SetOnline (isConnectedBool);
|
2016-07-10 01:42:42 +00:00
|
|
|
}
|
2019-04-20 19:47:06 +00:00
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_setDataDir
|
|
|
|
(JNIEnv *env, jclass clazz, jstring jdataDir) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
// Method 1: convert UTF-16 jstring to std::string (https://stackoverflow.com/a/41820336)
|
|
|
|
const jclass stringClass = env->GetObjectClass(jdataDir);
|
|
|
|
const jmethodID getBytes = env->GetMethodID(stringClass, "getBytes", "(Ljava/lang/String;)[B");
|
|
|
|
const jbyteArray stringJbytes = (jbyteArray) env->CallObjectMethod(jdataDir, getBytes, env->NewStringUTF("UTF-8"));
|
|
|
|
|
|
|
|
size_t length = (size_t) env->GetArrayLength(stringJbytes);
|
|
|
|
jbyte* pBytes = env->GetByteArrayElements(stringJbytes, NULL);
|
|
|
|
|
|
|
|
std::string dataDir = std::string((char *)pBytes, length);
|
|
|
|
env->ReleaseByteArrayElements(stringJbytes, pBytes, JNI_ABORT);
|
|
|
|
|
|
|
|
env->DeleteLocalRef(stringJbytes);
|
|
|
|
env->DeleteLocalRef(stringClass); */
|
|
|
|
|
|
|
|
// Method 2: get string chars and make char array.
|
|
|
|
auto dataDir = env->GetStringUTFChars(jdataDir, NULL);
|
|
|
|
env->ReleaseStringUTFChars(jdataDir, dataDir);
|
|
|
|
|
|
|
|
// Set DataDir
|
|
|
|
i2p::android::SetDataDir(dataDir);
|
|
|
|
}
|
2020-04-28 23:11:35 +00:00
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_GetTransitTunnelsCount
|
|
|
|
(JNIEnv *env, jclass clazz) {
|
|
|
|
return i2p::tunnel::tunnels.CountTransitTunnels();
|
|
|
|
}
|