summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard/android/util
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/util
parentfbaa4d9ab1b59ba4610fe273743872f35e7e9091 (diff)
global: Add nullity annotations
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/util')
-rw-r--r--app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java6
-rw-r--r--app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java16
-rw-r--r--app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java10
-rw-r--r--app/src/main/java/com/wireguard/android/util/RootShell.java11
-rw-r--r--app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java3
-rw-r--r--app/src/main/java/com/wireguard/android/util/ToolsInstaller.java8
6 files changed, 28 insertions, 26 deletions
diff --git a/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java b/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java
index b8c0c4fa..70d97fb1 100644
--- a/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java
+++ b/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java
@@ -6,8 +6,9 @@
package com.wireguard.android.util;
-import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import android.util.Log;
+
import java9.util.concurrent.CompletionException;
import java9.util.function.BiConsumer;
@@ -34,7 +35,6 @@ public enum ExceptionLoggers implements BiConsumer<Object, Throwable> {
return throwable;
}
- @NonNull
public static String unwrapMessage(Throwable throwable) {
throwable = unwrap(throwable);
final String message = throwable.getMessage();
@@ -44,7 +44,7 @@ public enum ExceptionLoggers implements BiConsumer<Object, Throwable> {
}
@Override
- public void accept(final Object result, final Throwable throwable) {
+ public void accept(final Object result, @Nullable final Throwable throwable) {
if (throwable != null)
Log.println(Log.ERROR, TAG, Log.getStackTraceString(throwable));
else if (priority <= Log.DEBUG)
diff --git a/app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java b/app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java
index 1e064e42..0be3c005 100644
--- a/app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java
+++ b/app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java
@@ -7,7 +7,7 @@
package com.wireguard.android.util;
import android.databinding.ObservableArrayList;
-import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import com.wireguard.util.Keyed;
@@ -25,28 +25,28 @@ import java.util.Objects;
public class ObservableKeyedArrayList<K, E extends Keyed<? extends K>>
extends ObservableArrayList<E> implements ObservableKeyedList<K, E> {
@Override
- public boolean add(final E e) {
+ public boolean add(@Nullable final E e) {
if (e == null)
throw new NullPointerException("Trying to add a null element");
return super.add(e);
}
@Override
- public void add(final int index, final E e) {
+ public void add(final int index, @Nullable final E e) {
if (e == null)
throw new NullPointerException("Trying to add a null element");
super.add(index, e);
}
@Override
- public boolean addAll(@NonNull final Collection<? extends E> c) {
+ public boolean addAll(final Collection<? extends E> c) {
if (c.contains(null))
throw new NullPointerException("Trying to add a collection with null element(s)");
return super.addAll(c);
}
@Override
- public boolean addAll(final int index, @NonNull final Collection<? extends E> c) {
+ public boolean addAll(final int index, final Collection<? extends E> c) {
if (c.contains(null))
throw new NullPointerException("Trying to add a collection with null element(s)");
return super.addAll(index, c);
@@ -65,13 +65,13 @@ public class ObservableKeyedArrayList<K, E extends Keyed<? extends K>>
return indexOfKey(key) >= 0;
}
- @Override
+ @Override @Nullable
public E get(final K key) {
final int index = indexOfKey(key);
return index >= 0 ? get(index) : null;
}
- @Override
+ @Override @Nullable
public E getLast(final K key) {
final int index = lastIndexOfKey(key);
return index >= 0 ? get(index) : null;
@@ -100,7 +100,7 @@ public class ObservableKeyedArrayList<K, E extends Keyed<? extends K>>
}
@Override
- public E set(final int index, final E e) {
+ public E set(final int index, @Nullable final E e) {
if (e == null)
throw new NullPointerException("Trying to set a null key");
return super.set(index, e);
diff --git a/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java b/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java
index 4ff3a771..239520c4 100644
--- a/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java
+++ b/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java
@@ -6,7 +6,7 @@
package com.wireguard.android.util;
-import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import com.wireguard.util.Keyed;
import com.wireguard.util.SortedKeyedList;
@@ -29,6 +29,7 @@ import java.util.Spliterator;
public class ObservableSortedKeyedArrayList<K, E extends Keyed<? extends K>>
extends ObservableKeyedArrayList<K, E> implements ObservableSortedKeyedList<K, E> {
+ @Nullable
private final Comparator<? super K> comparator;
private final transient KeyList<K, E> keyList = new KeyList<>(this);
@@ -75,7 +76,7 @@ public class ObservableSortedKeyedArrayList<K, E extends Keyed<? extends K>>
}
@Override
- public boolean addAll(@NonNull final Collection<? extends E> c) {
+ public boolean addAll(final Collection<? extends E> c) {
boolean didChange = false;
for (final E e : c)
if (add(e))
@@ -84,12 +85,13 @@ public class ObservableSortedKeyedArrayList<K, E extends Keyed<? extends K>>
}
@Override
- public boolean addAll(int index, @NonNull final Collection<? extends E> c) {
+ public boolean addAll(int index, final Collection<? extends E> c) {
for (final E e : c)
add(index++, e);
return true;
}
+ @Nullable
@Override
public Comparator<? super K> comparator() {
return comparator;
@@ -128,7 +130,6 @@ public class ObservableSortedKeyedArrayList<K, E extends Keyed<? extends K>>
}
@Override
- @NonNull
public Set<K> keySet() {
return keyList;
}
@@ -168,7 +169,6 @@ public class ObservableSortedKeyedArrayList<K, E extends Keyed<? extends K>>
}
@Override
- @NonNull
public Collection<E> values() {
return this;
}
diff --git a/app/src/main/java/com/wireguard/android/util/RootShell.java b/app/src/main/java/com/wireguard/android/util/RootShell.java
index 9293dff9..18e04102 100644
--- a/app/src/main/java/com/wireguard/android/util/RootShell.java
+++ b/app/src/main/java/com/wireguard/android/util/RootShell.java
@@ -7,6 +7,7 @@
package com.wireguard.android.util;
import android.content.Context;
+import android.support.annotation.Nullable;
import android.util.Log;
import com.wireguard.android.R;
@@ -34,10 +35,10 @@ public class RootShell {
private final File localTemporaryDir;
private final Object lock = new Object();
private final String preamble;
- private Process process;
- private BufferedReader stderr;
- private OutputStreamWriter stdin;
- private BufferedReader stdout;
+ @Nullable private Process process;
+ @Nullable private BufferedReader stderr;
+ @Nullable private OutputStreamWriter stdin;
+ @Nullable private BufferedReader stdout;
public RootShell(final Context context) {
deviceNotRootedMessage = context.getString(R.string.error_root);
@@ -80,7 +81,7 @@ public class RootShell {
* @param command Command to run as root.
* @return The exit value of the command.
*/
- public int run(final Collection<String> output, final String command)
+ public int run(@Nullable final Collection<String> output, final String command)
throws IOException, NoRootException {
synchronized (lock) {
/* Start inside synchronized block to prevent a concurrent call to stop(). */
diff --git a/app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java b/app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java
index e0bb579d..997dd45c 100644
--- a/app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java
+++ b/app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java
@@ -19,8 +19,7 @@ import java.util.zip.ZipFile;
public final class SharedLibraryLoader {
private static final String TAG = "WireGuard/" + SharedLibraryLoader.class.getSimpleName();
- private SharedLibraryLoader() {
- }
+ private SharedLibraryLoader() { }
public static void loadSharedLibrary(final Context context, final String libName) {
Throwable noAbiException;
diff --git a/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java b/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
index 9cdb6a59..16c906eb 100644
--- a/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
+++ b/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
@@ -7,6 +7,7 @@
package com.wireguard.android.util;
import android.content.Context;
+import android.support.annotation.Nullable;
import android.system.OsConstants;
import android.util.Log;
@@ -39,20 +40,21 @@ public final class ToolsInstaller {
new File("/system/xbin"),
new File("/system/bin"),
};
- private static final File INSTALL_DIR = getInstallDir();
+ @Nullable private static final File INSTALL_DIR = getInstallDir();
private static final String TAG = "WireGuard/" + ToolsInstaller.class.getSimpleName();
private final File localBinaryDir;
private final Object lock = new Object();
private final File nativeLibraryDir;
- private Boolean areToolsAvailable;
- private Boolean installAsMagiskModule;
+ @Nullable private Boolean areToolsAvailable;
+ @Nullable private Boolean installAsMagiskModule;
public ToolsInstaller(final Context context) {
localBinaryDir = new File(context.getCacheDir(), "bin");
nativeLibraryDir = new File(context.getApplicationInfo().nativeLibraryDir);
}
+ @Nullable
private static File getInstallDir() {
final String path = System.getenv("PATH");
if (path == null)