diff options
author | Samuel Holland <samuel@sholland.org> | 2018-01-08 02:19:13 -0600 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-01-08 02:19:13 -0600 |
commit | 9c1e41ff56dc9f051b10bd460c845a65ce711a98 (patch) | |
tree | 3ace665e70d3b61402d209262ae1eccad518aa2c /app/src/main/java | |
parent | d4314becb3b22200c9cc796984b0df587ab13cd8 (diff) |
project: Global cleanup
Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/com/wireguard/android/activity/MainActivity.java | 4 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/android/activity/TunnelCreatorActivity.java | 4 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java | 2 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/android/databinding/BindingAdapters.java | 22 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java (renamed from app/src/main/java/com/wireguard/android/fragment/ConfigEditorFragment.java) | 10 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java | 10 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java | 2 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/crypto/Keypair.java | 32 |
8 files changed, 31 insertions, 55 deletions
diff --git a/app/src/main/java/com/wireguard/android/activity/MainActivity.java b/app/src/main/java/com/wireguard/android/activity/MainActivity.java index a905156c..9e69ca89 100644 --- a/app/src/main/java/com/wireguard/android/activity/MainActivity.java +++ b/app/src/main/java/com/wireguard/android/activity/MainActivity.java @@ -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; diff --git a/app/src/main/java/com/wireguard/android/activity/TunnelCreatorActivity.java b/app/src/main/java/com/wireguard/android/activity/TunnelCreatorActivity.java index 9a5f4e0a..986054df 100644 --- a/app/src/main/java/com/wireguard/android/activity/TunnelCreatorActivity.java +++ b/app/src/main/java/com/wireguard/android/activity/TunnelCreatorActivity.java @@ -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(); } } diff --git a/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java b/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java index 0bca1bd7..c2734fa1 100644 --- a/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java +++ b/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java @@ -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; diff --git a/app/src/main/java/com/wireguard/android/databinding/BindingAdapters.java b/app/src/main/java/com/wireguard/android/databinding/BindingAdapters.java index 34ddb010..4613257b 100644 --- a/app/src/main/java/com/wireguard/android/databinding/BindingAdapters.java +++ b/app/src/main/java/com/wireguard/android/databinding/BindingAdapters.java @@ -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); - } } diff --git a/app/src/main/java/com/wireguard/android/fragment/ConfigEditorFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java index a4da80fd..b5f21ece 100644 --- a/app/src/main/java/com/wireguard/android/fragment/ConfigEditorFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java @@ -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(); } diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java index e174634d..0a374555 100644 --- a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java @@ -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: diff --git a/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java b/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java index a11529f4..71c949ca 100644 --- a/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java +++ b/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java @@ -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> { diff --git a/app/src/main/java/com/wireguard/crypto/Keypair.java b/app/src/main/java/com/wireguard/crypto/Keypair.java index e0d35d64..25327182 100644 --- a/app/src/main/java/com/wireguard/crypto/Keypair.java +++ b/app/src/main/java/com/wireguard/crypto/Keypair.java @@ -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); } |