Start foreground service early

Android will force kill the service when this is not done timely
This commit is contained in:
M66B 2017-08-03 09:57:52 +02:00
parent 9e0e816786
commit 2e836b1266
1 changed files with 5 additions and 0 deletions

View File

@ -2288,6 +2288,9 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (state == State.none)
startForeground(NOTIFY_WAITING, getWaitingNotification());
Log.i(TAG, "Received " + intent);
Util.logExtras(intent);
@ -2295,6 +2298,8 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
if (intent != null && intent.hasExtra(EXTRA_COMMAND) &&
intent.getSerializableExtra(EXTRA_COMMAND) == Command.set) {
set(intent);
if (state == State.none)
stopForeground(true);
return START_STICKY;
}