2014-12-10 21:17:23 +00:00
|
|
|
package org.galexander.sshd;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.os.Bundle;
|
2014-12-15 03:56:31 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
2014-12-16 16:21:17 +00:00
|
|
|
import android.content.Intent;
|
2014-12-15 03:56:31 +00:00
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.view.View;
|
2014-12-10 21:17:23 +00:00
|
|
|
|
|
|
|
public class SimpleSSHD extends Activity
|
|
|
|
{
|
2014-12-15 03:56:31 +00:00
|
|
|
private CheckBox onboot_view;
|
|
|
|
private EditText port_view, path_view, shell_view, home_view;
|
|
|
|
private Button startstop_view;
|
|
|
|
|
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.main);
|
|
|
|
onboot_view = (CheckBox)findViewById(R.id.onboot);
|
|
|
|
port_view = (EditText)findViewById(R.id.port);
|
|
|
|
path_view = (EditText)findViewById(R.id.path);
|
|
|
|
shell_view = (EditText)findViewById(R.id.shell);
|
|
|
|
home_view = (EditText)findViewById(R.id.home);
|
|
|
|
startstop_view = (Button)findViewById(R.id.startstop);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onResume() {
|
2014-12-16 21:37:17 +00:00
|
|
|
super.onResume();
|
2014-12-15 03:56:31 +00:00
|
|
|
load_prefs();
|
2014-12-16 16:20:36 +00:00
|
|
|
update_startstop();
|
|
|
|
SimpleSSHDService.activity = this;
|
2014-12-15 03:56:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onPause() {
|
2014-12-16 16:20:36 +00:00
|
|
|
SimpleSSHDService.activity = null;
|
2014-12-15 03:56:31 +00:00
|
|
|
save_prefs();
|
|
|
|
}
|
|
|
|
|
2014-12-16 16:20:36 +00:00
|
|
|
public void update_startstop() {
|
|
|
|
if (SimpleSSHDService.is_started()) {
|
|
|
|
startstop_view.setText("STOP");
|
|
|
|
startstop_view.setTextColor(0xFFFF8888);
|
|
|
|
} else {
|
|
|
|
startstop_view.setText("START");
|
|
|
|
startstop_view.setTextColor(0xFF88FF88);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-16 21:49:54 +00:00
|
|
|
public void startstop_clicked(View v) {
|
2014-12-15 03:56:31 +00:00
|
|
|
save_prefs();
|
2014-12-16 16:20:36 +00:00
|
|
|
Intent i = new Intent(this, SimpleSSHDService.class);
|
2014-12-16 16:21:17 +00:00
|
|
|
if (SimpleSSHDService.is_started()) {
|
2014-12-16 16:20:36 +00:00
|
|
|
i.putExtra("stop", true);
|
|
|
|
}
|
|
|
|
startService(i);
|
2014-12-15 03:56:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void load_prefs() {
|
|
|
|
SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
|
|
|
|
onboot_view.setChecked(get_onboot(prefs));
|
|
|
|
port_view.setText(Integer.toString(get_port(prefs)));
|
|
|
|
path_view.setText(get_path(prefs));
|
|
|
|
shell_view.setText(get_shell(prefs));
|
|
|
|
home_view.setText(get_home(prefs));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void save_prefs() {
|
|
|
|
SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor edit = prefs.edit();
|
|
|
|
boolean b = onboot_view.isChecked();
|
|
|
|
if (b != get_onboot(prefs)) { edit.putBoolean("onboot", b); }
|
|
|
|
int i = Integer.valueOf(onboot_view.getText().toString());
|
|
|
|
if (i != get_port(prefs)) { edit.putInt("port", i); }
|
|
|
|
String s = path_view.getText().toString();
|
|
|
|
if (!s.equals(get_path(prefs))) { edit.putString("path", s); }
|
|
|
|
s = shell_view.getText().toString();
|
|
|
|
if (!s.equals(get_shell(prefs))) { edit.putString("shell", s); }
|
|
|
|
s = home_view.getText().toString();
|
|
|
|
if (!s.equals(get_home(prefs))) { edit.putString("home", s); }
|
2014-12-15 04:23:43 +00:00
|
|
|
edit.commit();
|
2014-12-15 03:56:31 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 20:50:30 +00:00
|
|
|
public static boolean get_onboot(SharedPreferences p) {
|
2014-12-15 03:56:31 +00:00
|
|
|
return p.getBoolean("onboot", false);
|
|
|
|
}
|
2014-12-16 20:50:30 +00:00
|
|
|
public static int get_port(SharedPreferences p) {
|
2014-12-15 03:56:31 +00:00
|
|
|
return p.getInt("port", 2222);
|
|
|
|
}
|
2014-12-16 20:50:30 +00:00
|
|
|
public static String get_path(SharedPreferences p) {
|
2014-12-15 03:56:31 +00:00
|
|
|
return p.getString("path", "/sdcard/ssh");
|
|
|
|
}
|
2014-12-16 20:50:30 +00:00
|
|
|
public static String get_shell(SharedPreferences p) {
|
2014-12-15 03:56:31 +00:00
|
|
|
return p.getString("shell", "/system/bin/sh -l");
|
|
|
|
}
|
2014-12-16 20:50:30 +00:00
|
|
|
public static String get_home(SharedPreferences p) {
|
2014-12-15 03:56:31 +00:00
|
|
|
return p.getString("home", "/sdcard/ssh");
|
|
|
|
}
|
2014-12-10 21:17:23 +00:00
|
|
|
}
|