Config/Interface/Peer: Make Parcelable
This allows saving the editor state across restarts. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
@@ -3,16 +3,32 @@ package com.wireguard.config;
|
||||
import android.databinding.BaseObservable;
|
||||
import android.databinding.Bindable;
|
||||
import android.databinding.Observable;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.wireguard.android.BR;
|
||||
import com.wireguard.crypto.Keypair;
|
||||
import com.wireguard.crypto.KeyEncoding;
|
||||
import com.wireguard.crypto.Keypair;
|
||||
|
||||
/**
|
||||
* Represents the configuration for a WireGuard interface (an [Interface] block).
|
||||
*/
|
||||
|
||||
public class Interface extends BaseObservable implements Copyable<Interface>, Observable {
|
||||
public class Interface extends BaseObservable
|
||||
implements Copyable<Interface>, Observable, Parcelable {
|
||||
public static final Parcelable.Creator<Interface> CREATOR
|
||||
= new Parcelable.Creator<Interface>() {
|
||||
@Override
|
||||
public Interface createFromParcel(final Parcel in) {
|
||||
return new Interface(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Interface[] newArray(final int size) {
|
||||
return new Interface[size];
|
||||
}
|
||||
};
|
||||
|
||||
private String address;
|
||||
private String dns;
|
||||
private String listenPort;
|
||||
@@ -20,6 +36,18 @@ public class Interface extends BaseObservable implements Copyable<Interface>, Ob
|
||||
private String mtu;
|
||||
private String privateKey;
|
||||
|
||||
public Interface() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
protected Interface(final Parcel in) {
|
||||
address = in.readString();
|
||||
dns = in.readString();
|
||||
listenPort = in.readString();
|
||||
mtu = in.readString();
|
||||
setPrivateKey(in.readString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Interface copy() {
|
||||
final Interface copy = new Interface();
|
||||
@@ -45,6 +73,11 @@ public class Interface extends BaseObservable implements Copyable<Interface>, Ob
|
||||
notifyChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void generateKeypair() {
|
||||
keypair = new Keypair();
|
||||
privateKey = keypair.getPrivateKey();
|
||||
@@ -158,4 +191,13 @@ public class Interface extends BaseObservable implements Copyable<Interface>, Ob
|
||||
sb.append(Attribute.PRIVATE_KEY.composeWith(privateKey));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(final Parcel dest, final int flags) {
|
||||
dest.writeString(address);
|
||||
dest.writeString(dns);
|
||||
dest.writeString(listenPort);
|
||||
dest.writeString(mtu);
|
||||
dest.writeString(privateKey);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user