mirror of
http://galexander.org/git/simplesshd.git
synced 2025-08-03 00:28:22 +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;
|
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
|
JNIEXPORT void JNICALL
|
||||||
Java_org_galexander_sshd_SimpleSSHDService_start_1sshd(JNIEnv *env_,
|
Java_org_galexander_sshd_SimpleSSHDService_start_1sshd(JNIEnv *env_,
|
||||||
jobject this)
|
jobject this,
|
||||||
|
jint port, jobject jpath, jobject jshell, jobject jhome)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
const char *path, *shell, *home;
|
||||||
|
|
||||||
if (!jni_init(env_)) {
|
if (!jni_init(env_)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
path = from_java_string(jpath);
|
||||||
|
shell = from_java_string(jshell);
|
||||||
|
home = from_java_string(jhome);
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
/* XXX - call dropbear main() */
|
/* XXX - call dropbear main() */
|
||||||
} else {
|
} 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();
|
edit.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean get_onboot(SharedPreferences p) {
|
public static boolean get_onboot(SharedPreferences p) {
|
||||||
return p.getBoolean("onboot", false);
|
return p.getBoolean("onboot", false);
|
||||||
}
|
}
|
||||||
private int get_port(SharedPreferences p) {
|
public static int get_port(SharedPreferences p) {
|
||||||
return p.getInt("port", 2222);
|
return p.getInt("port", 2222);
|
||||||
}
|
}
|
||||||
private String get_path(SharedPreferences p) {
|
public static String get_path(SharedPreferences p) {
|
||||||
return p.getString("path", "/sdcard/ssh");
|
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");
|
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");
|
return p.getString("home", "/sdcard/ssh");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,10 @@ package org.galexander.sshd;
|
|||||||
|
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.Context;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
public class SimpleSSHDService extends Service {
|
public class SimpleSSHDService extends Service {
|
||||||
public static int sshd_pid = 0;
|
public static int sshd_pid = 0;
|
||||||
@ -11,10 +14,14 @@ public class SimpleSSHDService extends Service {
|
|||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
if ((intent == null) ||
|
if ((intent == null) ||
|
||||||
(!intent.getBooleanExtra("stop", false))) {
|
(!intent.getBooleanExtra("stop", false))) {
|
||||||
|
SharedPreferences p = PreferenceManager.
|
||||||
|
getDefaultSharedPreferences(this);
|
||||||
if (is_started()) {
|
if (is_started()) {
|
||||||
stop_sshd();
|
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) {
|
if (activity != null) {
|
||||||
activity.update_startstop();
|
activity.update_startstop();
|
||||||
}
|
}
|
||||||
@ -35,7 +42,8 @@ public class SimpleSSHDService extends Service {
|
|||||||
return (sshd_pid != 0);
|
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();
|
private native void stop_sshd();
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("simplesshd-jni");
|
System.loadLibrary("simplesshd-jni");
|
||||||
|
Loading…
Reference in New Issue
Block a user