make the foreground service an option

sigsegv_dump
Greg Alexander 8 years ago
parent 484094d064
commit 3da61bfa96

11
NOTES

@ -331,6 +331,17 @@ get wedged, it might even be a flaw in Dropbear that makes it so
unreliable with Nougat.
October 16, 2016.
I've been using a foreground service for a while, and it has not caused
me any troubles. The thing I have been most anxious about is that it
might disable doze mode entirely...but there has not been any noteworthy
overnight drain.
So, in case someone does have problems with it, I am making it an option
that defaults to enabled.
XXX - make clicking on the notification go to the app?
XXX - support password-based logins for boot-strapping?

@ -4,6 +4,11 @@
android:key="onboot"
android:title="Start on Boot"
android:defaultValue="false" />
<CheckBoxPreference
android:key="foreground"
android:title="Foreground service"
android:summary="Enable a notification while running, and run with more priority (especially in Doze mode)."
android:defaultValue="true" />
<EditTextPreference
android:key="port"
android:title="Port Number"

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

@ -17,6 +17,7 @@ public class SimpleSSHDService extends Service {
private static int sshd_pid = 0;
private static long sshd_when = 0;
private static long sshd_duration = 0;
private static boolean foregrounded = false;
public void onCreate() {
super.onCreate();
@ -55,10 +56,14 @@ public class SimpleSSHDService extends Service {
}
private void do_foreground() {
Notification n = new Notification(R.drawable.notification_icon,
"SimpleSSHD", 0);
n.tickerText = "SimpleSSHD";
startForeground(1, n);
foregrounded = Prefs.get_foreground();
if (foregrounded) {
Notification n = new Notification(
R.drawable.notification_icon,
"SimpleSSHD", 0);
n.tickerText = "SimpleSSHD";
startForeground(1, n);
}
}
public static boolean is_started() {
@ -78,7 +83,10 @@ public class SimpleSSHDService extends Service {
private void stop_service() {
stopSelf();
stopForeground(true);
if (foregrounded) {
stopForeground(true);
foregrounded = false;
}
}
private static void maybe_restart(int pid) {

Loading…
Cancel
Save