global: get rid of nonnull gradle hack

Hacking things up via gradle is not right, and package-info.java poses
problems with two modules, so instead we just apply it manually to every
class.

Remember to add this to new classes!

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2020-03-09 12:01:52 -06:00
parent c00a0b12e4
commit 8e8643122e
77 changed files with 216 additions and 89 deletions

1
.gitignore vendored
View File

@ -15,4 +15,3 @@ build/
*.iml *.iml
*.jks *.jks
keystore.properties keystore.properties
package-info.java

View File

@ -1,86 +0,0 @@
/*
* Copyright © 2017-2019 WireGuard LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
task generateNonNullJavaFiles(dependsOn: "assembleDebug", type: Copy) {
group = "Copying"
description = "Generate package-info.java classes"
def basePackage = "com" + File.separatorChar + "wireguard"
def mainSrcPhrase = "src" + File.separatorChar + "main" + File.separatorChar +
"java" + File.separatorChar
def mainTestSrcPhrase = "src" + File.separatorChar + "test" + File.separatorChar +
"java" + File.separatorChar
def mainAndroidTestSrcPhrase = "src" + File.separatorChar + "androidTest" + File.separatorChar +
"java" + File.separatorChar
def sourceDir = file( "${projectDir}" + File.separatorChar + "src" + File.separatorChar +
"main" + File.separatorChar + "java" + File.separatorChar +
basePackage )
def testSourceDir = file( "${projectDir}" + File.separatorChar + "src" + File.separatorChar +
"test" + File.separatorChar + "java" + File.separatorChar +
basePackage)
def androidTestSourceDir = file( "${projectDir}" + File.separatorChar + "src" + File
.separatorChar +
"androidTest" + File.separatorChar + "java" + File.separatorChar +
basePackage )
generateInfoFiles(sourceDir, mainSrcPhrase)
sourceDir.eachDirRecurse { dir ->
generateInfoFiles(dir, mainSrcPhrase)
}
if (file(testSourceDir).exists()) {
generateInfoFiles(testSourceDir, mainTestSrcPhrase)
testSourceDir.eachDirRecurse { dir ->
generateInfoFiles(dir, mainTestSrcPhrase)
}
}
if (file(androidTestSourceDir).exists()) {
generateInfoFiles(androidTestSourceDir, mainAndroidTestSrcPhrase)
androidTestSourceDir.eachDirRecurse { dir ->
generateInfoFiles(dir, mainAndroidTestSrcPhrase)
}
}
println "[SUCCESS] NonNull generator: package-info.java files checked"
}
private void generateInfoFiles(File dir, String mainSrcPhrase) {
def infoFileContentHeader = getFileContentHeader()
def infoFileContentFooter = getFileContentFooter()
def infoFilePath = dir.getAbsolutePath() + File.separatorChar + "package-info.java"
//file(infoFilePath).delete(); //do not use in production code
if (!file(infoFilePath).exists()) {
def infoFileContentPackage = getFileContentPackage(dir.getAbsolutePath(), mainSrcPhrase)
new File(infoFilePath).write(infoFileContentHeader +
infoFileContentPackage + infoFileContentFooter)
println "[dir] " + infoFilePath + " created"
}
}
static def getFileContentPackage(String path, String mainSrcPhrase) {
def mainSrcPhraseIndex = path.indexOf(mainSrcPhrase)
def output = path.substring(mainSrcPhraseIndex)
// Win hotfix
if (System.properties['os.name'].toLowerCase().contains('windows')) {
output = output.replace("\\", "/")
mainSrcPhrase = mainSrcPhrase.replace("\\", "/")
}
return "package " + output.replaceAll(mainSrcPhrase, "").replaceAll(
"/", ".") + ";\n"
}
static def getFileContentHeader() {
return "/**\n" +
" * Make all method parameters @NonNull by default.\n" +
" */\n" +
"@NonNullForAll\n"
}
static def getFileContentFooter() {
return "\n" +
"import com.wireguard.util.NonNullForAll;\n"
}

View File

@ -1,5 +1,4 @@
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply from: rootProject.file('nonnull.gradle')
android { android {
buildToolsVersion '29.0.3' buildToolsVersion '29.0.3'

View File

@ -5,6 +5,8 @@
package com.wireguard.android.backend; package com.wireguard.android.backend;
import com.wireguard.util.NonNullForAll;
import com.wireguard.config.Config; import com.wireguard.config.Config;
import java.util.Collection; import java.util.Collection;
@ -16,6 +18,7 @@ import androidx.annotation.Nullable;
* Interface for implementations of the WireGuard secure network tunnel. * Interface for implementations of the WireGuard secure network tunnel.
*/ */
@NonNullForAll
public interface Backend { public interface Backend {
/** /**
* Enumerate names of currently-running tunnels. * Enumerate names of currently-running tunnels.

View File

@ -5,6 +5,9 @@
package com.wireguard.android.backend; package com.wireguard.android.backend;
import com.wireguard.util.NonNullForAll;
@NonNullForAll
public final class BackendException extends Exception { public final class BackendException extends Exception {
public enum Reason { public enum Reason {
UNKNOWN_KERNEL_MODULE_NAME, UNKNOWN_KERNEL_MODULE_NAME,

View File

@ -5,6 +5,8 @@
package com.wireguard.android.backend; package com.wireguard.android.backend;
import com.wireguard.util.NonNullForAll;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
@ -30,6 +32,7 @@ import java.util.concurrent.TimeoutException;
import java9.util.concurrent.CompletableFuture; import java9.util.concurrent.CompletableFuture;
@NonNullForAll
public final class GoBackend implements Backend { public final class GoBackend implements Backend {
private static final String TAG = "WireGuard/" + GoBackend.class.getSimpleName(); private static final String TAG = "WireGuard/" + GoBackend.class.getSimpleName();
private static CompletableFuture<VpnService> vpnService = new CompletableFuture<>(); private static CompletableFuture<VpnService> vpnService = new CompletableFuture<>();

View File

@ -5,6 +5,8 @@
package com.wireguard.android.backend; package com.wireguard.android.backend;
import com.wireguard.util.NonNullForAll;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.Pair; import android.util.Pair;
@ -13,6 +15,7 @@ import com.wireguard.crypto.Key;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@NonNullForAll
public class Statistics { public class Statistics {
private long lastTouched = SystemClock.elapsedRealtime(); private long lastTouched = SystemClock.elapsedRealtime();
private final Map<Key, Pair<Long, Long>> peerBytes = new HashMap<>(); private final Map<Key, Pair<Long, Long>> peerBytes = new HashMap<>();

View File

@ -5,12 +5,15 @@
package com.wireguard.android.backend; package com.wireguard.android.backend;
import com.wireguard.util.NonNullForAll;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
* Represents a WireGuard tunnel. * Represents a WireGuard tunnel.
*/ */
@NonNullForAll
public interface Tunnel { public interface Tunnel {
enum State { enum State {
DOWN, DOWN,

View File

@ -5,6 +5,8 @@
package com.wireguard.android.backend; package com.wireguard.android.backend;
import com.wireguard.util.NonNullForAll;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import android.content.Context; import android.content.Context;
@ -39,6 +41,7 @@ import java9.util.stream.Stream;
* WireGuard backend that uses {@code wg-quick} to implement tunnel configuration. * WireGuard backend that uses {@code wg-quick} to implement tunnel configuration.
*/ */
@NonNullForAll
public final class WgQuickBackend implements Backend { public final class WgQuickBackend implements Backend {
private static final String TAG = "WireGuard/" + WgQuickBackend.class.getSimpleName(); private static final String TAG = "WireGuard/" + WgQuickBackend.class.getSimpleName();

View File

@ -5,6 +5,8 @@
package com.wireguard.android.util; package com.wireguard.android.util;
import com.wireguard.util.NonNullForAll;
import android.content.Context; import android.content.Context;
import android.system.OsConstants; import android.system.OsConstants;
import android.util.Base64; import android.util.Base64;
@ -36,6 +38,7 @@ import java.util.Map;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@NonNullForAll
public class ModuleLoader { public class ModuleLoader {
private static final String MODULE_PUBLIC_KEY_BASE64 = "RWRmHuT9PSqtwfsLtEx+QS06BJtLgFYteL9WCNjH7yuyu5Y1DieSN7If"; private static final String MODULE_PUBLIC_KEY_BASE64 = "RWRmHuT9PSqtwfsLtEx+QS06BJtLgFYteL9WCNjH7yuyu5Y1DieSN7If";
private static final String MODULE_LIST_URL = "https://download.wireguard.com/android-module/modules.txt.sig"; private static final String MODULE_LIST_URL = "https://download.wireguard.com/android-module/modules.txt.sig";

View File

@ -5,6 +5,8 @@
package com.wireguard.android.util; package com.wireguard.android.util;
import com.wireguard.util.NonNullForAll;
import android.content.Context; import android.content.Context;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import android.util.Log; import android.util.Log;
@ -24,6 +26,7 @@ import java.util.UUID;
* Helper class for running commands as root. * Helper class for running commands as root.
*/ */
@NonNullForAll
public class RootShell { public class RootShell {
private static final String SU = "su"; private static final String SU = "su";
private static final String TAG = "WireGuard/" + RootShell.class.getSimpleName(); private static final String TAG = "WireGuard/" + RootShell.class.getSimpleName();

View File

@ -5,6 +5,8 @@
package com.wireguard.android.util; package com.wireguard.android.util;
import com.wireguard.util.NonNullForAll;
import android.content.Context; import android.content.Context;
import android.os.Build; import android.os.Build;
import android.util.Log; import android.util.Log;
@ -19,6 +21,7 @@ import java.util.HashSet;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
@NonNullForAll
public final class SharedLibraryLoader { public final class SharedLibraryLoader {
private static final String TAG = "WireGuard/" + SharedLibraryLoader.class.getSimpleName(); private static final String TAG = "WireGuard/" + SharedLibraryLoader.class.getSimpleName();

View File

@ -5,6 +5,8 @@
package com.wireguard.android.util; package com.wireguard.android.util;
import com.wireguard.util.NonNullForAll;
import android.content.Context; import android.content.Context;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import android.system.OsConstants; import android.system.OsConstants;
@ -22,6 +24,7 @@ import java.util.List;
* Helper to install WireGuard tools to the system partition. * Helper to install WireGuard tools to the system partition.
*/ */
@NonNullForAll
public final class ToolsInstaller { public final class ToolsInstaller {
public static final int ERROR = 0x0; public static final int ERROR = 0x0;
public static final int MAGISK = 0x4; public static final int MAGISK = 0x4;

View File

@ -5,12 +5,15 @@
package com.wireguard.config; package com.wireguard.config;
import com.wireguard.util.NonNullForAll;
import java.util.Iterator; import java.util.Iterator;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java9.util.Optional; import java9.util.Optional;
@NonNullForAll
public final class Attribute { public final class Attribute {
private static final Pattern LINE_PATTERN = Pattern.compile("(\\w+)\\s*=\\s*([^\\s#][^#]*)"); private static final Pattern LINE_PATTERN = Pattern.compile("(\\w+)\\s*=\\s*([^\\s#][^#]*)");
private static final Pattern LIST_SEPARATOR = Pattern.compile("\\s*,\\s*"); private static final Pattern LIST_SEPARATOR = Pattern.compile("\\s*,\\s*");

View File

@ -5,10 +5,13 @@
package com.wireguard.config; package com.wireguard.config;
import com.wireguard.util.NonNullForAll;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.wireguard.crypto.KeyFormatException; import com.wireguard.crypto.KeyFormatException;
@NonNullForAll
public class BadConfigException extends Exception { public class BadConfigException extends Exception {
private final Location location; private final Location location;
private final Reason reason; private final Reason reason;

View File

@ -5,6 +5,8 @@
package com.wireguard.config; package com.wireguard.config;
import com.wireguard.util.NonNullForAll;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.wireguard.config.BadConfigException.Location; import com.wireguard.config.BadConfigException.Location;
@ -29,6 +31,7 @@ import java.util.Set;
* <p> * <p>
* Instances of this class are immutable. * Instances of this class are immutable.
*/ */
@NonNullForAll
public final class Config { public final class Config {
private final Interface interfaze; private final Interface interfaze;
private final List<Peer> peers; private final List<Peer> peers;

View File

@ -5,6 +5,8 @@
package com.wireguard.config; package com.wireguard.config;
import com.wireguard.util.NonNullForAll;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.Inet4Address; import java.net.Inet4Address;
import java.net.Inet6Address; import java.net.Inet6Address;
@ -17,6 +19,7 @@ import androidx.annotation.Nullable;
/** /**
* Utility methods for creating instances of {@link InetAddress}. * Utility methods for creating instances of {@link InetAddress}.
*/ */
@NonNullForAll
public final class InetAddresses { public final class InetAddresses {
@Nullable private static final Method PARSER_METHOD; @Nullable private static final Method PARSER_METHOD;
private static final Pattern WONT_TOUCH_RESOLVER = Pattern.compile("^(((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?)|((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))$"); private static final Pattern WONT_TOUCH_RESOLVER = Pattern.compile("^(((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?)|((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))$");

View File

@ -5,6 +5,8 @@
package com.wireguard.config; package com.wireguard.config;
import com.wireguard.util.NonNullForAll;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.threeten.bp.Duration; import org.threeten.bp.Duration;
@ -25,6 +27,7 @@ import java9.util.Optional;
* <p> * <p>
* Instances of this class are externally immutable. * Instances of this class are externally immutable.
*/ */
@NonNullForAll
public final class InetEndpoint { public final class InetEndpoint {
private static final Pattern BARE_IPV6 = Pattern.compile("^[^\\[\\]]*:[^\\[\\]]*"); private static final Pattern BARE_IPV6 = Pattern.compile("^[^\\[\\]]*:[^\\[\\]]*");
private static final Pattern FORBIDDEN_CHARACTERS = Pattern.compile("[/?#]"); private static final Pattern FORBIDDEN_CHARACTERS = Pattern.compile("[/?#]");

View File

@ -5,6 +5,8 @@
package com.wireguard.config; package com.wireguard.config;
import com.wireguard.util.NonNullForAll;
import java.net.Inet4Address; import java.net.Inet4Address;
import java.net.InetAddress; import java.net.InetAddress;
@ -13,6 +15,7 @@ import java.net.InetAddress;
* <p> * <p>
* Instances of this class are immutable. * Instances of this class are immutable.
*/ */
@NonNullForAll
public final class InetNetwork { public final class InetNetwork {
private final InetAddress address; private final InetAddress address;
private final int mask; private final int mask;

View File

@ -5,6 +5,8 @@
package com.wireguard.config; package com.wireguard.config;
import com.wireguard.util.NonNullForAll;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.wireguard.config.BadConfigException.Location; import com.wireguard.config.BadConfigException.Location;
@ -35,6 +37,7 @@ import java9.util.stream.StreamSupport;
* <p> * <p>
* Instances of this class are immutable. * Instances of this class are immutable.
*/ */
@NonNullForAll
public final class Interface { public final class Interface {
private static final int MAX_UDP_PORT = 65535; private static final int MAX_UDP_PORT = 65535;
private static final int MIN_UDP_PORT = 0; private static final int MIN_UDP_PORT = 0;

View File

@ -5,10 +5,13 @@
package com.wireguard.config; package com.wireguard.config;
import com.wireguard.util.NonNullForAll;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
/** /**
*/ */
@NonNullForAll
public class ParseException extends Exception { public class ParseException extends Exception {
private final Class<?> parsingClass; private final Class<?> parsingClass;
private final CharSequence text; private final CharSequence text;

View File

@ -5,6 +5,8 @@
package com.wireguard.config; package com.wireguard.config;
import com.wireguard.util.NonNullForAll;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.wireguard.config.BadConfigException.Location; import com.wireguard.config.BadConfigException.Location;
@ -28,6 +30,7 @@ import java9.util.Optional;
* <p> * <p>
* Instances of this class are immutable. * Instances of this class are immutable.
*/ */
@NonNullForAll
public final class Peer { public final class Peer {
private final Set<InetNetwork> allowedIps; private final Set<InetNetwork> allowedIps;
private final Optional<InetEndpoint> endpoint; private final Optional<InetEndpoint> endpoint;

View File

@ -6,6 +6,8 @@
package com.wireguard.crypto; package com.wireguard.crypto;
import com.wireguard.util.NonNullForAll;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import java.util.Arrays; import java.util.Arrays;
@ -25,6 +27,7 @@ import java.util.Arrays;
* References: http://cr.yp.to/ecdh.html, RFC 7748 * References: http://cr.yp.to/ecdh.html, RFC 7748
*/ */
@SuppressWarnings({"MagicNumber", "NonConstantFieldWithUpperCaseName", "SuspiciousNameCombination"}) @SuppressWarnings({"MagicNumber", "NonConstantFieldWithUpperCaseName", "SuspiciousNameCombination"})
@NonNullForAll
public final class Curve25519 { public final class Curve25519 {
// Numbers modulo 2^255 - 19 are broken up into ten 26-bit words. // Numbers modulo 2^255 - 19 are broken up into ten 26-bit words.
private static final int NUM_LIMBS_255BIT = 10; private static final int NUM_LIMBS_255BIT = 10;

View File

@ -5,6 +5,8 @@
package com.wireguard.crypto; package com.wireguard.crypto;
import com.wireguard.util.NonNullForAll;
import com.wireguard.crypto.KeyFormatException.Type; import com.wireguard.crypto.KeyFormatException.Type;
import java.security.MessageDigest; import java.security.MessageDigest;
@ -18,6 +20,7 @@ import java.util.Arrays;
* Instances of this class are immutable. * Instances of this class are immutable.
*/ */
@SuppressWarnings("MagicNumber") @SuppressWarnings("MagicNumber")
@NonNullForAll
public final class Key { public final class Key {
private final byte[] key; private final byte[] key;

View File

@ -5,11 +5,14 @@
package com.wireguard.crypto; package com.wireguard.crypto;
import com.wireguard.util.NonNullForAll;
/** /**
* An exception thrown when attempting to parse an invalid key (too short, too long, or byte * An exception thrown when attempting to parse an invalid key (too short, too long, or byte
* data inappropriate for the format). The format being parsed can be accessed with the * data inappropriate for the format). The format being parsed can be accessed with the
* {@link #getFormat} method. * {@link #getFormat} method.
*/ */
@NonNullForAll
public final class KeyFormatException extends Exception { public final class KeyFormatException extends Exception {
private final Key.Format format; private final Key.Format format;
private final Type type; private final Type type;

View File

@ -5,11 +5,14 @@
package com.wireguard.crypto; package com.wireguard.crypto;
import com.wireguard.util.NonNullForAll;
/** /**
* Represents a Curve25519 key pair as used by WireGuard. * Represents a Curve25519 key pair as used by WireGuard.
* <p> * <p>
* Instances of this class are immutable. * Instances of this class are immutable.
*/ */
@NonNullForAll
public class KeyPair { public class KeyPair {
private final Key privateKey; private final Key privateKey;
private final Key publicKey; private final Key publicKey;

View File

@ -22,5 +22,6 @@ import javax.annotation.meta.TypeQualifierDefault;
@Nonnull @Nonnull
@TypeQualifierDefault({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @TypeQualifierDefault({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface NonNullForAll { public @interface NonNullForAll {
} }

View File

@ -1,6 +1,5 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply from: rootProject.file('nonnull.gradle')
// Create a variable called keystorePropertiesFile, and initialize it to your // Create a variable called keystorePropertiesFile, and initialize it to your
// keystore.properties file, in the rootProject folder. // keystore.properties file, in the rootProject folder.

View File

@ -5,6 +5,8 @@
package com.wireguard.android; package com.wireguard.android;
import com.wireguard.util.NonNullForAll;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -35,6 +37,7 @@ import java.util.Locale;
import java9.util.concurrent.CompletableFuture; import java9.util.concurrent.CompletableFuture;
@NonNullForAll
public class Application extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener { public class Application extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = "WireGuard/" + Application.class.getSimpleName(); private static final String TAG = "WireGuard/" + Application.class.getSimpleName();
public static final String USER_AGENT = String.format(Locale.ENGLISH, "WireGuard/%s (Android %d; %s; %s; %s %s; %s)", BuildConfig.VERSION_NAME, Build.VERSION.SDK_INT, Build.SUPPORTED_ABIS.length > 0 ? Build.SUPPORTED_ABIS[0] : "unknown ABI", Build.BOARD, Build.MANUFACTURER, Build.MODEL, Build.FINGERPRINT); public static final String USER_AGENT = String.format(Locale.ENGLISH, "WireGuard/%s (Android %d; %s; %s; %s %s; %s)", BuildConfig.VERSION_NAME, Build.VERSION.SDK_INT, Build.SUPPORTED_ABIS.length > 0 ? Build.SUPPORTED_ABIS[0] : "unknown ABI", Build.BOARD, Build.MANUFACTURER, Build.MODEL, Build.FINGERPRINT);

View File

@ -5,6 +5,8 @@
package com.wireguard.android; package com.wireguard.android;
import com.wireguard.util.NonNullForAll;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -14,6 +16,7 @@ import com.wireguard.android.backend.WgQuickBackend;
import com.wireguard.android.model.TunnelManager; import com.wireguard.android.model.TunnelManager;
import com.wireguard.android.util.ExceptionLoggers; import com.wireguard.android.util.ExceptionLoggers;
@NonNullForAll
public class BootShutdownReceiver extends BroadcastReceiver { public class BootShutdownReceiver extends BroadcastReceiver {
private static final String TAG = "WireGuard/" + BootShutdownReceiver.class.getSimpleName(); private static final String TAG = "WireGuard/" + BootShutdownReceiver.class.getSimpleName();

View File

@ -5,6 +5,8 @@
package com.wireguard.android; package com.wireguard.android;
import com.wireguard.util.NonNullForAll;
import android.content.Intent; import android.content.Intent;
import androidx.databinding.Observable; import androidx.databinding.Observable;
import androidx.databinding.Observable.OnPropertyChangedCallback; import androidx.databinding.Observable.OnPropertyChangedCallback;
@ -34,6 +36,7 @@ import java.util.Objects;
*/ */
@RequiresApi(Build.VERSION_CODES.N) @RequiresApi(Build.VERSION_CODES.N)
@NonNullForAll
public class QuickTileService extends TileService { public class QuickTileService extends TileService {
private static final String TAG = "WireGuard/" + QuickTileService.class.getSimpleName(); private static final String TAG = "WireGuard/" + QuickTileService.class.getSimpleName();

View File

@ -5,6 +5,8 @@
package com.wireguard.android.activity; package com.wireguard.android.activity;
import com.wireguard.util.NonNullForAll;
import androidx.databinding.CallbackRegistry; import androidx.databinding.CallbackRegistry;
import androidx.databinding.CallbackRegistry.NotifierCallback; import androidx.databinding.CallbackRegistry.NotifierCallback;
import android.os.Bundle; import android.os.Bundle;
@ -19,6 +21,7 @@ import java.util.Objects;
* Base class for activities that need to remember the currently-selected tunnel. * Base class for activities that need to remember the currently-selected tunnel.
*/ */
@NonNullForAll
public abstract class BaseActivity extends ThemeChangeAwareActivity { public abstract class BaseActivity extends ThemeChangeAwareActivity {
private static final String KEY_SELECTED_TUNNEL = "selected_tunnel"; private static final String KEY_SELECTED_TUNNEL = "selected_tunnel";

View File

@ -5,6 +5,8 @@
package com.wireguard.android.activity; package com.wireguard.android.activity;
import com.wireguard.util.NonNullForAll;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
@ -31,6 +33,7 @@ import java.util.List;
* editing the configuration and interface state of WireGuard tunnels. * editing the configuration and interface state of WireGuard tunnels.
*/ */
@NonNullForAll
public class MainActivity extends BaseActivity public class MainActivity extends BaseActivity
implements FragmentManager.OnBackStackChangedListener { implements FragmentManager.OnBackStackChangedListener {
@Nullable private ActionBar actionBar; @Nullable private ActionBar actionBar;

View File

@ -5,6 +5,8 @@
package com.wireguard.android.activity; package com.wireguard.android.activity;
import com.wireguard.util.NonNullForAll;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -30,6 +32,7 @@ import java.util.List;
* Interface for changing application-global persistent settings. * Interface for changing application-global persistent settings.
*/ */
@NonNullForAll
public class SettingsActivity extends ThemeChangeAwareActivity { public class SettingsActivity extends ThemeChangeAwareActivity {
private final SparseArray<PermissionRequestCallback> permissionRequestCallbacks = new SparseArray<>(); private final SparseArray<PermissionRequestCallback> permissionRequestCallbacks = new SparseArray<>();
private int permissionRequestCounter; private int permissionRequestCounter;

View File

@ -5,6 +5,8 @@
package com.wireguard.android.activity; package com.wireguard.android.activity;
import com.wireguard.util.NonNullForAll;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Build; import android.os.Build;
@ -18,6 +20,7 @@ import com.wireguard.android.Application;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@NonNullForAll
public abstract class ThemeChangeAwareActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { public abstract class ThemeChangeAwareActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = "WireGuard/" + ThemeChangeAwareActivity.class.getSimpleName(); private static final String TAG = "WireGuard/" + ThemeChangeAwareActivity.class.getSimpleName();

View File

@ -5,6 +5,8 @@
package com.wireguard.android.activity; package com.wireguard.android.activity;
import com.wireguard.util.NonNullForAll;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -15,6 +17,7 @@ import com.wireguard.android.model.ObservableTunnel;
* Standalone activity for creating tunnels. * Standalone activity for creating tunnels.
*/ */
@NonNullForAll
public class TunnelCreatorActivity extends BaseActivity { public class TunnelCreatorActivity extends BaseActivity {
@Override @Override
@SuppressWarnings("UnnecessaryFullyQualifiedName") @SuppressWarnings("UnnecessaryFullyQualifiedName")

View File

@ -5,6 +5,8 @@
package com.wireguard.android.activity; package com.wireguard.android.activity;
import com.wireguard.util.NonNullForAll;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -24,6 +26,7 @@ import com.wireguard.android.backend.Tunnel.State;
import com.wireguard.android.util.ErrorMessages; import com.wireguard.android.util.ErrorMessages;
@RequiresApi(Build.VERSION_CODES.N) @RequiresApi(Build.VERSION_CODES.N)
@NonNullForAll
public class TunnelToggleActivity extends AppCompatActivity { public class TunnelToggleActivity extends AppCompatActivity {
private static final String TAG = "WireGuard/" + TunnelToggleActivity.class.getSimpleName(); private static final String TAG = "WireGuard/" + TunnelToggleActivity.class.getSimpleName();

View File

@ -5,6 +5,8 @@
package com.wireguard.android.configStore; package com.wireguard.android.configStore;
import com.wireguard.util.NonNullForAll;
import com.wireguard.config.Config; import com.wireguard.config.Config;
import java.util.Set; import java.util.Set;
@ -13,6 +15,7 @@ import java.util.Set;
* Interface for persistent storage providers for WireGuard configurations. * Interface for persistent storage providers for WireGuard configurations.
*/ */
@NonNullForAll
public interface ConfigStore { public interface ConfigStore {
/** /**
* Create a persistent tunnel, which must have a unique name within the persistent storage * Create a persistent tunnel, which must have a unique name within the persistent storage

View File

@ -5,6 +5,8 @@
package com.wireguard.android.configStore; package com.wireguard.android.configStore;
import com.wireguard.util.NonNullForAll;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.util.Log;
@ -27,6 +29,7 @@ import java9.util.stream.Stream;
* Configuration store that uses a {@code wg-quick}-style file for each configured tunnel. * Configuration store that uses a {@code wg-quick}-style file for each configured tunnel.
*/ */
@NonNullForAll
public final class FileConfigStore implements ConfigStore { public final class FileConfigStore implements ConfigStore {
private static final String TAG = "WireGuard/" + FileConfigStore.class.getSimpleName(); private static final String TAG = "WireGuard/" + FileConfigStore.class.getSimpleName();

View File

@ -5,6 +5,8 @@
package com.wireguard.android.databinding; package com.wireguard.android.databinding;
import com.wireguard.util.NonNullForAll;
import androidx.databinding.BindingAdapter; import androidx.databinding.BindingAdapter;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
import androidx.databinding.ObservableList; import androidx.databinding.ObservableList;
@ -35,6 +37,7 @@ import java9.util.Optional;
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
@NonNullForAll
public final class BindingAdapters { public final class BindingAdapters {
private BindingAdapters() { private BindingAdapters() {
// Prevent instantiation. // Prevent instantiation.

View File

@ -5,6 +5,8 @@
package com.wireguard.android.databinding; package com.wireguard.android.databinding;
import com.wireguard.util.NonNullForAll;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
import androidx.databinding.ObservableList; import androidx.databinding.ObservableList;
import androidx.databinding.ViewDataBinding; import androidx.databinding.ViewDataBinding;
@ -22,6 +24,7 @@ import java.util.Objects;
* Helper class for binding an ObservableList to the children of a ViewGroup. * Helper class for binding an ObservableList to the children of a ViewGroup.
*/ */
@NonNullForAll
class ItemChangeListener<T> { class ItemChangeListener<T> {
private final OnListChangedCallback<T> callback = new OnListChangedCallback<>(this); private final OnListChangedCallback<T> callback = new OnListChangedCallback<>(this);
private final ViewGroup container; private final ViewGroup container;

View File

@ -5,6 +5,8 @@
package com.wireguard.android.databinding; package com.wireguard.android.databinding;
import com.wireguard.util.NonNullForAll;
import android.content.Context; import android.content.Context;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
import androidx.databinding.ObservableList; import androidx.databinding.ObservableList;
@ -25,6 +27,7 @@ import java.lang.ref.WeakReference;
* A generic {@code RecyclerView.Adapter} backed by a {@code ObservableKeyedList}. * A generic {@code RecyclerView.Adapter} backed by a {@code ObservableKeyedList}.
*/ */
@NonNullForAll
public class ObservableKeyedRecyclerViewAdapter<K, E extends Keyed<? extends K>> extends Adapter<ObservableKeyedRecyclerViewAdapter.ViewHolder> { public class ObservableKeyedRecyclerViewAdapter<K, E extends Keyed<? extends K>> extends Adapter<ObservableKeyedRecyclerViewAdapter.ViewHolder> {
private final OnListChangedCallback<E> callback = new OnListChangedCallback<>(this); private final OnListChangedCallback<E> callback = new OnListChangedCallback<>(this);

View File

@ -5,6 +5,8 @@
package com.wireguard.android.fragment; package com.wireguard.android.fragment;
import com.wireguard.util.NonNullForAll;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -34,6 +36,7 @@ import java9.util.Comparators;
import java9.util.stream.Collectors; import java9.util.stream.Collectors;
import java9.util.stream.StreamSupport; import java9.util.stream.StreamSupport;
@NonNullForAll
public class AppListDialogFragment extends DialogFragment { public class AppListDialogFragment extends DialogFragment {
private static final String KEY_EXCLUDED_APPS = "excludedApps"; private static final String KEY_EXCLUDED_APPS = "excludedApps";

View File

@ -5,6 +5,8 @@
package com.wireguard.android.fragment; package com.wireguard.android.fragment;
import com.wireguard.util.NonNullForAll;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
@ -32,6 +34,7 @@ import com.wireguard.android.util.ErrorMessages;
* attached to a {@code BaseActivity}. * attached to a {@code BaseActivity}.
*/ */
@NonNullForAll
public abstract class BaseFragment extends Fragment implements OnSelectedTunnelChangedListener { public abstract class BaseFragment extends Fragment implements OnSelectedTunnelChangedListener {
private static final int REQUEST_CODE_VPN_PERMISSION = 23491; private static final int REQUEST_CODE_VPN_PERMISSION = 23491;
private static final String TAG = "WireGuard/" + BaseFragment.class.getSimpleName(); private static final String TAG = "WireGuard/" + BaseFragment.class.getSimpleName();

View File

@ -5,6 +5,8 @@
package com.wireguard.android.fragment; package com.wireguard.android.fragment;
import com.wireguard.util.NonNullForAll;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
@ -26,6 +28,7 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Objects; import java.util.Objects;
@NonNullForAll
public class ConfigNamingDialogFragment extends DialogFragment { public class ConfigNamingDialogFragment extends DialogFragment {
private static final String KEY_CONFIG_TEXT = "config_text"; private static final String KEY_CONFIG_TEXT = "config_text";

View File

@ -5,6 +5,8 @@
package com.wireguard.android.fragment; package com.wireguard.android.fragment;
import com.wireguard.util.NonNullForAll;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
@ -30,6 +32,7 @@ import java.util.TimerTask;
* Fragment that shows details about a specific tunnel. * Fragment that shows details about a specific tunnel.
*/ */
@NonNullForAll
public class TunnelDetailFragment extends BaseFragment { public class TunnelDetailFragment extends BaseFragment {
@Nullable private TunnelDetailFragmentBinding binding; @Nullable private TunnelDetailFragmentBinding binding;
@Nullable private Timer timer; @Nullable private Timer timer;

View File

@ -5,6 +5,8 @@
package com.wireguard.android.fragment; package com.wireguard.android.fragment;
import com.wireguard.util.NonNullForAll;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import androidx.databinding.ObservableList; import androidx.databinding.ObservableList;
@ -41,6 +43,7 @@ import java.util.Objects;
* Fragment for editing a WireGuard configuration. * Fragment for editing a WireGuard configuration.
*/ */
@NonNullForAll
public class TunnelEditorFragment extends BaseFragment implements AppExclusionListener { public class TunnelEditorFragment extends BaseFragment implements AppExclusionListener {
private static final String KEY_LOCAL_CONFIG = "local_config"; private static final String KEY_LOCAL_CONFIG = "local_config";
private static final String KEY_ORIGINAL_NAME = "original_name"; private static final String KEY_ORIGINAL_NAME = "original_name";

View File

@ -5,6 +5,8 @@
package com.wireguard.android.fragment; package com.wireguard.android.fragment;
import com.wireguard.util.NonNullForAll;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.ContentResolver; import android.content.ContentResolver;
@ -64,6 +66,7 @@ import java9.util.stream.StreamSupport;
* Fragment containing a list of known WireGuard tunnels. It allows creating and deleting tunnels. * Fragment containing a list of known WireGuard tunnels. It allows creating and deleting tunnels.
*/ */
@NonNullForAll
public class TunnelListFragment extends BaseFragment { public class TunnelListFragment extends BaseFragment {
public static final int REQUEST_IMPORT = 1; public static final int REQUEST_IMPORT = 1;
private static final int REQUEST_TARGET_FRAGMENT = 2; private static final int REQUEST_TARGET_FRAGMENT = 2;

View File

@ -5,6 +5,8 @@
package com.wireguard.android.model; package com.wireguard.android.model;
import com.wireguard.util.NonNullForAll;
import androidx.databinding.BaseObservable; import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable; import androidx.databinding.Bindable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@ -12,6 +14,7 @@ import android.graphics.drawable.Drawable;
import com.wireguard.android.BR; import com.wireguard.android.BR;
import com.wireguard.util.Keyed; import com.wireguard.util.Keyed;
@NonNullForAll
public class ApplicationData extends BaseObservable implements Keyed<String> { public class ApplicationData extends BaseObservable implements Keyed<String> {
private final Drawable icon; private final Drawable icon;
private final String name; private final String name;

View File

@ -5,6 +5,8 @@
package com.wireguard.android.model; package com.wireguard.android.model;
import com.wireguard.util.NonNullForAll;
import androidx.databinding.BaseObservable; import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable; import androidx.databinding.Bindable;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -23,6 +25,7 @@ import java9.util.concurrent.CompletionStage;
* Encapsulates the volatile and nonvolatile state of a WireGuard tunnel. * Encapsulates the volatile and nonvolatile state of a WireGuard tunnel.
*/ */
@NonNullForAll
public class ObservableTunnel extends BaseObservable implements Keyed<String>, Tunnel { public class ObservableTunnel extends BaseObservable implements Keyed<String>, Tunnel {
private final TunnelManager manager; private final TunnelManager manager;
@Nullable private Config config; @Nullable private Config config;

View File

@ -5,6 +5,8 @@
package com.wireguard.android.model; package com.wireguard.android.model;
import com.wireguard.util.NonNullForAll;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -39,6 +41,7 @@ import java9.util.stream.StreamSupport;
* Maintains and mediates changes to the set of available WireGuard tunnels, * Maintains and mediates changes to the set of available WireGuard tunnels,
*/ */
@NonNullForAll
public final class TunnelManager extends BaseObservable { public final class TunnelManager extends BaseObservable {
private static final Comparator<String> COMPARATOR = Comparators.<String>thenComparing( private static final Comparator<String> COMPARATOR = Comparators.<String>thenComparing(
String.CASE_INSENSITIVE_ORDER, Comparators.naturalOrder()); String.CASE_INSENSITIVE_ORDER, Comparators.naturalOrder());

View File

@ -5,6 +5,8 @@
package com.wireguard.android.preference; package com.wireguard.android.preference;
import com.wireguard.util.NonNullForAll;
import android.Manifest; import android.Manifest;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -29,6 +31,7 @@ import java.io.InputStreamReader;
* Preference implementing a button that asynchronously exports logs. * Preference implementing a button that asynchronously exports logs.
*/ */
@NonNullForAll
public class LogExporterPreference extends Preference { public class LogExporterPreference extends Preference {
private static final String TAG = "WireGuard/" + LogExporterPreference.class.getSimpleName(); private static final String TAG = "WireGuard/" + LogExporterPreference.class.getSimpleName();

View File

@ -5,6 +5,8 @@
package com.wireguard.android.preference; package com.wireguard.android.preference;
import com.wireguard.util.NonNullForAll;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.system.OsConstants; import android.system.OsConstants;
@ -18,6 +20,7 @@ import com.wireguard.android.util.ErrorMessages;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.preference.Preference; import androidx.preference.Preference;
@NonNullForAll
public class ModuleDownloaderPreference extends Preference { public class ModuleDownloaderPreference extends Preference {
private State state = State.INITIAL; private State state = State.INITIAL;

View File

@ -5,6 +5,8 @@
package com.wireguard.android.preference; package com.wireguard.android.preference;
import com.wireguard.util.NonNullForAll;
import android.content.Context; import android.content.Context;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.preference.Preference; import androidx.preference.Preference;
@ -19,6 +21,7 @@ import com.wireguard.android.util.ToolsInstaller;
* result as the preference summary. * result as the preference summary.
*/ */
@NonNullForAll
public class ToolsInstallerPreference extends Preference { public class ToolsInstallerPreference extends Preference {
private State state = State.INITIAL; private State state = State.INITIAL;

View File

@ -5,6 +5,8 @@
package com.wireguard.android.preference; package com.wireguard.android.preference;
import com.wireguard.util.NonNullForAll;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -22,6 +24,7 @@ import com.wireguard.android.backend.WgQuickBackend;
import java.util.Locale; import java.util.Locale;
@NonNullForAll
public class VersionPreference extends Preference { public class VersionPreference extends Preference {
@Nullable private String versionSummary; @Nullable private String versionSummary;

View File

@ -5,6 +5,8 @@
package com.wireguard.android.preference; package com.wireguard.android.preference;
import com.wireguard.util.NonNullForAll;
import android.Manifest; import android.Manifest;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -35,6 +37,7 @@ import java9.util.concurrent.CompletableFuture;
* Preference implementing a button that asynchronously exports config zips. * Preference implementing a button that asynchronously exports config zips.
*/ */
@NonNullForAll
public class ZipExporterPreference extends Preference { public class ZipExporterPreference extends Preference {
private static final String TAG = "WireGuard/" + ZipExporterPreference.class.getSimpleName(); private static final String TAG = "WireGuard/" + ZipExporterPreference.class.getSimpleName();

View File

@ -5,6 +5,8 @@
package com.wireguard.android.util; package com.wireguard.android.util;
import com.wireguard.util.NonNullForAll;
import android.os.Handler; import android.os.Handler;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@ -16,6 +18,7 @@ import java9.util.concurrent.CompletionStage;
* Helper class for running asynchronous tasks and ensuring they are completed on the main thread. * Helper class for running asynchronous tasks and ensuring they are completed on the main thread.
*/ */
@NonNullForAll
public class AsyncWorker { public class AsyncWorker {
private final Executor executor; private final Executor executor;
private final Handler handler; private final Handler handler;

View File

@ -5,6 +5,8 @@
package com.wireguard.android.util; package com.wireguard.android.util;
import com.wireguard.util.NonNullForAll;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
@ -16,6 +18,7 @@ import android.widget.TextView;
* Standalone utilities for interacting with the system clipboard. * Standalone utilities for interacting with the system clipboard.
*/ */
@NonNullForAll
public final class ClipboardUtils { public final class ClipboardUtils {
private ClipboardUtils() { private ClipboardUtils() {
// Prevent instantiation // Prevent instantiation

View File

@ -5,6 +5,8 @@
package com.wireguard.android.util; package com.wireguard.android.util;
import com.wireguard.util.NonNullForAll;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
@ -22,6 +24,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
@NonNullForAll
public class DownloadsFileSaver { public class DownloadsFileSaver {
public static class DownloadsFile { public static class DownloadsFile {

View File

@ -5,6 +5,8 @@
package com.wireguard.android.util; package com.wireguard.android.util;
import com.wireguard.util.NonNullForAll;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.RemoteException; import android.os.RemoteException;
@ -29,6 +31,7 @@ import java.util.Map;
import java9.util.Maps; import java9.util.Maps;
@NonNullForAll
public final class ErrorMessages { public final class ErrorMessages {
private static final Map<BadConfigException.Reason, Integer> BCE_REASON_MAP = new EnumMap<>(Maps.of( private static final Map<BadConfigException.Reason, Integer> BCE_REASON_MAP = new EnumMap<>(Maps.of(
BadConfigException.Reason.INVALID_KEY, R.string.bad_config_reason_invalid_key, BadConfigException.Reason.INVALID_KEY, R.string.bad_config_reason_invalid_key,

View File

@ -5,6 +5,8 @@
package com.wireguard.android.util; package com.wireguard.android.util;
import com.wireguard.util.NonNullForAll;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import android.util.Log; import android.util.Log;

View File

@ -4,12 +4,15 @@
*/ */
package com.wireguard.android.util; package com.wireguard.android.util;
import com.wireguard.util.NonNullForAll;
import android.content.Context; import android.content.Context;
import androidx.preference.Preference; import androidx.preference.Preference;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import com.wireguard.android.activity.SettingsActivity; import com.wireguard.android.activity.SettingsActivity;
@NonNullForAll
public final class FragmentUtils { public final class FragmentUtils {
private FragmentUtils() { private FragmentUtils() {
// Prevent instantiation // Prevent instantiation

View File

@ -5,6 +5,8 @@
package com.wireguard.android.util; package com.wireguard.android.util;
import com.wireguard.util.NonNullForAll;
import androidx.databinding.ObservableArrayList; import androidx.databinding.ObservableArrayList;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -21,6 +23,7 @@ import java.util.Objects;
* operations, require O(n) time. * operations, require O(n) time.
*/ */
@NonNullForAll
public class ObservableKeyedArrayList<K, E extends Keyed<? extends K>> public class ObservableKeyedArrayList<K, E extends Keyed<? extends K>>
extends ObservableArrayList<E> implements ObservableKeyedList<K, E> { extends ObservableArrayList<E> implements ObservableKeyedList<K, E> {
@Override @Override

View File

@ -5,6 +5,8 @@
package com.wireguard.android.util; package com.wireguard.android.util;
import com.wireguard.util.NonNullForAll;
import androidx.databinding.ObservableList; import androidx.databinding.ObservableList;
import com.wireguard.util.Keyed; import com.wireguard.util.Keyed;
@ -14,6 +16,7 @@ import com.wireguard.util.KeyedList;
* A list that is both keyed and observable. * A list that is both keyed and observable.
*/ */
@NonNullForAll
public interface ObservableKeyedList<K, E extends Keyed<? extends K>> public interface ObservableKeyedList<K, E extends Keyed<? extends K>>
extends KeyedList<K, E>, ObservableList<E> { extends KeyedList<K, E>, ObservableList<E> {
} }

View File

@ -5,6 +5,8 @@
package com.wireguard.android.util; package com.wireguard.android.util;
import com.wireguard.util.NonNullForAll;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.wireguard.util.Keyed; import com.wireguard.util.Keyed;
@ -26,6 +28,7 @@ import java.util.Spliterator;
* key still require O(n) time. * key still require O(n) time.
*/ */
@NonNullForAll
public class ObservableSortedKeyedArrayList<K, E extends Keyed<? extends K>> public class ObservableSortedKeyedArrayList<K, E extends Keyed<? extends K>>
extends ObservableKeyedArrayList<K, E> implements ObservableSortedKeyedList<K, E> { extends ObservableKeyedArrayList<K, E> implements ObservableSortedKeyedList<K, E> {
@Nullable private final Comparator<? super K> comparator; @Nullable private final Comparator<? super K> comparator;

View File

@ -5,6 +5,8 @@
package com.wireguard.android.util; package com.wireguard.android.util;
import com.wireguard.util.NonNullForAll;
import com.wireguard.util.Keyed; import com.wireguard.util.Keyed;
import com.wireguard.util.SortedKeyedList; import com.wireguard.util.SortedKeyedList;
@ -12,6 +14,7 @@ import com.wireguard.util.SortedKeyedList;
* A list that is both sorted/keyed and observable. * A list that is both sorted/keyed and observable.
*/ */
@NonNullForAll
public interface ObservableSortedKeyedList<K, E extends Keyed<? extends K>> public interface ObservableSortedKeyedList<K, E extends Keyed<? extends K>>
extends ObservableKeyedList<K, E>, SortedKeyedList<K, E> { extends ObservableKeyedList<K, E>, SortedKeyedList<K, E> {
} }

View File

@ -5,6 +5,8 @@
package com.wireguard.android.viewmodel; package com.wireguard.android.viewmodel;
import com.wireguard.util.NonNullForAll;
import androidx.databinding.ObservableArrayList; import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableList; import androidx.databinding.ObservableList;
import android.os.Parcel; import android.os.Parcel;
@ -17,6 +19,7 @@ import com.wireguard.config.Peer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@NonNullForAll
public class ConfigProxy implements Parcelable { public class ConfigProxy implements Parcelable {
public static final Parcelable.Creator<ConfigProxy> CREATOR = new ConfigProxyCreator(); public static final Parcelable.Creator<ConfigProxy> CREATOR = new ConfigProxyCreator();

View File

@ -5,6 +5,8 @@
package com.wireguard.android.viewmodel; package com.wireguard.android.viewmodel;
import com.wireguard.util.NonNullForAll;
import androidx.databinding.BaseObservable; import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable; import androidx.databinding.Bindable;
import androidx.databinding.ObservableArrayList; import androidx.databinding.ObservableArrayList;
@ -26,6 +28,7 @@ import java.util.List;
import java9.util.stream.Collectors; import java9.util.stream.Collectors;
import java9.util.stream.StreamSupport; import java9.util.stream.StreamSupport;
@NonNullForAll
public class InterfaceProxy extends BaseObservable implements Parcelable { public class InterfaceProxy extends BaseObservable implements Parcelable {
public static final Parcelable.Creator<InterfaceProxy> CREATOR = new InterfaceProxyCreator(); public static final Parcelable.Creator<InterfaceProxy> CREATOR = new InterfaceProxyCreator();

View File

@ -5,6 +5,8 @@
package com.wireguard.android.viewmodel; package com.wireguard.android.viewmodel;
import com.wireguard.util.NonNullForAll;
import androidx.databinding.BaseObservable; import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable; import androidx.databinding.Bindable;
import androidx.databinding.Observable; import androidx.databinding.Observable;
@ -32,6 +34,7 @@ import java9.util.Sets;
import java9.util.stream.Collectors; import java9.util.stream.Collectors;
import java9.util.stream.Stream; import java9.util.stream.Stream;
@NonNullForAll
public class PeerProxy extends BaseObservable implements Parcelable { public class PeerProxy extends BaseObservable implements Parcelable {
public static final Parcelable.Creator<PeerProxy> CREATOR = new PeerProxyCreator(); public static final Parcelable.Creator<PeerProxy> CREATOR = new PeerProxyCreator();
private static final Set<String> IPV4_PUBLIC_NETWORKS = new LinkedHashSet<>(Lists.of( private static final Set<String> IPV4_PUBLIC_NETWORKS = new LinkedHashSet<>(Lists.of(

View File

@ -5,6 +5,8 @@
package com.wireguard.android.widget; package com.wireguard.android.widget;
import com.wireguard.util.NonNullForAll;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import android.text.InputFilter; import android.text.InputFilter;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
@ -16,6 +18,7 @@ import com.wireguard.crypto.Key;
* InputFilter for entering WireGuard private/public keys encoded with base64. * InputFilter for entering WireGuard private/public keys encoded with base64.
*/ */
@NonNullForAll
public class KeyInputFilter implements InputFilter { public class KeyInputFilter implements InputFilter {
private static boolean isAllowed(final char c) { private static boolean isAllowed(final char c) {
return Character.isLetterOrDigit(c) || c == '+' || c == '/'; return Character.isLetterOrDigit(c) || c == '+' || c == '/';

View File

@ -5,12 +5,15 @@
package com.wireguard.android.widget; package com.wireguard.android.widget;
import com.wireguard.util.NonNullForAll;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import com.wireguard.android.R; import com.wireguard.android.R;
@NonNullForAll
public class MultiselectableRelativeLayout extends RelativeLayout { public class MultiselectableRelativeLayout extends RelativeLayout {
private static final int[] STATE_MULTISELECTED = {R.attr.state_multiselected}; private static final int[] STATE_MULTISELECTED = {R.attr.state_multiselected};
private boolean multiselected; private boolean multiselected;

View File

@ -5,6 +5,8 @@
package com.wireguard.android.widget; package com.wireguard.android.widget;
import com.wireguard.util.NonNullForAll;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import android.text.InputFilter; import android.text.InputFilter;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
@ -16,6 +18,7 @@ import com.wireguard.android.backend.Tunnel;
* InputFilter for entering WireGuard configuration names (Linux interface names). * InputFilter for entering WireGuard configuration names (Linux interface names).
*/ */
@NonNullForAll
public class NameInputFilter implements InputFilter { public class NameInputFilter implements InputFilter {
private static boolean isAllowed(final char c) { private static boolean isAllowed(final char c) {
return Character.isLetterOrDigit(c) || "_=+.-".indexOf(c) >= 0; return Character.isLetterOrDigit(c) || "_=+.-".indexOf(c) >= 0;

View File

@ -6,6 +6,8 @@
package com.wireguard.android.widget; package com.wireguard.android.widget;
import com.wireguard.util.NonNullForAll;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
@ -29,6 +31,7 @@ import androidx.annotation.RequiresApi;
import android.util.FloatProperty; import android.util.FloatProperty;
@RequiresApi(Build.VERSION_CODES.N) @RequiresApi(Build.VERSION_CODES.N)
@NonNullForAll
public class SlashDrawable extends Drawable { public class SlashDrawable extends Drawable {
private static final float CENTER_X = 10.65f; private static final float CENTER_X = 10.65f;

View File

@ -6,12 +6,15 @@
package com.wireguard.android.widget; package com.wireguard.android.widget;
import com.wireguard.util.NonNullForAll;
import android.content.Context; import android.content.Context;
import android.os.Parcelable; import android.os.Parcelable;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.Switch; import android.widget.Switch;
@NonNullForAll
public class ToggleSwitch extends Switch { public class ToggleSwitch extends Switch {
private boolean isRestoringState; private boolean isRestoringState;
@Nullable private OnBeforeCheckedChangeListener listener; @Nullable private OnBeforeCheckedChangeListener listener;

View File

@ -5,10 +5,13 @@
package com.wireguard.util; package com.wireguard.util;
import com.wireguard.util.NonNullForAll;
/** /**
* Interface for objects that have a identifying key of the given type. * Interface for objects that have a identifying key of the given type.
*/ */
@NonNullForAll
public interface Keyed<K> { public interface Keyed<K> {
K getKey(); K getKey();
} }

View File

@ -5,6 +5,8 @@
package com.wireguard.util; package com.wireguard.util;
import com.wireguard.util.NonNullForAll;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
@ -15,6 +17,7 @@ import java.util.List;
* {@code null} elements. * {@code null} elements.
*/ */
@NonNullForAll
public interface KeyedList<K, E extends Keyed<? extends K>> extends List<E> { public interface KeyedList<K, E extends Keyed<? extends K>> extends List<E> {
boolean containsAllKeys(Collection<K> keys); boolean containsAllKeys(Collection<K> keys);

View File

@ -5,6 +5,8 @@
package com.wireguard.util; package com.wireguard.util;
import com.wireguard.util.NonNullForAll;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
@ -16,6 +18,7 @@ import java.util.Set;
* applied to their keys. * applied to their keys.
*/ */
@NonNullForAll
public interface SortedKeyedList<K, E extends Keyed<? extends K>> extends KeyedList<K, E> { public interface SortedKeyedList<K, E extends Keyed<? extends K>> extends KeyedList<K, E> {
Comparator<? super K> comparator(); Comparator<? super K> comparator();