From 973e2f29c3a7948104320dde7c184ca56db4c021 Mon Sep 17 00:00:00 2001 From: Robin Lee Date: Mon, 11 Apr 2016 11:23:10 +0100 Subject: Handle case where profileUUID is missing Android NYC+ might start the VPN service on its own without any useful intent extras saying which profile to load. Handle it the same as the restart case -- use the most recent profile instead of crashing. --- main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 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 536abdc2..ef397fa8 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -358,8 +358,11 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac return START_REDELIVER_INTENT; } - /* The intent is null when the service has been restarted */ - if (intent == null) { + if (intent != null && intent.hasExtra(getPackageName() + ".profileUUID")) { + String profileUUID = intent.getStringExtra(getPackageName() + ".profileUUID"); + mProfile = ProfileManager.get(this, profileUUID); + } else { + /* The intent is null when we are set as always-on or the service has been restarted. */ mProfile = ProfileManager.getLastConnectedProfile(this, false); VpnStatus.logInfo(R.string.service_restarted); @@ -374,10 +377,6 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac /* Recreate the intent */ intent = mProfile.getStartServiceIntent(this); - - } else { - String profileUUID = intent.getStringExtra(getPackageName() + ".profileUUID"); - mProfile = ProfileManager.get(this, profileUUID); } /* start the OpenVPN process itself in a background thread */ -- cgit v1.2.3