1
0
mirror of http://galexander.org/git/simplesshd.git synced 2024-11-14 02:59:05 +00:00

implemented startForeground(), with some reservation

This commit is contained in:
Greg Alexander 2016-10-01 17:35:41 -04:00
parent a2b14e405c
commit ae7703fad0
3 changed files with 81 additions and 10 deletions

69
NOTES
View File

@ -245,8 +245,69 @@ all of the off_t to off64_t and hope for the best.
sftp and rsync work! Not gonna bother testing scp on big files...
XXX - Jared Stafford says startForeground() improves responsiveness
substantially on Nkey Lime Pie
October 1, 2016.
XXX - if you remove it from the recent apps list, does it stop the service??
XXX - support password-based logins?
Jared Stafford told me startForeground() improves responsiveness on
Nougat. There had been a comment suggesting startForeground(), but I
never got around to trying it because it has worked "well enough". With
Nougat, though, there is a definite tendency for SimpleSSHD to be
non-responsive. I'm not sure exactly what its cause is, but the symptom
I notice most frequently is that the first ssh connection after a while
will be delayed "a long time" - on the order of 10-30 seconds, or maybe
indefinitely sometimes. Oddly, a second connection can sometimes get
through undelayed, even before the first connection does. It is as if
the fork() of process for the new connection is where the delay is, not
in the listen() call.
That's not overall too surprising, Nougat is a lot harsher about
background processes as part of a Google push to reduce power consumption
on idle devices.
Another concern is related to a change back in July - sometimes the
system will kill the sshd process for no good reason (maybe because they
removed it from the recent apps list). The remedy I settled on was to
monitor for the sshd process dying from within the regular
Android-managed process, and restart it. I guess I didn't write down
where in the documentation I found it, but Android seems expressly
antagonistic to non-system-managed processes. If they ever get more
hard-assed about that, this whole idea goes out the window.
Anyways, I implemented startForeground(), and I am unhappy that it
requires a Notification. At API 7 (Android 2.1) those are really
primitive. For example, the PRIORITY_MIN behavior which will sometimes
hide the notification is added in API 16 (Android 4.1). So, I've got it
with this stupid old-style notification, and it really doesn't look good,
and it is always present. That is not awesome.
On the other hand, it's easy to block the notifications, and a few people
have expressed an interest in a notification.
It doesn't seem worth it to me to upgrade to a newer API just for the
better notifications... On the other hand, Google Play shows that I have
862 users:
Android 7+ : 3.13%
Android 6+ : 37.47%
Android 5+ : 67.86%
Android 4.1+: 96.62%
Android 4.0+: 98.01%
The oldest reported version is Android 2.3.
So, there are a few people on very old versions, but actually SimpleSSHD
is used on newer devices than the average app, which is the reverse of my
typical trend. So a few people would be negatively impacted, but not a
very large number. I could switch to multi-APK mode so that legacy users
are just stuck with an unsupported back-version, which is probably what
they truly want anyways..
Anyways, I'm gonna use it with startForeground() and the notifications
disabled for a while, and if I find it to be an improvement then I'll
just make it so clicking on the notification goes to the app, update the
doc, and then publish it.
XXX - make clicking on the notification go to the app?
XXX - support password-based logins for boot-strapping?

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -1,5 +1,6 @@
package org.galexander.sshd;
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.content.Context;
@ -31,15 +32,12 @@ public class SimpleSSHDService extends Service {
if ((intent == null) ||
(!intent.getBooleanExtra("stop", false))) {
do_start();
/* XXX - maybe we should call startForeground(), but then we'd have to make a
* bogus notification... and START_STICKY seems to actually do a good job of
* restarting us if we're killed... */
do_foreground();
return START_STICKY;
} else {
stop_sshd();
stop_service();
SimpleSSHD.update_startstop();
stopSelf();
/* XXX - need stopForeground() too ? */
return START_NOT_STICKY;
}
}
@ -52,10 +50,17 @@ public class SimpleSSHDService extends Service {
* the package is upgraded... so it's really pretty useless */
public void onDestroy() {
stop_sshd();
stopSelf();
stop_service();
super.onDestroy();
}
private void do_foreground() {
Notification n = new Notification(R.drawable.notification_icon,
"SimpleSSHD", 0);
n.tickerText = "SimpleSSHD";
startForeground(1, n);
}
public static boolean is_started() {
return (sshd_pid != 0);
}
@ -71,6 +76,11 @@ public class SimpleSSHDService extends Service {
}
}
private void stop_service() {
stopSelf();
stopForeground(true);
}
private static void maybe_restart(int pid) {
boolean do_restart = false;
long now = System.currentTimeMillis();