mirror of
http://galexander.org/git/simplesshd.git
synced 2025-01-03 19:50:55 +00:00
communicate the preferences to the C code
This commit is contained in:
parent
02a88eae06
commit
a9ca75accc
@ -36,19 +36,39 @@ jni_init(JNIEnv *env_)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *
|
||||
from_java_string(jobject s)
|
||||
{
|
||||
const char *ret, *t;
|
||||
t = (*env)->GetStringUTFChars(env, s, NULL);
|
||||
if (!t) {
|
||||
return NULL;
|
||||
}
|
||||
ret = strdup(t);
|
||||
(*env)->ReleaseStringUTFChars(env, s, t);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_galexander_sshd_SimpleSSHDService_start_1sshd(JNIEnv *env_,
|
||||
jobject this)
|
||||
jobject this,
|
||||
jint port, jobject jpath, jobject jshell, jobject jhome)
|
||||
{
|
||||
pid_t pid;
|
||||
const char *path, *shell, *home;
|
||||
|
||||
if (!jni_init(env_)) {
|
||||
return;
|
||||
}
|
||||
path = from_java_string(jpath);
|
||||
shell = from_java_string(jshell);
|
||||
home = from_java_string(jhome);
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
/* XXX - call dropbear main() */
|
||||
} else {
|
||||
(*env)->SetStaticIntField(env, cl_simplesshdservice, fid_sss_sshd_pid, pid);
|
||||
(*env)->SetStaticIntField(env, cl_simplesshdservice,
|
||||
fid_sss_sshd_pid, pid);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,19 +83,19 @@ public class SimpleSSHD extends Activity
|
||||
edit.commit();
|
||||
}
|
||||
|
||||
private boolean get_onboot(SharedPreferences p) {
|
||||
public static boolean get_onboot(SharedPreferences p) {
|
||||
return p.getBoolean("onboot", false);
|
||||
}
|
||||
private int get_port(SharedPreferences p) {
|
||||
public static int get_port(SharedPreferences p) {
|
||||
return p.getInt("port", 2222);
|
||||
}
|
||||
private String get_path(SharedPreferences p) {
|
||||
public static String get_path(SharedPreferences p) {
|
||||
return p.getString("path", "/sdcard/ssh");
|
||||
}
|
||||
private String get_shell(SharedPreferences p) {
|
||||
public static String get_shell(SharedPreferences p) {
|
||||
return p.getString("shell", "/system/bin/sh -l");
|
||||
}
|
||||
private String get_home(SharedPreferences p) {
|
||||
public static String get_home(SharedPreferences p) {
|
||||
return p.getString("home", "/sdcard/ssh");
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,10 @@ package org.galexander.sshd;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.Context;
|
||||
import android.os.IBinder;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
public class SimpleSSHDService extends Service {
|
||||
public static int sshd_pid = 0;
|
||||
@ -11,10 +14,14 @@ public class SimpleSSHDService extends Service {
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if ((intent == null) ||
|
||||
(!intent.getBooleanExtra("stop", false))) {
|
||||
SharedPreferences p = PreferenceManager.
|
||||
getDefaultSharedPreferences(this);
|
||||
if (is_started()) {
|
||||
stop_sshd();
|
||||
}
|
||||
start_sshd();
|
||||
start_sshd(SimpleSSHD.get_port(p),
|
||||
SimpleSSHD.get_path(p), SimpleSSHD.get_shell(p),
|
||||
SimpleSSHD.get_home(p));
|
||||
if (activity != null) {
|
||||
activity.update_startstop();
|
||||
}
|
||||
@ -35,7 +42,8 @@ public class SimpleSSHDService extends Service {
|
||||
return (sshd_pid != 0);
|
||||
}
|
||||
|
||||
private native void start_sshd();
|
||||
private native void start_sshd(int port, String path,
|
||||
String shell, String home);
|
||||
private native void stop_sshd();
|
||||
static {
|
||||
System.loadLibrary("simplesshd-jni");
|
||||
|
Loading…
Reference in New Issue
Block a user