From 9c1e41ff56dc9f051b10bd460c845a65ce711a98 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Mon, 8 Jan 2018 02:19:13 -0600 Subject: project: Global cleanup Signed-off-by: Samuel Holland --- .../wireguard/android/activity/MainActivity.java | 4 +- .../android/activity/TunnelCreatorActivity.java | 4 +- .../wireguard/android/backend/WgQuickBackend.java | 2 +- .../android/databinding/BindingAdapters.java | 22 -- .../android/fragment/ConfigEditorFragment.java | 236 --------------------- .../android/fragment/TunnelEditorFragment.java | 236 +++++++++++++++++++++ .../android/fragment/TunnelListFragment.java | 10 +- .../wireguard/android/util/ExceptionLoggers.java | 2 +- .../main/java/com/wireguard/crypto/Keypair.java | 32 +-- 9 files changed, 262 insertions(+), 286 deletions(-) delete mode 100644 app/src/main/java/com/wireguard/android/fragment/ConfigEditorFragment.java create mode 100644 app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java (limited to 'app/src/main/java') 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/ConfigEditorFragment.java deleted file mode 100644 index a4da80fd..00000000 --- a/app/src/main/java/com/wireguard/android/fragment/ConfigEditorFragment.java +++ /dev/null @@ -1,236 +0,0 @@ -package com.wireguard.android.fragment; - -import android.app.Activity; -import android.content.Context; -import android.databinding.ObservableField; -import android.os.Bundle; -import android.os.Parcel; -import android.os.Parcelable; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.view.inputmethod.InputMethodManager; - -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.model.Tunnel; -import com.wireguard.android.model.TunnelManager; -import com.wireguard.android.util.ExceptionLoggers; -import com.wireguard.config.Config; - -/** - * Fragment for editing a WireGuard configuration. - */ - -public class ConfigEditorFragment 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 final ObservableField localName = new ObservableField<>(""); - private ConfigEditorFragmentBinding binding; - private boolean isViewStateRestored; - private Config localConfig = new Config(); - private Tunnel localTunnel; - private String originalName; - - private static T copyParcelable(final T original) { - if (original == null) - return null; - final Parcel parcel = Parcel.obtain(); - parcel.writeParcelable(original, 0); - parcel.setDataPosition(0); - final T copy = parcel.readParcelable(original.getClass().getClassLoader()); - parcel.recycle(); - return copy; - } - - private void onConfigLoaded(final Config config) { - localConfig = copyParcelable(config); - if (binding != null && isViewStateRestored) - binding.setConfig(localConfig); - } - - private void onConfigSaved(final Config config, final Throwable throwable) { - if (throwable != null) { - Log.e(TAG, "Cannot save configuration", throwable); - final String message = "Cannot save configuration: " - + ExceptionLoggers.unwrap(throwable).getMessage(); - if (binding != null) { - final CoordinatorLayout container = binding.mainContainer; - Snackbar.make(container, message, Snackbar.LENGTH_LONG).show(); - } - } else { - Log.d(TAG, "Successfully saved configuration for " + localTunnel.getName()); - onFinished(); - } - } - - @Override - public void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (savedInstanceState != null) { - localConfig = savedInstanceState.getParcelable(KEY_LOCAL_CONFIG); - localName.set(savedInstanceState.getString(KEY_LOCAL_NAME)); - originalName = savedInstanceState.getString(KEY_ORIGINAL_NAME); - } - // Erase the remains of creating or editing a different tunnel. - if (getSelectedTunnel() != null && !getSelectedTunnel().getName().equals(originalName)) { - // The config must be loaded asynchronously since it's not an observable property. - localConfig = null; - getSelectedTunnel().getConfigAsync().thenAccept(this::onConfigLoaded); - originalName = getSelectedTunnel().getName(); - localName.set(originalName); - } else if (getSelectedTunnel() == null && originalName != null) { - localConfig = new Config(); - originalName = null; - localName.set(""); - } - localTunnel = getSelectedTunnel(); - setHasOptionsMenu(true); - } - - @Override - public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { - inflater.inflate(R.menu.config_editor, menu); - } - - @Override - public View onCreateView(final LayoutInflater inflater, final ViewGroup container, - final Bundle savedInstanceState) { - super.onCreateView(inflater, container, savedInstanceState); - binding = ConfigEditorFragmentBinding.inflate(inflater, container, false); - binding.executePendingBindings(); - return binding.getRoot(); - } - - @Override - public void onDestroyView() { - binding = null; - super.onDestroyView(); - } - - private void onFinished() { - // Hide the keyboard; it rarely goes away on its own. - final Activity activity = getActivity(); - final View focusedView = activity.getCurrentFocus(); - if (focusedView != null) { - final Object service = activity.getSystemService(Context.INPUT_METHOD_SERVICE); - final InputMethodManager inputManager = (InputMethodManager) service; - if (inputManager != null) - inputManager.hideSoftInputFromWindow(focusedView.getWindowToken(), - InputMethodManager.HIDE_NOT_ALWAYS); - } - // Tell the activity to finish itself or go back to the detail view. - getActivity().runOnUiThread(() -> { - // The selected tunnel has to actually change, but we have to remember this one. - final Tunnel savedTunnel = localTunnel; - if (savedTunnel == getSelectedTunnel()) - setSelectedTunnel(null); - setSelectedTunnel(savedTunnel); - }); - } - - @Override - public boolean onOptionsItemSelected(final MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_action_save: - if (getSelectedTunnel() == null) { - Log.d(TAG, "Attempting to create new tunnel " + localName.get()); - final TunnelManager manager = Application.getComponent().getTunnelManager(); - manager.create(localName.get(), localConfig) - .whenComplete(this::onTunnelCreated); - } else if (!getSelectedTunnel().getName().equals(localName.get())) { - Log.d(TAG, "Attempting to rename tunnel to " + localName.get()); - getSelectedTunnel().rename(localName.get()) - .whenComplete(this::onTunnelRenamed); - } else { - Log.d(TAG, "Attempting to save config of " + getSelectedTunnel().getName()); - getSelectedTunnel().setConfig(localConfig) - .whenComplete(this::onConfigSaved); - } - return true; - default: - return super.onOptionsItemSelected(item); - } - } - - @Override - public void onSaveInstanceState(final Bundle outState) { - outState.putParcelable(KEY_LOCAL_CONFIG, localConfig); - outState.putString(KEY_LOCAL_NAME, localName.get()); - outState.putString(KEY_ORIGINAL_NAME, originalName); - super.onSaveInstanceState(outState); - } - - @Override - public void onSelectedTunnelChanged(final Tunnel oldTunnel, final Tunnel newTunnel) { - // Erase the remains of creating or editing a different tunnel. - if (newTunnel != null) { - // The config must be loaded asynchronously since it's not an observable property. - localConfig = null; - newTunnel.getConfigAsync().thenAccept(this::onConfigLoaded); - originalName = newTunnel.getName(); - localName.set(originalName); - } else { - localConfig = new Config(); - if (binding != null && isViewStateRestored) - binding.setConfig(localConfig); - originalName = null; - localName.set(""); - } - localTunnel = newTunnel; - } - - private void onTunnelCreated(final Tunnel tunnel, final Throwable throwable) { - if (throwable != null) { - Log.e(TAG, "Cannot create tunnel", throwable); - final String message = "Cannot create tunnel: " - + ExceptionLoggers.unwrap(throwable).getMessage(); - if (binding != null) { - final CoordinatorLayout container = binding.mainContainer; - Snackbar.make(container, message, Snackbar.LENGTH_LONG).show(); - } - } else { - Log.d(TAG, "Successfully created tunnel " + tunnel.getName()); - localTunnel = tunnel; - onFinished(); - } - } - - - private void onTunnelRenamed(final Tunnel tunnel, final Throwable throwable) { - if (throwable != null) { - Log.e(TAG, "Cannot rename tunnel", throwable); - final String message = "Cannot rename tunnel: " - + ExceptionLoggers.unwrap(throwable).getMessage(); - if (binding != null) { - final CoordinatorLayout container = binding.mainContainer; - Snackbar.make(container, message, Snackbar.LENGTH_LONG).show(); - } - } else { - Log.d(TAG, "Successfully renamed tunnel to " + tunnel.getName()); - localTunnel = tunnel; - // Now save the rest of configuration changes. - Log.d(TAG, "Attempting to save config of " + tunnel.getName()); - tunnel.setConfig(localConfig) - .whenComplete(this::onConfigSaved); - } - } - - @Override - public void onViewStateRestored(final Bundle savedInstanceState) { - super.onViewStateRestored(savedInstanceState); - binding.setConfig(localConfig); - binding.setName(localName); - isViewStateRestored = true; - } -} diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java new file mode 100644 index 00000000..b5f21ece --- /dev/null +++ b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java @@ -0,0 +1,236 @@ +package com.wireguard.android.fragment; + +import android.app.Activity; +import android.content.Context; +import android.databinding.ObservableField; +import android.os.Bundle; +import android.os.Parcel; +import android.os.Parcelable; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; + +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.TunnelEditorFragmentBinding; +import com.wireguard.android.model.Tunnel; +import com.wireguard.android.model.TunnelManager; +import com.wireguard.android.util.ExceptionLoggers; +import com.wireguard.config.Config; + +/** + * Fragment for editing a WireGuard configuration. + */ + +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 = TunnelEditorFragment.class.getSimpleName(); + + private final ObservableField localName = new ObservableField<>(""); + private TunnelEditorFragmentBinding binding; + private boolean isViewStateRestored; + private Config localConfig = new Config(); + private Tunnel localTunnel; + private String originalName; + + private static T copyParcelable(final T original) { + if (original == null) + return null; + final Parcel parcel = Parcel.obtain(); + parcel.writeParcelable(original, 0); + parcel.setDataPosition(0); + final T copy = parcel.readParcelable(original.getClass().getClassLoader()); + parcel.recycle(); + return copy; + } + + private void onConfigLoaded(final Config config) { + localConfig = copyParcelable(config); + if (binding != null && isViewStateRestored) + binding.setConfig(localConfig); + } + + private void onConfigSaved(final Config config, final Throwable throwable) { + if (throwable != null) { + Log.e(TAG, "Cannot save configuration", throwable); + final String message = "Cannot save configuration: " + + ExceptionLoggers.unwrap(throwable).getMessage(); + if (binding != null) { + final CoordinatorLayout container = binding.mainContainer; + Snackbar.make(container, message, Snackbar.LENGTH_LONG).show(); + } + } else { + Log.d(TAG, "Successfully saved configuration for " + localTunnel.getName()); + onFinished(); + } + } + + @Override + public void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (savedInstanceState != null) { + localConfig = savedInstanceState.getParcelable(KEY_LOCAL_CONFIG); + localName.set(savedInstanceState.getString(KEY_LOCAL_NAME)); + originalName = savedInstanceState.getString(KEY_ORIGINAL_NAME); + } + // Erase the remains of creating or editing a different tunnel. + if (getSelectedTunnel() != null && !getSelectedTunnel().getName().equals(originalName)) { + // The config must be loaded asynchronously since it's not an observable property. + localConfig = null; + getSelectedTunnel().getConfigAsync().thenAccept(this::onConfigLoaded); + originalName = getSelectedTunnel().getName(); + localName.set(originalName); + } else if (getSelectedTunnel() == null && originalName != null) { + localConfig = new Config(); + originalName = null; + localName.set(""); + } + localTunnel = getSelectedTunnel(); + setHasOptionsMenu(true); + } + + @Override + public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { + inflater.inflate(R.menu.config_editor, menu); + } + + @Override + public View onCreateView(final LayoutInflater inflater, final ViewGroup container, + final Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState); + binding = TunnelEditorFragmentBinding.inflate(inflater, container, false); + binding.executePendingBindings(); + return binding.getRoot(); + } + + @Override + public void onDestroyView() { + binding = null; + super.onDestroyView(); + } + + private void onFinished() { + // Hide the keyboard; it rarely goes away on its own. + final Activity activity = getActivity(); + final View focusedView = activity.getCurrentFocus(); + if (focusedView != null) { + final Object service = activity.getSystemService(Context.INPUT_METHOD_SERVICE); + final InputMethodManager inputManager = (InputMethodManager) service; + if (inputManager != null) + inputManager.hideSoftInputFromWindow(focusedView.getWindowToken(), + InputMethodManager.HIDE_NOT_ALWAYS); + } + // Tell the activity to finish itself or go back to the detail view. + getActivity().runOnUiThread(() -> { + // The selected tunnel has to actually change, but we have to remember this one. + final Tunnel savedTunnel = localTunnel; + if (savedTunnel == getSelectedTunnel()) + setSelectedTunnel(null); + setSelectedTunnel(savedTunnel); + }); + } + + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_action_save: + if (getSelectedTunnel() == null) { + Log.d(TAG, "Attempting to create new tunnel " + localName.get()); + final TunnelManager manager = Application.getComponent().getTunnelManager(); + manager.create(localName.get(), localConfig) + .whenComplete(this::onTunnelCreated); + } else if (!getSelectedTunnel().getName().equals(localName.get())) { + Log.d(TAG, "Attempting to rename tunnel to " + localName.get()); + getSelectedTunnel().rename(localName.get()) + .whenComplete(this::onTunnelRenamed); + } else { + Log.d(TAG, "Attempting to save config of " + getSelectedTunnel().getName()); + getSelectedTunnel().setConfig(localConfig) + .whenComplete(this::onConfigSaved); + } + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + @Override + public void onSaveInstanceState(final Bundle outState) { + outState.putParcelable(KEY_LOCAL_CONFIG, localConfig); + outState.putString(KEY_LOCAL_NAME, localName.get()); + outState.putString(KEY_ORIGINAL_NAME, originalName); + super.onSaveInstanceState(outState); + } + + @Override + public void onSelectedTunnelChanged(final Tunnel oldTunnel, final Tunnel newTunnel) { + // Erase the remains of creating or editing a different tunnel. + if (newTunnel != null) { + // The config must be loaded asynchronously since it's not an observable property. + localConfig = null; + newTunnel.getConfigAsync().thenAccept(this::onConfigLoaded); + originalName = newTunnel.getName(); + localName.set(originalName); + } else { + localConfig = new Config(); + if (binding != null && isViewStateRestored) + binding.setConfig(localConfig); + originalName = null; + localName.set(""); + } + localTunnel = newTunnel; + } + + private void onTunnelCreated(final Tunnel tunnel, final Throwable throwable) { + if (throwable != null) { + Log.e(TAG, "Cannot create tunnel", throwable); + final String message = "Cannot create tunnel: " + + ExceptionLoggers.unwrap(throwable).getMessage(); + if (binding != null) { + final CoordinatorLayout container = binding.mainContainer; + Snackbar.make(container, message, Snackbar.LENGTH_LONG).show(); + } + } else { + Log.d(TAG, "Successfully created tunnel " + tunnel.getName()); + localTunnel = tunnel; + onFinished(); + } + } + + + private void onTunnelRenamed(final Tunnel tunnel, final Throwable throwable) { + if (throwable != null) { + Log.e(TAG, "Cannot rename tunnel", throwable); + final String message = "Cannot rename tunnel: " + + ExceptionLoggers.unwrap(throwable).getMessage(); + if (binding != null) { + final CoordinatorLayout container = binding.mainContainer; + Snackbar.make(container, message, Snackbar.LENGTH_LONG).show(); + } + } else { + Log.d(TAG, "Successfully renamed tunnel to " + tunnel.getName()); + localTunnel = tunnel; + // Now save the rest of configuration changes. + Log.d(TAG, "Attempting to save config of " + tunnel.getName()); + tunnel.setConfig(localConfig) + .whenComplete(this::onConfigSaved); + } + } + + @Override + public void onViewStateRestored(final Bundle savedInstanceState) { + super.onViewStateRestored(savedInstanceState); + binding.setConfig(localConfig); + binding.setName(localName); + isViewStateRestored = true; + } +} 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 { 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); } -- cgit v1.2.3