From bc0d94ad4f4102b63813655ef86e0d3d08b6b1c5 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Fri, 26 Feb 2021 16:25:38 +0100 Subject: fix potential Nullpointer exception when calling VpnService.prepare() --- .../java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/se') diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java index 6d6b24c8..e2cd86b9 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java @@ -5,6 +5,9 @@ import android.content.Intent; import android.net.VpnService; import android.os.Bundle; +import static se.leap.bitmaskclient.base.models.Constants.EIP_ACTION_PREPARE_VPN; +import static se.leap.bitmaskclient.eip.EipResultBroadcast.tellToReceiverOrBroadcast; + public class VoidVpnLauncher extends Activity { private static final int VPN_USER_PERMISSION = 71; @@ -16,9 +19,16 @@ public class VoidVpnLauncher extends Activity { } public void setUp() { - Intent blocking_intent = VpnService.prepare(getApplicationContext()); // stops the VPN connection created by another application. - if (blocking_intent != null) - startActivityForResult(blocking_intent, VPN_USER_PERMISSION); + Intent blockingIntent = null; + try { + blockingIntent = VpnService.prepare(getApplicationContext()); // stops the VPN connection created by another application. + } catch (NullPointerException npe) { + tellToReceiverOrBroadcast(this.getApplicationContext(), EIP_ACTION_PREPARE_VPN, RESULT_CANCELED); + finish(); + } + if (blockingIntent != null) { + startActivityForResult(blockingIntent, VPN_USER_PERMISSION); + } else { EipCommand.startBlockingVPN(getApplicationContext()); } -- cgit v1.2.3