BootBroadcastReceiver: fix crash on Android 8+
This commit is contained in:
parent
417408105a
commit
2067ef5d07
@ -210,9 +210,13 @@ public class Daedalus extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void activateService(Context context) {
|
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.primaryServer = (AbstractDnsServer) DnsServerHelper.getServerById(DnsServerHelper.getPrimary()).clone();
|
||||||
DaedalusVpnService.secondaryServer = (AbstractDnsServer) DnsServerHelper.getServerById(DnsServerHelper.getSecondary()).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) {
|
&& Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
|
||||||
Logger.info("Starting foreground service");
|
Logger.info("Starting foreground service");
|
||||||
context.startForegroundService(Daedalus.getServiceIntent(context).setAction(DaedalusVpnService.ACTION_ACTIVATE));
|
context.startForegroundService(Daedalus.getServiceIntent(context).setAction(DaedalusVpnService.ACTION_ACTIVATE));
|
||||||
|
@ -21,7 +21,7 @@ public class BootBroadcastReceiver extends BroadcastReceiver {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (Daedalus.getPrefs().getBoolean("settings_boot", false)) {
|
if (Daedalus.getPrefs().getBoolean("settings_boot", false)) {
|
||||||
Daedalus.activateService(context);
|
Daedalus.activateService(context, true);
|
||||||
Logger.info("Triggered boot receiver");
|
Logger.info("Triggered boot receiver");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user