summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2021-02-26 16:25:38 +0100
committercyBerta <cyberta@riseup.net>2021-02-26 16:25:38 +0100
commitbc0d94ad4f4102b63813655ef86e0d3d08b6b1c5 (patch)
tree4e566ffc5a70a8edb0d7a29a99217741c2f9f86f
parenteadc74a7e0a99e31044a369508efbbab9d7295f6 (diff)
fix potential Nullpointer exception when calling VpnService.prepare()
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java16
1 files changed, 13 insertions, 3 deletions
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());
}