summaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2018-04-27 22:03:39 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2018-04-28 06:07:48 +0200
commit217ab5e17f31d78a41c575783c0779a54aafff63 (patch)
tree58a988282cda52a6ef0eadcd207eac854b93e649 /app
parentba862b166bd30de8c15593ed3b8dfd457eb39d36 (diff)
config: Minor cleanup
- Stop implicitly assuming locales in String.format - Cleanup method visibilities - Improve uses of Integer methods - Remove unused getToken method Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/com/wireguard/config/Attribute.java7
-rw-r--r--app/src/main/java/com/wireguard/config/IPCidr.java13
-rw-r--r--app/src/main/java/com/wireguard/config/Interface.java6
-rw-r--r--app/src/main/java/com/wireguard/config/Peer.java15
4 files changed, 23 insertions, 18 deletions
diff --git a/app/src/main/java/com/wireguard/config/Attribute.java b/app/src/main/java/com/wireguard/config/Attribute.java
index 695caeda..5ecd21f4 100644
--- a/app/src/main/java/com/wireguard/config/Attribute.java
+++ b/app/src/main/java/com/wireguard/config/Attribute.java
@@ -7,6 +7,7 @@ import java.lang.reflect.Method;
import java.net.InetAddress;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -88,17 +89,13 @@ enum Attribute {
}
public String composeWith(final int value) {
- return String.format("%s = %d%n", token, value);
+ return String.format(Locale.getDefault(), "%s = %d%n", token, value);
}
public <T> String composeWith(final List<T> value) {
return String.format("%s = %s%n", token, listToString(value));
}
- public String getToken() {
- return token;
- }
-
public String parse(final CharSequence line) {
final Matcher matcher = pattern.matcher(line);
return matcher.matches() ? matcher.group(1) : null;
diff --git a/app/src/main/java/com/wireguard/config/IPCidr.java b/app/src/main/java/com/wireguard/config/IPCidr.java
index aeb5fb36..569fd410 100644
--- a/app/src/main/java/com/wireguard/config/IPCidr.java
+++ b/app/src/main/java/com/wireguard/config/IPCidr.java
@@ -6,10 +6,11 @@ import android.os.Parcelable;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
+import java.util.Locale;
public class IPCidr implements Parcelable {
- InetAddress address;
- int cidr;
+ private InetAddress address;
+ private int cidr;
public static final Parcelable.Creator<IPCidr> CREATOR = new Parcelable.Creator<IPCidr>() {
@@ -24,7 +25,7 @@ public class IPCidr implements Parcelable {
}
};
- public IPCidr(String in) {
+ IPCidr(String in) {
parse(in);
}
@@ -35,7 +36,7 @@ public class IPCidr implements Parcelable {
try {
cidr = Integer.parseInt(in.substring(slash + 1), 10);
in = in.substring(0, slash);
- } catch (Exception e) {
+ } catch (Exception ignored) {
}
}
address = Attribute.parseIPString(in);
@@ -55,7 +56,7 @@ public class IPCidr implements Parcelable {
@Override
public String toString() {
- return String.format("%s/%d", address.getHostAddress(), cidr);
+ return String.format(Locale.getDefault(), "%s/%d", address.getHostAddress(), cidr);
}
@Override
@@ -71,7 +72,7 @@ public class IPCidr implements Parcelable {
private IPCidr(final Parcel in) {
try {
parse(in.readString());
- } catch (Exception e) {
+ } catch (Exception ignored) {
}
}
diff --git a/app/src/main/java/com/wireguard/config/Interface.java b/app/src/main/java/com/wireguard/config/Interface.java
index 2ed2b4e6..5b125f51 100644
--- a/app/src/main/java/com/wireguard/config/Interface.java
+++ b/app/src/main/java/com/wireguard/config/Interface.java
@@ -151,7 +151,7 @@ public class Interface implements Parcelable {
for (int i = 0; i < dnsItems; ++i) {
try {
dnsList.add(InetAddress.getByAddress(in.createByteArray()));
- } catch (Exception e) {
+ } catch (Exception ignored) {
}
}
listenPort = in.readInt();
@@ -198,7 +198,7 @@ public class Interface implements Parcelable {
private String getListenPortString() {
if (listenPort == 0)
return null;
- return new Integer(listenPort).toString();
+ return Integer.valueOf(listenPort).toString();
}
public int getMtu() {
@@ -208,7 +208,7 @@ public class Interface implements Parcelable {
private String getMtuString() {
if (mtu == 0)
return null;
- return new Integer(mtu).toString();
+ return Integer.toString(mtu);
}
public String getPrivateKey() {
diff --git a/app/src/main/java/com/wireguard/config/Peer.java b/app/src/main/java/com/wireguard/config/Peer.java
index 5c506b36..28495f46 100644
--- a/app/src/main/java/com/wireguard/config/Peer.java
+++ b/app/src/main/java/com/wireguard/config/Peer.java
@@ -15,6 +15,7 @@ import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
/**
* Represents the configuration for a WireGuard peer (a [Peer] block).
@@ -167,7 +168,7 @@ public class Peer implements Parcelable {
private String getEndpointString() {
if (endpoint == null)
return null;
- return String.format("%s:%d", endpoint.getHostString(), endpoint.getPort());
+ return String.format(Locale.getDefault(), "%s:%d", endpoint.getHostString(), endpoint.getPort());
}
public String getResolvedEndpointString() throws UnknownHostException {
@@ -178,8 +179,14 @@ public class Peer implements Parcelable {
if (endpoint.isUnresolved())
throw new UnknownHostException(endpoint.getHostString());
if (endpoint.getAddress() instanceof Inet6Address)
- return String.format("[%s]:%d", endpoint.getAddress().getHostAddress(), endpoint.getPort());
- return String.format("%s:%d", endpoint.getAddress().getHostAddress(), endpoint.getPort());
+ return String.format(Locale.getDefault(),
+ "[%s]:%d",
+ endpoint.getAddress().getHostAddress(),
+ endpoint.getPort());
+ return String.format(Locale.getDefault(),
+ "%s:%d",
+ endpoint.getAddress().getHostAddress(),
+ endpoint.getPort());
}
public int getPersistentKeepalive() {
@@ -189,7 +196,7 @@ public class Peer implements Parcelable {
private String getPersistentKeepaliveString() {
if (persistentKeepalive == 0)
return null;
- return new Integer(persistentKeepalive).toString();
+ return Integer.valueOf(persistentKeepalive).toString();
}
public String getPreSharedKey() {