diff options
Diffstat (limited to 'main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java')
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java index a4b7b480..42199a8a 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -57,6 +57,8 @@ import de.blinkt.openvpn.core.VpnStatus.ByteCountListener; import de.blinkt.openvpn.core.VpnStatus.StateListener; import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_CONNECTED; +import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_CONNECTING_NO_SERVER_REPLY_YET; +import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_START; import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT; import static de.blinkt.openvpn.core.NetworkSpace.ipAddress; @@ -253,6 +255,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac int notificationId = channel.hashCode(); mNotificationManager.notify(notificationId, notification); + startForeground(notificationId, notification); if (lastChannel != null && !channel.equals(lastChannel)) { @@ -467,6 +470,12 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac return START_REDELIVER_INTENT; } + // Always show notification here to avoid problem with startForeground timeout + VpnStatus.logInfo(R.string.building_configration); + VpnStatus.updateStateString("VPN_GENERATE_CONFIG", "", R.string.building_configration, ConnectionStatus.LEVEL_START); + showNotification(VpnStatus.getLastCleanLogMessage(this), + VpnStatus.getLastCleanLogMessage(this), NOTIFICATION_CHANNEL_NEWSTATUS_ID, 0, ConnectionStatus.LEVEL_START); + if (intent != null && intent.hasExtra(getPackageName() + ".profileUUID")) { String profileUUID = intent.getStringExtra(getPackageName() + ".profileUUID"); int profileVersion = intent.getIntExtra(getPackageName() + ".profileVersion", 0); @@ -495,6 +504,12 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac mProfile.checkForRestart(this); } + if (mProfile == null) { + stopSelf(startId); + return START_NOT_STICKY; + } + + /* start the OpenVPN process itself in a background thread */ new Thread(new Runnable() { @Override @@ -519,10 +534,6 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac } private void startOpenVPN() { - VpnStatus.logInfo(R.string.building_configration); - VpnStatus.updateStateString("VPN_GENERATE_CONFIG", "", R.string.building_configration, ConnectionStatus.LEVEL_START); - - try { mProfile.writeConfigFile(this); } catch (IOException e) { |