Browse Source

moved hard code into java side and successfully passed back to native

pull/1064/head^2
unlnown542a 7 years ago
parent
commit
bc72800fef
  1. 29
      android/jni/i2pd_android.cpp
  2. 2
      android/jni/org_purplei2p_i2pd_I2PD_JNI.h
  3. 11
      android/src/org/purplei2p/i2pd/DaemonSingleton.java
  4. 2
      android/src/org/purplei2p/i2pd/I2PD_JNI.java

29
android/jni/i2pd_android.cpp

@ -44,18 +44,27 @@ JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_getABICompiledWith @@ -44,18 +44,27 @@ JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_getABICompiledWith
}
JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_startDaemon
(JNIEnv * env, jclass clazz) {
(JNIEnv * env, jclass clazz, jobjectArray args) {
int argc = env->GetArrayLength(args);
typedef char *pchar;
pchar* argv = new pchar[argc];
for (int i = 0; i < argc; i++) {
jstring arg = (jstring) env->GetObjectArrayElement(args, i);
const char *argStr = env->GetStringUTFChars(arg, 0);
size_t len = strlen(argStr);
argv[i] = new char[len + 1];
strcpy(argv[i], argStr);
env->ReleaseStringUTFChars(arg, argStr);
}
int argc=5;
static char* argv[]={
strdup("i2pd"),
strdup("--conf=/sdcard/i2pd/i2pd.conf"),
strdup("--tunconf=/sdcard/i2pd/tunnels.conf"),
strdup("--datadir=/data/data/org.purplei2p.i2pd/app_data/"),
strdup("--service"), strdup("--daemon")
};
const char* result = i2p::android::start(argc,argv).c_str();
for (int i = 0; i < argc; i++) {
delete [] argv[i];
}
delete [] argv;
return env->NewStringUTF(i2p::android::start(argc,argv).c_str());
return env->NewStringUTF(result);
}
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_stopDaemon

2
android/jni/org_purplei2p_i2pd_I2PD_JNI.h

@ -16,7 +16,7 @@ JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_getABICompiledWith @@ -16,7 +16,7 @@ JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_getABICompiledWith
(JNIEnv *, jclass);
JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_startDaemon
(JNIEnv *, jclass);
(JNIEnv *, jclass, jobjectArray args);
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_stopDaemon
(JNIEnv *, jclass);

11
android/src/org/purplei2p/i2pd/DaemonSingleton.java

@ -62,7 +62,16 @@ public class DaemonSingleton { @@ -62,7 +62,16 @@ public class DaemonSingleton {
}
try {
synchronized (DaemonSingleton.this) {
daemonStartResult = I2PD_JNI.startDaemon();
String args[] = {
"i2pd",
"--conf=/sdcard/i2pd/i2pd.conf",
"--tunconf=/sdcard/i2pd/tunnels.conf",
"--datadir=/data/data/org.purplei2p.i2pd/app_data/",
"--service",
"--daemon"
};
daemonStartResult = I2PD_JNI.startDaemon(args);
if("ok".equals(daemonStartResult)){
state=State.startedOkay;
setStartedOkay(true);

2
android/src/org/purplei2p/i2pd/I2PD_JNI.java

@ -6,7 +6,7 @@ public class I2PD_JNI { @@ -6,7 +6,7 @@ public class I2PD_JNI {
* returns error info if failed
* returns "ok" if daemon initialized and started okay
*/
public static native String startDaemon();
public static native String startDaemon(String args[]);
//should only be called after startDaemon() success
public static native void stopDaemon();

Loading…
Cancel
Save