From c72d30a1af8114ef506a137e3e7274ac33d82bd1 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sun, 13 Aug 2017 07:23:16 -0500 Subject: [PATCH] Profile: Add function to copy config from another profile Signed-off-by: Jason A. Donenfeld --- app/src/main/java/com/wireguard/config/Profile.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/wireguard/config/Profile.java b/app/src/main/java/com/wireguard/config/Profile.java index e04cab3e..a0388427 100644 --- a/app/src/main/java/com/wireguard/config/Profile.java +++ b/app/src/main/java/com/wireguard/config/Profile.java @@ -32,15 +32,15 @@ public class Profile extends BaseObservable implements Copyable, Observ public Profile(String name) { super(); + if (!isNameValid(name)) + throw new IllegalArgumentException(); this.name = name; } private Profile(Profile original) throws IOException { this(original.getName()); - final byte configBytes[] = original.toString().getBytes(StandardCharsets.UTF_8); - final ByteArrayInputStream configStream = new ByteArrayInputStream(configBytes); - parseFrom(configStream); + parseFrom(original); } public Profile copy() { @@ -90,6 +90,13 @@ public class Profile extends BaseObservable implements Copyable, Observ } } + public void parseFrom(Profile profile) + throws IOException { + final byte configBytes[] = profile.toString().getBytes(StandardCharsets.UTF_8); + final ByteArrayInputStream configStream = new ByteArrayInputStream(configBytes); + parseFrom(configStream); + } + public void setIsConnected(boolean isConnected) { this.isConnected = isConnected; notifyPropertyChanged(BR.isConnected);