project: Global cleanup
Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
@@ -9,8 +9,8 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.wireguard.android.R;
|
||||
import com.wireguard.android.fragment.ConfigEditorFragment;
|
||||
import com.wireguard.android.fragment.TunnelDetailFragment;
|
||||
import com.wireguard.android.fragment.TunnelEditorFragment;
|
||||
import com.wireguard.android.fragment.TunnelListFragment;
|
||||
import com.wireguard.android.model.Tunnel;
|
||||
|
||||
@@ -129,7 +129,7 @@ public class MainActivity extends BaseActivity {
|
||||
EMPTY(null, 0),
|
||||
LIST(TunnelListFragment.class, 1),
|
||||
DETAIL(TunnelDetailFragment.class, 2),
|
||||
EDITOR(ConfigEditorFragment.class, 3);
|
||||
EDITOR(TunnelEditorFragment.class, 3);
|
||||
|
||||
private final String fragment;
|
||||
private final int layer;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.wireguard.android.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.wireguard.android.fragment.ConfigEditorFragment;
|
||||
import com.wireguard.android.fragment.TunnelEditorFragment;
|
||||
import com.wireguard.android.model.Tunnel;
|
||||
|
||||
/**
|
||||
@@ -15,7 +15,7 @@ public class TunnelCreatorActivity extends BaseActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getFragmentManager().findFragmentById(android.R.id.content) == null) {
|
||||
getFragmentManager().beginTransaction()
|
||||
.add(android.R.id.content, new ConfigEditorFragment())
|
||||
.add(android.R.id.content, new TunnelEditorFragment())
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import com.wireguard.config.Config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.wireguard.android.databinding;
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.ObservableList;
|
||||
import android.databinding.adapters.ListenerUtil;
|
||||
import android.graphics.Typeface;
|
||||
import android.text.InputFilter;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
@@ -15,11 +14,6 @@ import com.wireguard.android.util.ObservableKeyedList;
|
||||
import com.wireguard.android.widget.ToggleSwitch;
|
||||
import com.wireguard.android.widget.ToggleSwitch.OnBeforeCheckedChangeListener;
|
||||
|
||||
import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.ZoneId;
|
||||
import org.threeten.bp.ZonedDateTime;
|
||||
import org.threeten.bp.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* Static methods for use by generated code in the Android data binding library.
|
||||
*/
|
||||
@@ -96,20 +90,4 @@ public final class BindingAdapters {
|
||||
final OnBeforeCheckedChangeListener listener) {
|
||||
view.setOnBeforeCheckedChangeListener(listener);
|
||||
}
|
||||
|
||||
@BindingAdapter({"android:text"})
|
||||
public static void setText(final TextView view, final Instant instant) {
|
||||
if (instant == null || Instant.EPOCH.equals(instant)) {
|
||||
view.setText(R.string.never);
|
||||
} else {
|
||||
final ZoneId defaultZone = ZoneId.systemDefault();
|
||||
final ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, defaultZone);
|
||||
view.setText(zonedDateTime.format(DateTimeFormatter.RFC_1123_DATE_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter({"android:textStyle"})
|
||||
public static void setTextStyle(final TextView view, final Typeface typeface) {
|
||||
view.setTypeface(typeface);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -19,7 +19,7 @@ import com.commonsware.cwac.crossport.design.widget.CoordinatorLayout;
|
||||
import com.commonsware.cwac.crossport.design.widget.Snackbar;
|
||||
import com.wireguard.android.Application;
|
||||
import com.wireguard.android.R;
|
||||
import com.wireguard.android.databinding.ConfigEditorFragmentBinding;
|
||||
import com.wireguard.android.databinding.TunnelEditorFragmentBinding;
|
||||
import com.wireguard.android.model.Tunnel;
|
||||
import com.wireguard.android.model.TunnelManager;
|
||||
import com.wireguard.android.util.ExceptionLoggers;
|
||||
@@ -29,14 +29,14 @@ import com.wireguard.config.Config;
|
||||
* Fragment for editing a WireGuard configuration.
|
||||
*/
|
||||
|
||||
public class ConfigEditorFragment extends BaseFragment {
|
||||
public class TunnelEditorFragment extends BaseFragment {
|
||||
private static final String KEY_LOCAL_CONFIG = "local_config";
|
||||
private static final String KEY_LOCAL_NAME = "local_name";
|
||||
private static final String KEY_ORIGINAL_NAME = "original_name";
|
||||
private static final String TAG = ConfigEditorFragment.class.getSimpleName();
|
||||
private static final String TAG = TunnelEditorFragment.class.getSimpleName();
|
||||
|
||||
private final ObservableField<String> localName = new ObservableField<>("");
|
||||
private ConfigEditorFragmentBinding binding;
|
||||
private TunnelEditorFragmentBinding binding;
|
||||
private boolean isViewStateRestored;
|
||||
private Config localConfig = new Config();
|
||||
private Tunnel localTunnel;
|
||||
@@ -107,7 +107,7 @@ public class ConfigEditorFragment extends BaseFragment {
|
||||
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
|
||||
final Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
binding = ConfigEditorFragmentBinding.inflate(inflater, container, false);
|
||||
binding = TunnelEditorFragmentBinding.inflate(inflater, container, false);
|
||||
binding.executePendingBindings();
|
||||
return binding.getRoot();
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class TunnelListFragment extends BaseFragment {
|
||||
asyncWorker.supplyAsync(() -> Config.from(contentResolver.openInputStream(uri)))
|
||||
.thenCombine(nameStage, (config, name) -> tunnelManager.create(name, config))
|
||||
.thenCompose(Function.identity())
|
||||
.handle(this::onTunnelImportFinished);
|
||||
.whenComplete(this::onTunnelImportFinished);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,7 +142,7 @@ public class TunnelListFragment extends BaseFragment {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
private Void onTunnelDeletionFinished(final Integer count, final Throwable throwable) {
|
||||
private void onTunnelDeletionFinished(final Integer count, final Throwable throwable) {
|
||||
final String message;
|
||||
if (throwable == null) {
|
||||
message = "Successfully deleted " + count + " tunnels";
|
||||
@@ -155,10 +155,9 @@ public class TunnelListFragment extends BaseFragment {
|
||||
final CoordinatorLayout container = binding.mainContainer;
|
||||
Snackbar.make(container, message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Void onTunnelImportFinished(final Tunnel tunnel, final Throwable throwable) {
|
||||
private void onTunnelImportFinished(final Tunnel tunnel, final Throwable throwable) {
|
||||
final String message;
|
||||
if (throwable == null) {
|
||||
message = "Successfully imported tunnel '" + tunnel.getName() + '\'';
|
||||
@@ -171,7 +170,6 @@ public class TunnelListFragment extends BaseFragment {
|
||||
final CoordinatorLayout container = binding.mainContainer;
|
||||
Snackbar.make(container, message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -202,7 +200,7 @@ public class TunnelListFragment extends BaseFragment {
|
||||
.toArray(CompletableFuture[]::new);
|
||||
CompletableFuture.allOf(futures)
|
||||
.thenApply(x -> futures.length)
|
||||
.handle(TunnelListFragment.this::onTunnelDeletionFinished);
|
||||
.whenComplete(TunnelListFragment.this::onTunnelDeletionFinished);
|
||||
mode.finish();
|
||||
return true;
|
||||
default:
|
||||
|
||||
@@ -7,7 +7,7 @@ import java9.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* Helpers for logging exceptions from asynchronous tasks. These can be passed to
|
||||
* {@code CompletionStage.handle()} at the end of an asynchronous future chain.
|
||||
* {@code CompletionStage.whenComplete()} at the end of an asynchronous future chain.
|
||||
*/
|
||||
|
||||
public enum ExceptionLoggers implements BiConsumer<Object, Throwable> {
|
||||
|
||||
@@ -7,22 +7,6 @@ import java.security.SecureRandom;
|
||||
*/
|
||||
|
||||
public class Keypair {
|
||||
private static byte[] generatePrivateKey() {
|
||||
final SecureRandom secureRandom = new SecureRandom();
|
||||
final byte[] privateKey = new byte[KeyEncoding.KEY_LENGTH];
|
||||
secureRandom.nextBytes(privateKey);
|
||||
privateKey[0] &= 248;
|
||||
privateKey[31] &= 127;
|
||||
privateKey[31] |= 64;
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
private static byte[] generatePublicKey(final byte[] privateKey) {
|
||||
final byte[] publicKey = new byte[KeyEncoding.KEY_LENGTH];
|
||||
Curve25519.eval(publicKey, 0, privateKey, null);
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
private final byte[] privateKey;
|
||||
private final byte[] publicKey;
|
||||
|
||||
@@ -39,6 +23,22 @@ public class Keypair {
|
||||
this(KeyEncoding.keyFromBase64(privateKey));
|
||||
}
|
||||
|
||||
private static byte[] generatePrivateKey() {
|
||||
final SecureRandom secureRandom = new SecureRandom();
|
||||
final byte[] privateKey = new byte[KeyEncoding.KEY_LENGTH];
|
||||
secureRandom.nextBytes(privateKey);
|
||||
privateKey[0] &= 248;
|
||||
privateKey[31] &= 127;
|
||||
privateKey[31] |= 64;
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
private static byte[] generatePublicKey(final byte[] privateKey) {
|
||||
final byte[] publicKey = new byte[KeyEncoding.KEY_LENGTH];
|
||||
Curve25519.eval(publicKey, 0, privateKey, null);
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
public String getPrivateKey() {
|
||||
return KeyEncoding.keyToBase64(privateKey);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user