aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app/src/main/java/com/wireguard/config/Interface.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/wireguard/config/Interface.java')
-rw-r--r--app/src/main/java/com/wireguard/config/Interface.java53
1 files changed, 34 insertions, 19 deletions
diff --git a/app/src/main/java/com/wireguard/config/Interface.java b/app/src/main/java/com/wireguard/config/Interface.java
index 3f72e812..99336ae4 100644
--- a/app/src/main/java/com/wireguard/config/Interface.java
+++ b/app/src/main/java/com/wireguard/config/Interface.java
@@ -10,6 +10,7 @@ import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.os.Parcel;
import android.os.Parcelable;
+import android.support.annotation.Nullable;
import com.wireguard.android.BR;
import com.wireguard.crypto.Keypair;
@@ -27,7 +28,7 @@ public class Interface {
private final List<InetNetwork> addressList;
private final List<InetAddress> dnsList;
private final List<String> excludedApplications;
- private Keypair keypair;
+ @Nullable private Keypair keypair;
private int listenPort;
private int mtu;
@@ -37,7 +38,7 @@ public class Interface {
excludedApplications = new ArrayList<>();
}
- private void addAddresses(final String[] addresses) {
+ private void addAddresses(@Nullable final String[] addresses) {
if (addresses != null && addresses.length > 0) {
for (final String addr : addresses) {
if (addr.isEmpty())
@@ -47,7 +48,7 @@ public class Interface {
}
}
- private void addDnses(final String[] dnses) {
+ private void addDnses(@Nullable final String[] dnses) {
if (dnses != null && dnses.length > 0) {
for (final String dns : dnses) {
dnsList.add(InetAddresses.parse(dns));
@@ -55,12 +56,13 @@ public class Interface {
}
}
- private void addExcludedApplications(final String[] applications) {
+ private void addExcludedApplications(@Nullable final String[] applications) {
if (applications != null && applications.length > 0) {
excludedApplications.addAll(Arrays.asList(applications));
}
}
+ @Nullable
private String getAddressString() {
if (addressList.isEmpty())
return null;
@@ -71,6 +73,7 @@ public class Interface {
return addressList.toArray(new InetNetwork[addressList.size()]);
}
+ @Nullable
private String getDnsString() {
if (dnsList.isEmpty())
return null;
@@ -88,6 +91,7 @@ public class Interface {
return dnsList.toArray(new InetAddress[dnsList.size()]);
}
+ @Nullable
private String getExcludedApplicationsString() {
if (excludedApplications.isEmpty())
return null;
@@ -102,6 +106,7 @@ public class Interface {
return listenPort;
}
+ @Nullable
private String getListenPortString() {
if (listenPort == 0)
return null;
@@ -112,18 +117,21 @@ public class Interface {
return mtu;
}
+ @Nullable
private String getMtuString() {
if (mtu == 0)
return null;
return Integer.toString(mtu);
}
+ @Nullable
public String getPrivateKey() {
if (keypair == null)
return null;
return keypair.getPrivateKey();
}
+ @Nullable
public String getPublicKey() {
if (keypair == null)
return null;
@@ -156,17 +164,17 @@ public class Interface {
}
}
- private void setAddressString(final String addressString) {
+ private void setAddressString(@Nullable final String addressString) {
addressList.clear();
addAddresses(Attribute.stringToList(addressString));
}
- private void setDnsString(final String dnsString) {
+ private void setDnsString(@Nullable final String dnsString) {
dnsList.clear();
addDnses(Attribute.stringToList(dnsString));
}
- private void setExcludedApplicationsString(final String applicationsString) {
+ private void setExcludedApplicationsString(@Nullable final String applicationsString) {
excludedApplications.clear();
addExcludedApplications(Attribute.stringToList(applicationsString));
}
@@ -175,7 +183,7 @@ public class Interface {
this.listenPort = listenPort;
}
- private void setListenPortString(final String port) {
+ private void setListenPortString(@Nullable final String port) {
if (port != null && !port.isEmpty())
setListenPort(Integer.parseInt(port, 10));
else
@@ -186,14 +194,14 @@ public class Interface {
this.mtu = mtu;
}
- private void setMtuString(final String mtu) {
+ private void setMtuString(@Nullable final String mtu) {
if (mtu != null && !mtu.isEmpty())
setMtu(Integer.parseInt(mtu, 10));
else
setMtu(0);
}
- private void setPrivateKey(String privateKey) {
+ private void setPrivateKey(@Nullable String privateKey) {
if (privateKey != null && privateKey.isEmpty())
privateKey = null;
keypair = privateKey == null ? null : new Keypair(privateKey);
@@ -229,15 +237,15 @@ public class Interface {
return new Observable[size];
}
};
- private String addresses;
- private String dnses;
- private String excludedApplications;
- private String listenPort;
- private String mtu;
- private String privateKey;
- private String publicKey;
-
- public Observable(final Interface parent) {
+ @Nullable private String addresses;
+ @Nullable private String dnses;
+ @Nullable private String excludedApplications;
+ @Nullable private String listenPort;
+ @Nullable private String mtu;
+ @Nullable private String privateKey;
+ @Nullable private String publicKey;
+
+ public Observable(@Nullable final Interface parent) {
if (parent != null)
loadData(parent);
}
@@ -276,16 +284,19 @@ public class Interface {
notifyPropertyChanged(BR.publicKey);
}
+ @Nullable
@Bindable
public String getAddresses() {
return addresses;
}
+ @Nullable
@Bindable
public String getDnses() {
return dnses;
}
+ @Nullable
@Bindable
public String getExcludedApplications() {
return excludedApplications;
@@ -296,21 +307,25 @@ public class Interface {
return Attribute.stringToList(excludedApplications).length;
}
+ @Nullable
@Bindable
public String getListenPort() {
return listenPort;
}
+ @Nullable
@Bindable
public String getMtu() {
return mtu;
}
+ @Nullable
@Bindable
public String getPrivateKey() {
return privateKey;
}
+ @Nullable
@Bindable
public String getPublicKey() {
return publicKey;