add "Start on Open" option that makes the activity start the service, and

stopping the service ends the activity
sigsegv_dump
Greg Alexander 8 years ago
parent 14a9812c85
commit c9b8494352

16
NOTES

@ -341,6 +341,22 @@ overnight drain.
So, in case someone does have problems with it, I am making it an option
that defaults to enabled.
Looking through email, I haven't seen any, but I have the idea several
users have asked for a notification icon in the past. And now that that
is finally implemented, I am curious about other things people have
requested that I have not been keen on. And Jan Ondrej's requests come
to mind:
o) setting to start the service automatically when the application is
launched
o) QUIT button that stops the service and the activity at once
o) not allow wifi to power down when the activity is open
I'm really not crazy about integrating any kind of wakelock. And QUIT
still seems silly to me. But with the notification there, the idea that
someone will micromanage whether the service is running or not does not
seem so far fetched.
So I'll go ahead and add "Start on Open" setting.
XXX - make clicking on the notification go to the app?

@ -58,6 +58,13 @@ On newer versions of Android (since Marshmallow), this may also make
SimpleSSHD more responsive if the phone has been in Doze mode. It does
not seem to increase battery consumption much.</dd>
<dt>Start on Open</dt>
<dd>Run the SimpleSSHD service whenever the app is launched. The "STOP"
button will be replaced with a "QUIT" button that stops the service and
exits the app. This is useful if you want to only run the service when
you really need it -- start the app to start listening for connections,
and then click "QUIT" when you are done.</dd>
<dt>Port Number</dt>
<dd>This is the port number that SimpleSSHD will listen on. It must be
greater than 1024 (because SimpleSSHD does not have root).</dd>

@ -9,6 +9,11 @@
android:title="Foreground Service"
android:summary="Enable a notification while running, and run with more priority (especially in Doze mode)."
android:defaultValue="true" />
<CheckBoxPreference
android:key="onopen"
android:title="Start on Open"
android:summary="Start the service when the app is launched (and quit app when stopping service)"
android:defaultValue="false" />
<EditTextPreference
android:key="port"
android:title="Port Number"

@ -19,6 +19,9 @@ public class Prefs {
public static boolean get_foreground() {
return pref.getBoolean("foreground", true);
}
public static boolean get_onopen() {
return pref.getBoolean("onopen", false);
}
public static boolean get_rsyncbuffer() {
return pref.getBoolean("rsyncbuffer", false);
}

@ -57,6 +57,10 @@ public class SimpleSSHD extends Activity
updater = new UpdaterThread();
updater.start();
ip_view.setText(get_ip());
if (Prefs.get_onopen() && !SimpleSSHDService.is_started()) {
startService(new Intent(this, SimpleSSHDService.class));
}
}
public void onPause() {
@ -108,7 +112,8 @@ public class SimpleSSHD extends Activity
private void update_startstop_prime() {
if (SimpleSSHDService.is_started()) {
startstop_view.setText("STOP");
startstop_view.setText(
Prefs.get_onopen() ? "QUIT" : "STOP");
startstop_view.setTextColor(0xFF881111);
} else {
startstop_view.setText("START");
@ -134,11 +139,15 @@ public class SimpleSSHD extends Activity
}
public void startstop_clicked(View v) {
boolean already_started = SimpleSSHDService.is_started();
Intent i = new Intent(this, SimpleSSHDService.class);
if (SimpleSSHDService.is_started()) {
if (already_started) {
i.putExtra("stop", true);
}
startService(i);
if (already_started && Prefs.get_onopen()) {
finish();
}
}
private void update_log_prime() {

Loading…
Cancel
Save