BootBroadcastReceiver: fix crash on Android 8+

This commit is contained in:
PeratX 2019-11-20 13:21:32 +08:00
parent 417408105a
commit 2067ef5d07
2 changed files with 6 additions and 2 deletions

View File

@ -210,9 +210,13 @@ public class Daedalus extends Application {
}
public static void activateService(Context context) {
activateService(context, false);
}
public static void activateService(Context context, boolean forceForeground) {
DaedalusVpnService.primaryServer = (AbstractDnsServer) DnsServerHelper.getServerById(DnsServerHelper.getPrimary()).clone();
DaedalusVpnService.secondaryServer = (AbstractDnsServer) DnsServerHelper.getServerById(DnsServerHelper.getSecondary()).clone();
if (getInstance().prefs.getBoolean("settings_foreground", false)
if ((getInstance().prefs.getBoolean("settings_foreground", false) || forceForeground)
&& Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
Logger.info("Starting foreground service");
context.startForegroundService(Daedalus.getServiceIntent(context).setAction(DaedalusVpnService.ACTION_ACTIVATE));

View File

@ -21,7 +21,7 @@ public class BootBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Daedalus.getPrefs().getBoolean("settings_boot", false)) {
Daedalus.activateService(context);
Daedalus.activateService(context, true);
Logger.info("Triggered boot receiver");
}
}