diff options
author | Samuel Holland <samuel@sholland.org> | 2017-08-13 07:24:03 -0500 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2017-08-13 07:24:03 -0500 |
commit | 5e55d196be092f4a4dcb212cf09d7a1bdab70e00 (patch) | |
tree | eb765a1b961fefdaa7ddc3cfae9cb83a09e0c031 /app/src/main/java/com/wireguard/config/Interface.java | |
parent | Profile: Add function to copy config from another profile (diff) | |
download | wireguard-android-5e55d196be092f4a4dcb212cf09d7a1bdab70e00.tar.xz wireguard-android-5e55d196be092f4a4dcb212cf09d7a1bdab70e00.zip |
Major renaming and refactoring in activity and service
Apparently "configuration" is the proper term, not "profile".
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/config/Interface.java')
-rw-r--r-- | app/src/main/java/com/wireguard/config/Interface.java | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/app/src/main/java/com/wireguard/config/Interface.java b/app/src/main/java/com/wireguard/config/Interface.java index 6116a4a7..deb85876 100644 --- a/app/src/main/java/com/wireguard/config/Interface.java +++ b/app/src/main/java/com/wireguard/config/Interface.java @@ -12,13 +12,29 @@ import com.wireguard.crypto.KeyEncoding; * Represents the configuration for a WireGuard interface (an [Interface] block). */ -public class Interface extends BaseObservable implements Observable { +public class Interface extends BaseObservable implements Copyable<Interface>, Observable { private String address; private String dns; private String listenPort; private Keypair keypair; private String mtu; + @Override + public Interface copy() { + final Interface copy = new Interface(); + copy.copyFrom(this); + return copy; + } + + @Override + public void copyFrom(final Interface source) { + address = source.address; + dns = source.dns; + listenPort = source.listenPort; + keypair = source.keypair; + mtu = source.mtu; + } + public void generateKeypair() { keypair = new Keypair(); notifyPropertyChanged(BR.privateKey); @@ -55,7 +71,7 @@ public class Interface extends BaseObservable implements Observable { return keypair != null ? keypair.getPublicKey() : null; } - public void parseFrom(String line) { + public void parseFrom(final String line) { final Attribute key = Attribute.match(line); if (key == Attribute.ADDRESS) address = key.parseFrom(line); @@ -67,29 +83,39 @@ public class Interface extends BaseObservable implements Observable { mtu = key.parseFrom(line); else if (key == Attribute.PRIVATE_KEY) keypair = new Keypair(key.parseFrom(line)); + else + throw new IllegalArgumentException(line); } public void setAddress(String address) { + if (address != null && address.isEmpty()) + address = null; this.address = address; notifyPropertyChanged(BR.address); } public void setDns(String dns) { + if (dns != null && dns.isEmpty()) + dns = null; this.dns = dns; notifyPropertyChanged(BR.dns); } public void setListenPort(String listenPort) { + if (listenPort != null && listenPort.isEmpty()) + listenPort = null; this.listenPort = listenPort; notifyPropertyChanged(BR.listenPort); } public void setMtu(String mtu) { + if (mtu != null && mtu.isEmpty()) + mtu = null; this.mtu = mtu; notifyPropertyChanged(BR.mtu); } - public void setPrivateKey(String privateKey) { + public void setPrivateKey(final String privateKey) { if (privateKey != null && !privateKey.isEmpty()) { // Avoid exceptions from Keypair while the user is typing. if (privateKey.length() != KeyEncoding.KEY_LENGTH_BASE64) |