From 83b5dd496d1ee5ec4919d811b28a8a198c72b07e Mon Sep 17 00:00:00 2001 From: Greg Alexander Date: Sun, 9 Jun 2019 15:50:49 -0400 Subject: [PATCH] If asked to start at boot in background on Oreo, give a toast so the user knows why it doesn't work. --- .../main/java/org/galexander/sshd/BootReceiver.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/galexander/sshd/BootReceiver.java b/app/src/main/java/org/galexander/sshd/BootReceiver.java index 0cb65ae..f1ce149 100644 --- a/app/src/main/java/org/galexander/sshd/BootReceiver.java +++ b/app/src/main/java/org/galexander/sshd/BootReceiver.java @@ -4,15 +4,21 @@ import android.content.BroadcastReceiver; import android.content.Intent; import android.content.Context; import android.os.Build; +import android.widget.Toast; + public class BootReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { Prefs.init(context); if (Prefs.get_onboot()) { Intent i = new Intent(context, SimpleSSHDService.class); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - /* Oreo won't allow a background service here */ + if (Prefs.get_foreground()) { context.startForegroundService(i); + } else if (Build.VERSION.SDK_INT >= + Build.VERSION_CODES.O) { + Toast.makeText(context, +"SimpleSSHD cannot start background at boot since Oreo (see Settings).", + Toast.LENGTH_LONG).show(); } else { context.startService(i); }