summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard/android/backend
diff options
context:
space:
mode:
authorEric Kuck <eric@bluelinelabs.com>2018-07-12 19:10:35 -0500
committerJason A. Donenfeld <Jason@zx2c4.com>2018-07-13 03:46:23 +0200
commit67ea8b2936343526ff0b3f476c515f0e11dbb272 (patch)
tree84f904d66f6111a7d8f897164eb236bc62199cae /app/src/main/java/com/wireguard/android/backend
parentfbaa4d9ab1b59ba4610fe273743872f35e7e9091 (diff)
global: Add nullity annotations
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/backend')
-rw-r--r--app/src/main/java/com/wireguard/android/backend/GoBackend.java10
-rw-r--r--app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java7
2 files changed, 12 insertions, 5 deletions
diff --git a/app/src/main/java/com/wireguard/android/backend/GoBackend.java b/app/src/main/java/com/wireguard/android/backend/GoBackend.java
index 66d3698f..a075913f 100644
--- a/app/src/main/java/com/wireguard/android/backend/GoBackend.java
+++ b/app/src/main/java/com/wireguard/android/backend/GoBackend.java
@@ -10,6 +10,7 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.ParcelFileDescriptor;
+import android.support.annotation.Nullable;
import android.support.v4.util.ArraySet;
import android.util.Log;
@@ -29,6 +30,7 @@ import com.wireguard.crypto.KeyEncoding;
import java.net.InetAddress;
import java.util.Collections;
import java.util.Formatter;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -40,7 +42,7 @@ public final class GoBackend implements Backend {
private static CompletableFuture<VpnService> vpnService = new CompletableFuture<>();
private final Context context;
- private Tunnel currentTunnel;
+ @Nullable private Tunnel currentTunnel;
private int currentTunnelHandle = -1;
public GoBackend(final Context context) {
@@ -114,12 +116,14 @@ public final class GoBackend implements Backend {
return getState(tunnel);
}
- private void setStateInternal(final Tunnel tunnel, final Config config, final State state)
+ private void setStateInternal(final Tunnel tunnel, @Nullable final Config config, final State state)
throws Exception {
if (state == State.UP) {
Log.i(TAG, "Bringing tunnel up");
+ Objects.requireNonNull(config, "Trying to bring up a tunnel with no config");
+
if (VpnService.prepare(context) != null)
throw new Exception("VPN service not authorized by user");
@@ -245,7 +249,7 @@ public final class GoBackend implements Backend {
}
@Override
- public int onStartCommand(final Intent intent, final int flags, final int startId) {
+ public int onStartCommand(@Nullable final Intent intent, final int flags, final int startId) {
vpnService.complete(this);
if (intent == null || intent.getComponent() == null || !intent.getComponent().getPackageName().equals(getPackageName())) {
Log.d(TAG, "Service started by Always-on VPN feature");
diff --git a/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java b/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
index fbc43dc0..25634841 100644
--- a/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
+++ b/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
@@ -7,6 +7,7 @@
package com.wireguard.android.backend;
import android.content.Context;
+import android.support.annotation.Nullable;
import android.util.Log;
import com.wireguard.android.Application;
@@ -21,6 +22,7 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
import java9.util.stream.Collectors;
@@ -106,8 +108,9 @@ public final class WgQuickBackend implements Backend {
return getState(tunnel);
}
- private void setStateInternal(final Tunnel tunnel, final Config config, final State state)
- throws Exception {
+ private void setStateInternal(final Tunnel tunnel, @Nullable final Config config, final State state) throws Exception {
+ Objects.requireNonNull(config, "Trying to set state with a null config");
+
final File tempFile = new File(localTemporaryDir, tunnel.getName() + ".conf");
try (final FileOutputStream stream = new FileOutputStream(tempFile, false)) {
stream.write(config.toString().getBytes(StandardCharsets.UTF_8));