Skip to content
Snippets Groups Projects
Commit 272460f1 authored by Matthias Goebl's avatar Matthias Goebl
Browse files

ported bugfixes by tanguy.pruvot@gmail.com from...

ported bugfixes by tanguy.pruvot@gmail.com from https://github.com/tpruvot/android_external_droidsshd
(more try/catch, service startup, released boot receiver, status management)
but preserved the dropbear binaries and related code from https://github.com/mestre/droidsshd
parent d7ced859
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -67,17 +67,20 @@ public class DroidSSHd extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Base.initialize(getBaseContext());
setContentView(R.layout.act_main);
Base.setDropbearDaemonStatus(Base.DAEMON_STATUS_STOPPED);
Base.setDropbearDaemonStatus(Base.DAEMON_STATUS_UNKNOWN);
 
setContentView(R.layout.act_main);
setUpUiListeners();
 
mDropbearDaemonHandlerService = new Intent(this, br.com.bott.droidsshd.system.DroidSSHdService.class);
if ((!Util.validateHostKeys() || (!Util.checkPathToBinaries()))) {
startInitialSetupActivity();
}
Base.setDropbearDaemonStatus(Base.DAEMON_STATUS_STOPPED);
Base.setManualServiceStart(true);
mDropbearDaemonHandlerService = new Intent(this, br.com.bott.droidsshd.system.DroidSSHdService.class);
mHandler.postDelayed(mUpdateUI, 150);
}
 
@Override
Loading
Loading
@@ -99,8 +102,8 @@ public class DroidSSHd extends Activity {
 
@Override
protected void onDestroy() {
super.onDestroy();
doUnbindDaemonHandlerService(mDropbearDaemonHandlerService);
super.onDestroy();
}
 
@Override
Loading
Loading
@@ -155,11 +158,13 @@ public class DroidSSHd extends Activity {
Log.v(TAG, "btnStartStop pressed: stopping");
}
stopDropbear();
mHandler.postDelayed(mUpdateUI, 2000);
} else {
if(Base.debug) {
Log.v(TAG, "btnStartStop pressed: starting");
}
startDropbear();
mHandler.postDelayed(mUpdateUI, 1000);
}
// setResult(android.app.Activity.RESULT_OK);
}
Loading
Loading
@@ -190,12 +195,16 @@ public class DroidSSHd extends Activity {
public void updateStatus() {
String tmp = "";
Iterator<String> ipAddr = Util.getLocalIpAddress();
try {
while(ipAddr.hasNext()) {
tmp = tmp + ipAddr.next() + " ";
if (ipAddr.hasNext()) {
tmp = tmp + ", ";
}
}
} catch (Exception e) {
Log.w(TAG, "updateStatus() exception in IpAddress Iterator");
}
status_ip_address.setText(tmp);
status_username.setText(Base.getUsername());
status_tcp_port.setText(String.valueOf(Base.getDaemonPort()));
Loading
Loading
@@ -233,12 +242,20 @@ public class DroidSSHd extends Activity {
status_content.setText("Stopped");
break;
 
case Base.DAEMON_STATUS_UNKNOWN:
btnStartStop.setEnabled(true);
btnStartStop.setFocusable(true);
btnStartStop.setText("Start");
status_content.setText("Unknown");
break;
default:
break;
}
}
 
public void startDropbear() {
doBindDaemonHandlerService(mDropbearDaemonHandlerService);
if (!Util.checkPathToBinaries()) {
if(Base.debug) {
Log.v(TAG, "startDropbear bailing out: status was " + Base.getDropbearDaemonStatus() + ", changed to STOPPED(" + ")" );
Loading
Loading
@@ -257,7 +274,7 @@ public class DroidSSHd extends Activity {
Util.showMsg("Host keys not found");
return;
}
if(Base.getDropbearDaemonStatus() == Base.DAEMON_STATUS_STOPPED) {
if(Base.getDropbearDaemonStatus() <= Base.DAEMON_STATUS_STOPPED) {
Base.setDropbearDaemonStatus(Base.DAEMON_STATUS_STARTING);
if (Base.debug) {
Log.d(TAG, "Status was STOPPED, now it's STARTING");
Loading
Loading
@@ -402,6 +419,7 @@ public class DroidSSHd extends Activity {
};
 
private void doBindDaemonHandlerService(Intent intent) {
Base.setManualServiceStart(true);
mDaemonHandlerIsBound = bindService(intent, mDaemonHandlerConnection, Context.BIND_AUTO_CREATE);
}
 
Loading
Loading
Loading
Loading
@@ -180,6 +180,7 @@ public class InitialSetup extends Activity {
}
 
protected boolean setupDirectoryStructure() {
try {
// files/bin - binaries
Util.mkdir(Base.getDropbearBinDirPath());
Util.chmod(Base.getDropbearBinDirPath(), 0755);
Loading
Loading
@@ -189,6 +190,13 @@ public class InitialSetup extends Activity {
// files/etc - authorized pubkeys and host keys
Util.mkdir(Base.getDropbearEtcDirPath());
Util.chmod(Base.getDropbearEtcDirPath(), 0700);
} catch (Exception e) {
Log.e(TAG, "Exception in Setup Directory Structure", e);
return false;
} catch (UnsatisfiedLinkError er) {
Log.e(TAG, "Exception in Setup Directory Structure", er);
return false;
}
return true;
}
 
Loading
Loading
Loading
Loading
@@ -58,6 +58,7 @@ public class Base {
 
public static boolean debug;
protected static int daemonPort;
protected static boolean manualServiceStart = true;
protected static boolean runDaemonAsRoot;
protected static boolean startedAsRoot;
protected static boolean startAtBoot;
Loading
Loading
@@ -92,6 +93,20 @@ public class Base {
return startAtBootOnlyIfRunningBefore;
}
 
public static boolean manualServiceStart() {
return manualServiceStart;
}
public static void setManualServiceStart(boolean b) {
manualServiceStart = b;
if (debug) {
if (b)
Log.d(TAG, "setManualServiceStart = 1");
else
Log.d(TAG, "setManualServiceStart = 0");
}
}
public static boolean runDaemonAsRoot() {
return runDaemonAsRoot;
}
Loading
Loading
Loading
Loading
@@ -23,6 +23,7 @@ import android.util.Log;
public class BootReceiver extends BroadcastReceiver {
 
private static final String TAG = "DroidSSHdBootReceiver";
private BootReceiver inst = this;
 
@Override
public void onReceive(Context context, Intent intent) {
Loading
Loading
@@ -61,6 +62,12 @@ public class BootReceiver extends BroadcastReceiver {
Log.d(TAG, "dropbear daemon configured to NOT start on boot");
}
}
try {
context.unregisterReceiver(inst);
} catch (Exception e) {
Log.w(TAG, "unable to unregister BOOT_COMPLETED broadcast receiver");
}
}
}
}
Loading
Loading
Loading
Loading
@@ -43,6 +43,8 @@ public class DroidSSHdService extends Service{
// lock to handle (synchronized) FileObserver calls
private static Object sLock = new Object();
 
private static boolean serviceManualStartup = true;
public boolean isDaemonRunning() {
return dropbearDaemonRunning;
}
Loading
Loading
@@ -54,9 +56,11 @@ public class DroidSSHdService extends Service{
// TODO - i.e. this SVC was started on boot and DroidSSHd activity hasn't run just yet
// TODO - (is it the same ctx? is it null? etc...)
Base.initialize(getBaseContext());
serviceManualStartup = Base.manualServiceStart();
mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
if (Base.debug) {
Log.d(TAG, "onCreate called");
if (serviceManualStartup) Log.d(TAG, "ManualServiceStart");
}
}
 
Loading
Loading
@@ -65,6 +69,10 @@ public class DroidSSHdService extends Service{
if (Base.debug) {
Log.d(TAG, "onStart(" + intent.toString() + ", " + startId + ") called");
}
if (!Base.startDaemonAtBoot() && !Base.manualServiceStart()) {
stopSelf();
return;
}
handleStart(intent, 0, startId);
}
 
Loading
Loading
@@ -73,8 +81,14 @@ public class DroidSSHdService extends Service{
if (Base.debug) {
Log.d(TAG, "onStart(" + intent.toString() + ", " + flags + ", " + startId + ") called");
}
super.onStartCommand(intent, flags, startId);
int sticky=Service.START_STICKY;
serviceManualStartup = Base.manualServiceStart();
if (!Base.startDaemonAtBoot() && !serviceManualStartup) {
sticky=Service.START_NOT_STICKY;
}
handleStart(intent, flags, startId);
return Service.START_STICKY;
return sticky;
}
private void handleStart(Intent intent, int flags, int startId) {
Loading
Loading
@@ -213,6 +227,7 @@ public class DroidSSHdService extends Service{
@Override
public void onEvent(int event, String path) {
synchronized(sLock) {
try {
switch (event) {
case FileObserver.CREATE:
Base.setDropbearDaemonStatus(Base.DAEMON_STATUS_STARTING);
Loading
Loading
@@ -250,6 +265,10 @@ public class DroidSSHdService extends Service{
}
break;
}
} catch (Exception e) {
Log.e(TAG, "Exception in createPidWatchdog", e);
e.printStackTrace();
}
}
}
};
Loading
Loading
@@ -309,6 +328,7 @@ public class DroidSSHdService extends Service{
if(Base.debug) {
Log.d(TAG+"-updateDaemonStatus", "started");
}
try {
dropbearDaemonProcessId = Util.getDropbearPidFromPidFile(Base.getDropbearPidFilePath());
if (dropbearDaemonProcessId!=0) {
dropbearDaemonRunning = Util.isDropbearDaemonRunning();
Loading
Loading
@@ -321,6 +341,11 @@ public class DroidSSHdService extends Service{
} else {
Base.setDropbearDaemonStatus(Base.DAEMON_STATUS_STOPPED);
hideNotification();
}
} catch (Exception e) {
Log.e(TAG, "Exception in updateDaemonStatus", e);
e.printStackTrace();
Base.setDropbearDaemonStatus(Base.DAEMON_STATUS_UNKNOWN);
}
}
}
Loading
Loading
Loading
Loading
@@ -364,17 +364,23 @@ public class Util {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
try {
if (!inetAddress.isLoopbackAddress()) {
if (Base.debug) {
Log.v(TAG, "Interface " + intf.getDisplayName() + ", IPaddress " + inetAddress.getHostAddress().toString() );
}
ipAddr.add(inetAddress.getHostAddress().toString());
}
} catch (Exception e) {
Log.e(TAG, e.toString());
return null;
}
}
}
} catch (SocketException ex) {
Log.e(TAG, ex.toString());
return null;
ex.printStackTrace();
return ipAddr.iterator();
}
return ipAddr.iterator();
}
Loading
Loading
Loading
Loading
@@ -54,7 +54,7 @@ public class FileArrayAdapter extends ArrayAdapter<Option>{
t1.setText(o.getName());
if(t2!=null) {
t2.setText(o.getData());
if (o.getData().equalsIgnoreCase("folder")) {
if (o.getData().equalsIgnoreCase("folder")||o.getData().equalsIgnoreCase("parent directory")) {
i.setImageResource(R.drawable.directory_icon);
// i.setVisibility(View.VISIBLE);
} else {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment