From d645d698475f986d8be8a0c9c96f2cd9b5dd153d 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 --- app/src/main/AndroidManifest.xml | 2 +- .../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 +-- app/src/main/res/drawable/ic_action_add.xml | 12 +- app/src/main/res/drawable/ic_action_delete.xml | 12 +- .../main/res/drawable/ic_action_delete_black.xml | 12 +- app/src/main/res/drawable/ic_action_edit.xml | 12 +- app/src/main/res/drawable/ic_action_open.xml | 12 +- app/src/main/res/drawable/ic_settings.xml | 12 +- app/src/main/res/drawable/ic_tile.xml | 26 +-- app/src/main/res/drawable/ic_tile_disabled.xml | 30 +-- app/src/main/res/layout/config_editor_fragment.xml | 233 -------------------- app/src/main/res/layout/config_editor_peer.xml | 142 ------------- app/src/main/res/layout/tunnel_detail_fragment.xml | 2 +- app/src/main/res/layout/tunnel_editor_fragment.xml | 233 ++++++++++++++++++++ app/src/main/res/layout/tunnel_editor_peer.xml | 142 +++++++++++++ app/src/main/res/values/strings.xml | 32 +-- app/src/main/res/xml/preferences.xml | 2 +- 25 files changed, 716 insertions(+), 748 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 delete mode 100644 app/src/main/res/layout/config_editor_fragment.xml delete mode 100644 app/src/main/res/layout/config_editor_peer.xml create mode 100644 app/src/main/res/layout/tunnel_editor_fragment.xml create mode 100644 app/src/main/res/layout/tunnel_editor_peer.xml (limited to 'app/src') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0b44214e..37485ef0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -37,7 +37,7 @@ + android:label="@string/create_activity_title" /> 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); } diff --git a/app/src/main/res/drawable/ic_action_add.xml b/app/src/main/res/drawable/ic_action_add.xml index cc03f232..d4e66388 100644 --- a/app/src/main/res/drawable/ic_action_add.xml +++ b/app/src/main/res/drawable/ic_action_add.xml @@ -1,9 +1,9 @@ + android:width="24dp" + android:height="24dp" + android:viewportHeight="24" + android:viewportWidth="24"> + android:fillColor="#FFFFFF" + android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" /> diff --git a/app/src/main/res/drawable/ic_action_delete.xml b/app/src/main/res/drawable/ic_action_delete.xml index b45a975d..617ba001 100644 --- a/app/src/main/res/drawable/ic_action_delete.xml +++ b/app/src/main/res/drawable/ic_action_delete.xml @@ -1,9 +1,9 @@ + android:width="24dp" + android:height="24dp" + android:viewportHeight="24" + android:viewportWidth="24"> + android:fillColor="#FFFFFF" + android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z" /> diff --git a/app/src/main/res/drawable/ic_action_delete_black.xml b/app/src/main/res/drawable/ic_action_delete_black.xml index 8566a379..8fc53e7b 100644 --- a/app/src/main/res/drawable/ic_action_delete_black.xml +++ b/app/src/main/res/drawable/ic_action_delete_black.xml @@ -1,9 +1,9 @@ + android:width="24dp" + android:height="24dp" + android:viewportHeight="24" + android:viewportWidth="24"> + android:fillColor="#000000" + android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z" /> diff --git a/app/src/main/res/drawable/ic_action_edit.xml b/app/src/main/res/drawable/ic_action_edit.xml index 95d5392c..a0607f54 100644 --- a/app/src/main/res/drawable/ic_action_edit.xml +++ b/app/src/main/res/drawable/ic_action_edit.xml @@ -1,9 +1,9 @@ + android:width="24dp" + android:height="24dp" + android:viewportHeight="24" + android:viewportWidth="24"> + android:fillColor="#FFFFFF" + android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z" /> diff --git a/app/src/main/res/drawable/ic_action_open.xml b/app/src/main/res/drawable/ic_action_open.xml index b4fb5a65..ea777109 100644 --- a/app/src/main/res/drawable/ic_action_open.xml +++ b/app/src/main/res/drawable/ic_action_open.xml @@ -1,7 +1,9 @@ - - \ No newline at end of file + android:height="24dp" + android:viewportHeight="24" + android:viewportWidth="24"> + + diff --git a/app/src/main/res/drawable/ic_settings.xml b/app/src/main/res/drawable/ic_settings.xml index f1f4154f..8025452c 100644 --- a/app/src/main/res/drawable/ic_settings.xml +++ b/app/src/main/res/drawable/ic_settings.xml @@ -1,9 +1,9 @@ + android:width="24dp" + android:height="24dp" + android:viewportHeight="24" + android:viewportWidth="24"> + android:fillColor="#FFFFFF" + android:pathData="M19.43,12.98c0.04,-0.32 0.07,-0.64 0.07,-0.98s-0.03,-0.66 -0.07,-0.98l2.11,-1.65c0.19,-0.15 0.24,-0.42 0.12,-0.64l-2,-3.46c-0.12,-0.22 -0.39,-0.3 -0.61,-0.22l-2.49,1c-0.52,-0.4 -1.08,-0.73 -1.69,-0.98l-0.38,-2.65C14.46,2.18 14.25,2 14,2h-4c-0.25,0 -0.46,0.18 -0.49,0.42l-0.38,2.65c-0.61,0.25 -1.17,0.59 -1.69,0.98l-2.49,-1c-0.23,-0.09 -0.49,0 -0.61,0.22l-2,3.46c-0.13,0.22 -0.07,0.49 0.12,0.64l2.11,1.65c-0.04,0.32 -0.07,0.65 -0.07,0.98s0.03,0.66 0.07,0.98l-2.11,1.65c-0.19,0.15 -0.24,0.42 -0.12,0.64l2,3.46c0.12,0.22 0.39,0.3 0.61,0.22l2.49,-1c0.52,0.4 1.08,0.73 1.69,0.98l0.38,2.65c0.03,0.24 0.24,0.42 0.49,0.42h4c0.25,0 0.46,-0.18 0.49,-0.42l0.38,-2.65c0.61,-0.25 1.17,-0.59 1.69,-0.98l2.49,1c0.23,0.09 0.49,0 0.61,-0.22l2,-3.46c0.12,-0.22 0.07,-0.49 -0.12,-0.64l-2.11,-1.65zM12,15.5c-1.93,0 -3.5,-1.57 -3.5,-3.5s1.57,-3.5 3.5,-3.5 3.5,1.57 3.5,3.5 -1.57,3.5 -3.5,3.5z" /> diff --git a/app/src/main/res/drawable/ic_tile.xml b/app/src/main/res/drawable/ic_tile.xml index e231b7a5..eaf784c1 100644 --- a/app/src/main/res/drawable/ic_tile.xml +++ b/app/src/main/res/drawable/ic_tile.xml @@ -1,24 +1,24 @@ + android:width="400dp" + android:height="400dp" + android:viewportHeight="400.0" + android:viewportWidth="400.0"> + android:pathData="m197.7,0c-6.2,0.1 -12.5,0.5 -19,1.1 12.4,2.9 23.5,5.5 34.7,8.1 -0.1,0.7 -0.3,1.4 -0.4,2 -14.9,2 -29.1,-3.5 -43.7,-5.5 5.3,3.1 10.7,6 16.2,8.5 5.6,2.5 11.4,4.7 17.2,7 -7.4,6.3 -14.8,7.7 -24,5.6 -5.1,-1.2 -10.4,-1.8 -15.6,-1.5 -5.3,0.3 -10.7,1.6 -15.6,4.8 5.2,2.6 10,4.8 14.5,7.5 1.9,1.1 4,2.9 4.5,4.9 1.2,4.6 1.6,9.4 2.3,14.1 -8.5,1 -23.5,9.6 -26.5,15.3 13.1,2.5 27.3,-0.5 39.8,7.9 -4.1,3.1 -13.7,7 -17.2,9.6 4.3,1.1 14.4,0.6 18.3,0.3 3.3,-0.2 4.8,-0.3 6.2,0.8l38.5,30.1c4,3.3 20.4,18.7 24.7,28.5 3.6,8.3 4.1,15.3 4.1,17.1 -0,4.6 -0.6,11.8 -3.7,19.9 -1.3,3.4 -5.2,10.9 -13.3,19.6 -12.5,13.5 -28.6,20.9 -46.2,24.5 -40.9,8.4 -74.9,52.1 -65.3,100.2 11.2,56.2 73.2,86.6 123.9,59.9 32.8,-17.3 50.1,-51 45.5,-87.7 -2.8,-22.2 -12.8,-40.2 -29.7,-54.8 -2.2,-1.9 -3.6,-1.9 -6.2,-0.3 -8.7,5.6 -17.7,10.9 -26.8,15.9 -5.2,2.9 -10.9,5 -17.4,7.9 2.2,0.6 3.3,0.9 4.4,1.1 24.4,6.5 37.5,28 31.7,52 -5.1,21.4 -26.8,35 -47.9,31.4 -17.5,-3 -32.8,-17.6 -35.4,-35 -2.8,-19 6.7,-37.3 23.5,-44.9 9.3,-4.2 18.9,-7.9 28.3,-12.2 10.6,-4.9 22.1,-8.7 31.3,-15.5 23,-16.9 37.1,-40.1 42.7,-68.1 3.3,-16.8 3.1,-33.5 -4.6,-49.4 -5.9,-12.2 -15.6,-21.1 -26,-29.2 -10.7,-8.3 -22,-15.9 -32.7,-24.3 -2.9,-2.3 -4.8,-6.2 -6.2,-9.7 -0.6,-1.5 1.3,-5.6 2.5,-5.8 6.5,-1.2 13.2,-1.8 19.8,-2 7.7,-0.3 15.4,-0 23,0.1 1.7,0 3.9,-0.2 4.9,0.7 4,3.9 7.1,1.4 9.9,-1.2 2.3,-2.2 4,-5 5.8,-7.5 -1.1,-0.2 -3.4,-0.7 -5.7,-0.8 -7.7,-0.2 -15.4,-0.1 -23.2,-0.3 -1.4,-0.1 -2.7,-1.5 -4,-2.2 1.4,-0.6 2.8,-1.6 4.3,-1.6 13.3,-0.1 26.6,-0.1 40,-0.1 0,-6.9 -9.2,-16.4 -17.5,-19 -0.1,0.9 -0.1,1.8 -0.2,2.7 -8.2,0.2 -16.2,0 -23.5,-3.8 -1.9,-1 -3.2,-3.3 -4.7,-5 -2,-2.1 -3.6,-4.9 -6,-6.3 -4.9,-2.9 -10.3,-4.9 -15.4,-7.4C224.3,1.7 211.3,-0.1 197.7,0ZM249.6,29.4c0.6,-0 1.2,0.2 1.9,0.8 1,0.8 2,1.7 3.3,2.8 -1.5,0.8 -2.8,1.5 -4.1,2.2 -1.8,0.9 -3.1,0.3 -4.2,-1.1 -0.9,-1.2 -1,-2.3 0.3,-3.3 0.9,-0.7 1.8,-1.3 2.9,-1.3z" + android:strokeColor="#00000000" + android:strokeWidth="1.33333325" /> + android:pathData="m97.9,307.6c-7.8,2 -15.4,4.9 -23.4,7.5 3.9,-26.3 34.7,-50.6 60.8,-47.8 -8.1,10.9 -11.8,23.3 -12.7,35.6 -8.7,1.6 -16.8,2.7 -24.8,4.7" + android:strokeColor="#00000000" + android:strokeWidth="1.33333325" /> + android:pathData="m134.3,124c41.3,-25.3 94,-9.8 113.8,28.2 3.7,7.2 4.2,18.3 1.8,25.8 -8.2,26.1 -27.5,40.7 -54.1,46.9 7.8,-6.7 14.1,-14.3 16,-24.8 2,-10.6 -0.1,-20.1 -6.2,-28.8 -9.3,-13.2 -27.3,-18.6 -42.4,-12.9 -16.3,6.2 -25.3,21.1 -23.7,39.4 1.5,17 14.4,28.1 38.6,32.2 -3.6,1.9 -6.4,3.3 -9.1,4.8 -11.1,6.2 -20.7,14.3 -28.2,24.6 -2.5,3.3 -4.1,3.6 -7.9,1.3 -48.6,-29.7 -51.7,-104.3 1.4,-136.8" + android:strokeColor="#00000000" + android:strokeWidth="1.33333325" /> diff --git a/app/src/main/res/drawable/ic_tile_disabled.xml b/app/src/main/res/drawable/ic_tile_disabled.xml index e99f0ee3..3109c39a 100644 --- a/app/src/main/res/drawable/ic_tile_disabled.xml +++ b/app/src/main/res/drawable/ic_tile_disabled.xml @@ -1,29 +1,29 @@ + android:width="400dp" + android:height="400dp" + android:viewportHeight="400.0" + android:viewportWidth="400.0"> + android:pathData="M197.7,0C191.5,0.1 185.2,0.5 178.7,1.1C191.1,4 202.2,6.6 213.4,9.2C213.3,9.8 213.1,10.5 213,11.2C198.1,13.2 183.9,7.7 169.3,5.7C174.6,8.8 180,11.7 185.5,14.2C191.2,16.7 197,18.8 202.8,21.2C195.4,27.5 188,28.8 178.7,26.7C173.7,25.6 168.3,25 163.1,25.2C157.8,25.5 152.4,26.8 147.5,30C152.7,32.7 157.5,34.8 162.1,37.5C163.9,38.6 166.1,40.4 166.6,42.4C167.8,46.9 168.2,51.8 168.9,56.5C160.4,57.5 145.4,66.1 142.4,71.7C155.5,74.3 169.7,71.2 182.2,79.6C178.1,82.8 168.5,86.6 165,89.3C169.3,90.4 179.4,89.9 183.3,89.6C186.6,89.4 188.2,89.3 189.5,90.4L228,120.6C232.1,123.8 248.4,139.3 252.7,149C256.3,157.3 256.8,164.4 256.8,166.1C256.8,170.7 256.2,177.9 253,186C252.7,186.9 252,188.3 251.2,189.8L280.8,219.4C288.3,207.7 293.4,194.5 296.3,180C299.6,163.2 299.4,146.5 291.7,130.5C285.8,118.3 276.1,109.4 265.8,101.3C255.1,93 243.7,85.4 233.1,77C230.2,74.8 228.3,70.8 226.9,67.3C226.4,65.8 228.2,61.7 229.4,61.5C236,60.3 242.6,59.7 249.3,59.4C256.9,59.2 264.6,59.4 272.3,59.5C274,59.5 276.2,59.3 277.2,60.3C281.2,64.2 284.3,61.6 287,59.1C289.4,56.9 291,54 292.9,51.6C291.7,51.4 289.4,50.9 287.1,50.8C279.4,50.6 271.7,50.7 264,50.5C262.6,50.4 261.3,49 259.9,48.2C261.3,47.6 262.8,46.6 264.2,46.6C277.5,46.5 290.8,46.5 304.1,46.5C304.2,39.6 294.9,30.1 286.7,27.5C286.6,28.5 286.5,29.3 286.5,30.3C278.3,30.5 270.3,30.3 263,26.4C261.1,25.4 259.8,23.1 258.3,21.5C256.3,19.3 254.7,16.6 252.3,15.2C247.4,12.3 242,10.3 236.9,7.8C224.3,1.7 211.3,-0.1 197.7,0zM249.6,29.4C250.3,29.4 250.9,29.6 251.6,30.2C252.6,31 253.6,31.9 254.8,33C253.3,33.8 252,34.5 250.8,35.1C249,36 247.6,35.4 246.5,34C245.6,32.8 245.5,31.7 246.8,30.7C247.7,30 248.6,29.4 249.6,29.4zM231.8,213C220.7,221.9 207.6,227.2 193.6,230.1C152.7,238.5 118.7,282.2 128.3,330.3C139.5,386.5 201.5,416.9 252.2,390.2C285,372.9 302.3,339.2 297.7,302.5C295.9,288.1 291,275.4 283.1,264.3L265.1,246.3C264.2,246.2 263.2,246.6 261.9,247.5C253.1,253.1 244.2,258.4 235.1,263.4C229.9,266.2 224.2,268.3 217.7,271.2C219.9,271.8 221,272.1 222.1,272.4C246.5,278.9 259.6,300.3 253.8,324.4C248.7,345.7 227,359.4 205.9,355.8C188.4,352.8 173.1,338.2 170.5,320.8C167.8,301.8 177.2,283.5 194.1,275.9C203.4,271.6 213,267.9 222.3,263.6C232.9,258.7 244.4,254.9 253.6,248.1C256.2,246.2 258.7,244.2 261,242.2L231.8,213z" + android:strokeColor="#00000000" + android:strokeWidth="1.3750788" /> + android:pathData="m97.9,307.6c-7.8,2 -15.4,4.9 -23.4,7.5 3.9,-26.3 34.7,-50.6 60.8,-47.8 -8.1,10.9 -11.8,23.3 -12.7,35.6 -8.7,1.6 -16.8,2.7 -24.8,4.7" + android:strokeColor="#00000000" + android:strokeWidth="1.3750788" /> + android:pathData="M177,111.6C175.7,111.6 174.4,111.7 173.1,111.7L247,185.6C248.1,183.2 249,180.6 249.9,177.9C252.2,170.4 251.8,159.3 248,152.1C234.7,126.6 206.6,111.3 177,111.6zM139.7,120.9C137.9,121.8 136.1,122.9 134.3,124C81.2,156.4 84.3,231 132.9,260.7C136.6,263 138.3,262.7 140.8,259.4C148.4,249.2 157.9,241.1 169,234.9C171.7,233.3 174.5,231.9 178.1,230C154,225.8 141.1,214.8 139.6,197.8C137.9,179.4 146.9,164.5 163.2,158.3C167,156.9 171,156.2 174.9,156.1L139.7,120.9zM212.5,193.7C212.5,195.8 212.3,197.9 211.8,200.1C209.9,210.5 203.6,218.1 195.8,224.8C208.5,221.9 219.6,216.9 228.6,209.7L212.5,193.7z" + android:strokeColor="#00000000" + android:strokeWidth="1.3750788" /> + android:pathData="M78.4,59.6l262,262l-21.3,21.3l-262,-262z" + android:strokeWidth="0.82064575" /> diff --git a/app/src/main/res/layout/config_editor_fragment.xml b/app/src/main/res/layout/config_editor_fragment.xml deleted file mode 100644 index c0895656..00000000 --- a/app/src/main/res/layout/config_editor_fragment.xml +++ /dev/null @@ -1,233 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -