diff --git a/NOTES b/NOTES index 2e2b987..46187fc 100644 --- a/NOTES +++ b/NOTES @@ -72,6 +72,8 @@ it uses select(), I'm not sure how I would honor Thread.interrupt() or whatever. It's not guaranteed to interrupt select(), and I'm not keen on adding an arbitrary timeout/polling feature to it. +XXX - add locking on access to SimpleSSHD.curr +XXX - test scrolling the log XXX - implement extra commandline for dropbear XXX - main screen should show dropbear.err contents XXX - implement start on boot diff --git a/src/org/galexander/sshd/SimpleSSHD.java b/src/org/galexander/sshd/SimpleSSHD.java index 6d8a8f4..1cf0e6b 100644 --- a/src/org/galexander/sshd/SimpleSSHD.java +++ b/src/org/galexander/sshd/SimpleSSHD.java @@ -22,6 +22,7 @@ public class SimpleSSHD extends Activity private TextView log_view; private Button startstop_view; public static SimpleSSHD curr = null; + private UpdaterThread updater = null; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -33,13 +34,15 @@ public class SimpleSSHD extends Activity public void onResume() { super.onResume(); - update_startstop(); - update_log(); curr = this; + update_startstop(); + updater = new UpdaterThread(); + updater.start(); } public void onPause() { curr = null; + updater.interrupt(); super.onPause(); } diff --git a/src/org/galexander/sshd/UpdaterThread.java b/src/org/galexander/sshd/UpdaterThread.java new file mode 100644 index 0000000..6ccf8a9 --- /dev/null +++ b/src/org/galexander/sshd/UpdaterThread.java @@ -0,0 +1,39 @@ +package org.galexander.sshd; + +import java.io.File; + +public class UpdaterThread extends Thread { + /* poll for changes to the dropbear.err file */ + public void run() { + File f = new File(Prefs.get_path(), "dropbear.err"); + long lastmod = 0; +System.out.println("sshd: updater start"); + while (true) { + if (isInterrupted()) { +System.out.println("sshd: updater interrupted"); + break; + } + if (SimpleSSHD.curr == null) { +System.out.println("sshd: activity stopped"); + break; + } + long l = f.lastModified(); + if (l != lastmod) { +System.out.println("sshd: updating"); + SimpleSSHD.curr.runOnUiThread(new Thread() { + public void run() { + SimpleSSHD.curr.update_log(); + } + }); + lastmod = l; + } + try { + sleep(1000); + } catch (InterruptedException e) { +System.out.println("sshd: sleep interrupted"); + break; + } + } +System.out.println("sshd: done"); + } +}