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

This commit is contained in:
unlnown542a 2018-01-17 20:58:56 +03:00
parent cf5081d300
commit bc72800fef
4 changed files with 31 additions and 13 deletions

View File

@ -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();
return env->NewStringUTF(i2p::android::start(argc,argv).c_str());
for (int i = 0; i < argc; i++) {
delete [] argv[i];
}
delete [] argv;
return env->NewStringUTF(result);
}
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_stopDaemon

View File

@ -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);

View File

@ -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);

View File

@ -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();