summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard/android
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2018-04-30 11:39:12 -0500
committerSamuel Holland <samuel@sholland.org>2018-04-30 11:39:12 -0500
commit7eedf08d4bbe8d15a38cde777d92e72930ffa2e8 (patch)
tree12293719d001f3eef3a54244688279e62e2513a1 /app/src/main/java/com/wireguard/android
parente2636320b7faa372d724732265b380ef85b7d83e (diff)
global: Automatic code formatting
Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app/src/main/java/com/wireguard/android')
-rw-r--r--app/src/main/java/com/wireguard/android/Application.java4
-rw-r--r--app/src/main/java/com/wireguard/android/activity/SettingsActivity.java28
-rw-r--r--app/src/main/java/com/wireguard/android/backend/GoBackend.java58
-rw-r--r--app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java8
-rw-r--r--app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java102
-rw-r--r--app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java20
-rw-r--r--app/src/main/java/com/wireguard/android/model/TunnelManager.java18
-rw-r--r--app/src/main/java/com/wireguard/android/preference/ZipExporterPreference.java31
8 files changed, 131 insertions, 138 deletions
diff --git a/app/src/main/java/com/wireguard/android/Application.java b/app/src/main/java/com/wireguard/android/Application.java
index c1b21373..f3cf0887 100644
--- a/app/src/main/java/com/wireguard/android/Application.java
+++ b/app/src/main/java/com/wireguard/android/Application.java
@@ -55,11 +55,11 @@ public class Application extends android.app.Application {
public interface ApplicationComponent {
AsyncWorker getAsyncWorker();
+ Class getBackendType();
+
ToolsInstaller getToolsInstaller();
TunnelManager getTunnelManager();
-
- Class getBackendType();
}
@Qualifier
diff --git a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
index e48b6d88..fb5e7a09 100644
--- a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
+++ b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
@@ -23,11 +23,6 @@ import java.util.List;
*/
public class SettingsActivity extends AppCompatActivity {
- @FunctionalInterface
- public interface PermissionRequestCallback {
- void done(String[] permissions, int[] grantResults);
- }
-
private HashMap<Integer, PermissionRequestCallback> permissionRequestCallbacks = new HashMap<>();
private int permissionRequestCounter = 0;
@@ -49,15 +44,6 @@ public class SettingsActivity extends AppCompatActivity {
}
@Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- final PermissionRequestCallback f = permissionRequestCallbacks.get(requestCode);
- if (f != null) {
- permissionRequestCallbacks.remove(requestCode);
- f.done(permissions, grantResults);
- }
- }
-
- @Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
@@ -78,6 +64,20 @@ public class SettingsActivity extends AppCompatActivity {
}
}
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ final PermissionRequestCallback f = permissionRequestCallbacks.get(requestCode);
+ if (f != null) {
+ permissionRequestCallbacks.remove(requestCode);
+ f.done(permissions, grantResults);
+ }
+ }
+
+ @FunctionalInterface
+ public interface PermissionRequestCallback {
+ void done(String[] permissions, int[] grantResults);
+ }
+
public static class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(final Bundle savedInstanceState, final String key) {
diff --git a/app/src/main/java/com/wireguard/android/backend/GoBackend.java b/app/src/main/java/com/wireguard/android/backend/GoBackend.java
index 8201b116..519f7427 100644
--- a/app/src/main/java/com/wireguard/android/backend/GoBackend.java
+++ b/app/src/main/java/com/wireguard/android/backend/GoBackend.java
@@ -27,48 +27,20 @@ import java9.util.concurrent.CompletableFuture;
public final class GoBackend implements Backend {
private static final String TAG = "WireGuard/" + GoBackend.class.getSimpleName();
+ private static CompletableFuture<VpnService> vpnService = new CompletableFuture<>();
static {
System.loadLibrary("wg-go");
}
+ private Context context;
private Tunnel currentTunnel;
private int currentTunnelHandle = -1;
- private Context context;
-
public GoBackend(Context context) {
this.context = context;
}
- private void startVpnService() {
- context.startService(new Intent(context, VpnService.class));
- }
-
- public static class VpnService extends android.net.VpnService {
- @Override
- public void onCreate() {
- vpnService.complete(this);
- super.onCreate();
- }
-
- @Override
- public void onDestroy() {
- for (final Tunnel tunnel : Application.getComponent().getTunnelManager().getTunnels()) {
- if (tunnel != null && tunnel.getState() != State.DOWN)
- tunnel.setState(State.DOWN);
- }
- vpnService = vpnService.newIncompleteFuture();
- super.onDestroy();
- }
-
- public Builder getBuilder() {
- return new Builder();
- }
- }
-
- private static CompletableFuture<VpnService> vpnService = new CompletableFuture<>();
-
private static native int wgGetSocketV4(int handle);
private static native int wgGetSocketV6(int handle);
@@ -219,4 +191,30 @@ public final class GoBackend implements Backend {
currentTunnelHandle = -1;
}
}
+
+ private void startVpnService() {
+ context.startService(new Intent(context, VpnService.class));
+ }
+
+ public static class VpnService extends android.net.VpnService {
+ public Builder getBuilder() {
+ return new Builder();
+ }
+
+ @Override
+ public void onCreate() {
+ vpnService.complete(this);
+ super.onCreate();
+ }
+
+ @Override
+ public void onDestroy() {
+ for (final Tunnel tunnel : Application.getComponent().getTunnelManager().getTunnels()) {
+ if (tunnel != null && tunnel.getState() != State.DOWN)
+ tunnel.setState(State.DOWN);
+ }
+ vpnService = vpnService.newIncompleteFuture();
+ super.onDestroy();
+ }
+ }
}
diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java
index 8d0ae4cf..01fa594b 100644
--- a/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java
+++ b/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java
@@ -20,6 +20,10 @@ import com.wireguard.config.Config;
public class TunnelDetailFragment extends BaseFragment {
private TunnelDetailFragmentBinding binding;
+ private void onConfigLoaded(final String name, final Config config) {
+ binding.setConfig(new Config.Observable(config, name));
+ }
+
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -46,10 +50,6 @@ public class TunnelDetailFragment extends BaseFragment {
super.onDestroyView();
}
- private void onConfigLoaded(final String name, final Config config) {
- binding.setConfig(new Config.Observable(config, name));
- }
-
@Override
public void onSelectedTunnelChanged(final Tunnel oldTunnel, final Tunnel newTunnel) {
if (binding == null)
diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java
index b7467b14..a3760ed9 100644
--- a/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java
+++ b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java
@@ -3,8 +3,6 @@ package com.wireguard.android.fragment;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
-import android.os.Parcel;
-import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
@@ -41,6 +39,24 @@ public class TunnelEditorFragment extends BaseFragment {
binding.setConfig(new Config.Observable(config, name));
}
+ private void onConfigSaved(final Tunnel savedTunnel, final Config config,
+ final Throwable throwable) {
+ final String message;
+ if (throwable == null) {
+ message = getString(R.string.config_save_success, savedTunnel.getName());
+ Log.d(TAG, message);
+ onFinished();
+ } else {
+ final String error = ExceptionLoggers.unwrap(throwable).getMessage();
+ message = getString(R.string.config_save_error, savedTunnel.getName(), error);
+ Log.e(TAG, message, throwable);
+ if (binding != null) {
+ final CoordinatorLayout container = binding.mainContainer;
+ Snackbar.make(container, message, Snackbar.LENGTH_LONG).show();
+ }
+ }
+ }
+
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -48,40 +64,6 @@ public class TunnelEditorFragment extends BaseFragment {
}
@Override
- public void onSelectedTunnelChanged(final Tunnel oldTunnel, final Tunnel newTunnel) {
- tunnel = newTunnel;
- if (binding == null)
- return;
- binding.setConfig(new Config.Observable(null, null));
- if (tunnel != null)
- tunnel.getConfigAsync().thenAccept(a -> onConfigLoaded(tunnel.getName(), a));
- }
-
- @Override
- public void onSaveInstanceState(@NonNull final Bundle outState) {
- outState.putParcelable(KEY_LOCAL_CONFIG, binding.getConfig());
- outState.putString(KEY_ORIGINAL_NAME, tunnel == null ? null : tunnel.getName());
- super.onSaveInstanceState(outState);
- }
-
- @Override
- public void onViewStateRestored(final Bundle savedInstanceState) {
- if (savedInstanceState == null) {
- onSelectedTunnelChanged(null, getSelectedTunnel());
- } else {
- tunnel = getSelectedTunnel();
- Config.Observable config = savedInstanceState.getParcelable(KEY_LOCAL_CONFIG);
- String originalName = savedInstanceState.getString(KEY_ORIGINAL_NAME);
- if (tunnel != null && !tunnel.getName().equals(originalName))
- onSelectedTunnelChanged(null, tunnel);
- else
- binding.setConfig(config);
- }
-
- super.onViewStateRestored(savedInstanceState);
- }
-
- @Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
inflater.inflate(R.menu.config_editor, menu);
}
@@ -159,22 +141,21 @@ public class TunnelEditorFragment extends BaseFragment {
}
}
- private void onConfigSaved(final Tunnel savedTunnel, final Config config,
- final Throwable throwable) {
- final String message;
- if (throwable == null) {
- message = getString(R.string.config_save_success, savedTunnel.getName());
- Log.d(TAG, message);
- onFinished();
- } else {
- final String error = ExceptionLoggers.unwrap(throwable).getMessage();
- message = getString(R.string.config_save_error, savedTunnel.getName(), error);
- Log.e(TAG, message, throwable);
- if (binding != null) {
- final CoordinatorLayout container = binding.mainContainer;
- Snackbar.make(container, message, Snackbar.LENGTH_LONG).show();
- }
- }
+ @Override
+ public void onSaveInstanceState(@NonNull final Bundle outState) {
+ outState.putParcelable(KEY_LOCAL_CONFIG, binding.getConfig());
+ outState.putString(KEY_ORIGINAL_NAME, tunnel == null ? null : tunnel.getName());
+ super.onSaveInstanceState(outState);
+ }
+
+ @Override
+ public void onSelectedTunnelChanged(final Tunnel oldTunnel, final Tunnel newTunnel) {
+ tunnel = newTunnel;
+ if (binding == null)
+ return;
+ binding.setConfig(new Config.Observable(null, null));
+ if (tunnel != null)
+ tunnel.getConfigAsync().thenAccept(a -> onConfigLoaded(tunnel.getName(), a));
}
private void onTunnelCreated(final Tunnel newTunnel, final Throwable throwable) {
@@ -214,4 +195,21 @@ public class TunnelEditorFragment extends BaseFragment {
}
}
}
+
+ @Override
+ public void onViewStateRestored(final Bundle savedInstanceState) {
+ if (savedInstanceState == null) {
+ onSelectedTunnelChanged(null, getSelectedTunnel());
+ } else {
+ tunnel = getSelectedTunnel();
+ Config.Observable config = savedInstanceState.getParcelable(KEY_LOCAL_CONFIG);
+ String originalName = savedInstanceState.getString(KEY_ORIGINAL_NAME);
+ if (tunnel != null && !tunnel.getName().equals(originalName))
+ onSelectedTunnelChanged(null, tunnel);
+ else
+ binding.setConfig(config);
+ }
+
+ super.onViewStateRestored(savedInstanceState);
+ }
}
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 719960af..5291d8fb 100644
--- a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java
+++ b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java
@@ -27,7 +27,6 @@ import android.widget.AbsListView.MultiChoiceModeListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
-import android.widget.TextView;
import com.wireguard.android.Application;
import com.wireguard.android.Application.ApplicationComponent;
@@ -44,7 +43,6 @@ import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.zip.ZipEntry;
@@ -70,6 +68,14 @@ public class TunnelListFragment extends BaseFragment {
private TunnelListFragmentBinding binding;
private TunnelManager tunnelManager;
+ public boolean collapseActionMenu() {
+ if (binding.createMenu.isExpanded()) {
+ binding.createMenu.collapse();
+ return true;
+ }
+ return false;
+ }
+
private void importTunnel(final Uri uri) {
final Activity activity = getActivity();
if (activity == null)
@@ -199,14 +205,6 @@ public class TunnelListFragment extends BaseFragment {
super.onDestroyView();
}
- public boolean collapseActionMenu() {
- if (binding.createMenu.isExpanded()) {
- binding.createMenu.collapse();
- return true;
- }
- return false;
- }
-
public void onRequestCreateConfig(@SuppressWarnings("unused") final View view) {
startActivity(new Intent(getActivity(), TunnelCreatorActivity.class));
if (binding != null)
@@ -254,7 +252,7 @@ public class TunnelListFragment extends BaseFragment {
if (tunnels.size() == 1 && throwables.isEmpty())
message = getString(R.string.import_success, tunnels.get(0).getName());
else if (tunnels.isEmpty() && throwables.size() == 1)
- /* Use the exception message from above. */;
+ /* Use the exception message from above. */ ;
else if (throwables.isEmpty())
message = getString(R.string.import_total_success, tunnels.size());
else if (!throwables.isEmpty())
diff --git a/app/src/main/java/com/wireguard/android/model/TunnelManager.java b/app/src/main/java/com/wireguard/android/model/TunnelManager.java
index e4667c82..72980f5e 100644
--- a/app/src/main/java/com/wireguard/android/model/TunnelManager.java
+++ b/app/src/main/java/com/wireguard/android/model/TunnelManager.java
@@ -128,15 +128,6 @@ public final class TunnelManager extends BaseObservable {
return tunnels;
}
- public void refreshTunnelStates() {
- asyncWorker.supplyAsync(backend::enumerate)
- .thenAccept(running -> {
- for (final Tunnel tunnel : tunnels)
- tunnel.onStateChanged(running.contains(tunnel.getName()) ? State.UP : State.DOWN);
- })
- .whenComplete(ExceptionLoggers.E);
- }
-
public void onCreate() {
asyncWorker.supplyAsync(configStore::enumerate)
.thenAcceptBoth(asyncWorker.supplyAsync(backend::enumerate), this::onTunnelsLoaded)
@@ -151,6 +142,15 @@ public final class TunnelManager extends BaseObservable {
setLastUsedTunnel(tunnels.get(lastUsedName));
}
+ public void refreshTunnelStates() {
+ asyncWorker.supplyAsync(backend::enumerate)
+ .thenAccept(running -> {
+ for (final Tunnel tunnel : tunnels)
+ tunnel.onStateChanged(running.contains(tunnel.getName()) ? State.UP : State.DOWN);
+ })
+ .whenComplete(ExceptionLoggers.E);
+ }
+
public CompletionStage<Void> restoreState() {
if (!preferences.getBoolean(KEY_RESTORE_ON_BOOT, false))
return CompletableFuture.completedFuture(null);
diff --git a/app/src/main/java/com/wireguard/android/preference/ZipExporterPreference.java b/app/src/main/java/com/wireguard/android/preference/ZipExporterPreference.java
index 421be1df..b10d8388 100644
--- a/app/src/main/java/com/wireguard/android/preference/ZipExporterPreference.java
+++ b/app/src/main/java/com/wireguard/android/preference/ZipExporterPreference.java
@@ -6,9 +6,9 @@ import android.content.pm.PackageManager;
import android.os.Environment;
import android.support.design.widget.Snackbar;
import android.support.v7.preference.Preference;
-import android.view.ContextThemeWrapper;
import android.util.AttributeSet;
import android.util.Log;
+import android.view.ContextThemeWrapper;
import com.wireguard.android.Application;
import com.wireguard.android.Application.ApplicationComponent;
@@ -25,7 +25,6 @@ import java.io.FileOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
-import java.util.Objects;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@@ -50,19 +49,6 @@ public class ZipExporterPreference extends Preference {
tunnelManager = applicationComponent.getTunnelManager();
}
- @Override
- public CharSequence getSummary() {
- if (exportedFilePath == null)
- return getContext().getString(R.string.export_summary);
- else
- return getContext().getString(R.string.export_success, exportedFilePath);
- }
-
- @Override
- public CharSequence getTitle() {
- return getContext().getString(R.string.zip_exporter_title);
- }
-
private void exportZip() {
List<Tunnel> tunnels = new ArrayList<>(tunnelManager.getTunnels());
List<CompletableFuture<Config>> futureConfigs = new ArrayList<>(tunnels.size());
@@ -124,9 +110,22 @@ public class ZipExporterPreference extends Preference {
}
@Override
+ public CharSequence getSummary() {
+ if (exportedFilePath == null)
+ return getContext().getString(R.string.export_summary);
+ else
+ return getContext().getString(R.string.export_success, exportedFilePath);
+ }
+
+ @Override
+ public CharSequence getTitle() {
+ return getContext().getString(R.string.zip_exporter_title);
+ }
+
+ @Override
protected void onClick() {
getPrefActivity(this).ensurePermissions(
- new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE},
+ new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
(permissions, granted) -> {
if (granted.length > 0 && granted[0] == PackageManager.PERMISSION_GRANTED)
exportZip();