summaryrefslogtreecommitdiffhomepage
path: root/ui
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-03-09 12:36:47 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2020-03-09 12:36:47 -0600
commit1c247c7b0afb9ccab8957981fba657d71f2630c5 (patch)
treef3a2f33b3af02d8f72dc03034841835a60d01266 /ui
parente661d9652b13cd7ca3955bf4aa17dda5c4bb7dd4 (diff)
global: format code
Diffstat (limited to 'ui')
-rw-r--r--ui/src/main/java/com/wireguard/android/Application.java25
-rw-r--r--ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java68
-rw-r--r--ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java16
-rw-r--r--ui/src/main/java/com/wireguard/android/model/ObservableTunnel.java14
-rw-r--r--ui/src/main/java/com/wireguard/android/preference/LogExporterPreference.java3
-rw-r--r--ui/src/main/java/com/wireguard/android/preference/VersionPreference.java16
-rw-r--r--ui/src/main/java/com/wireguard/android/util/DownloadsFileSaver.java56
-rw-r--r--ui/src/main/java/com/wireguard/android/util/ErrorMessages.java16
8 files changed, 108 insertions, 106 deletions
diff --git a/ui/src/main/java/com/wireguard/android/Application.java b/ui/src/main/java/com/wireguard/android/Application.java
index 52d5e1ea..6cf4da36 100644
--- a/ui/src/main/java/com/wireguard/android/Application.java
+++ b/ui/src/main/java/com/wireguard/android/Application.java
@@ -37,17 +37,16 @@ import java9.util.concurrent.CompletableFuture;
@NonNullForAll
public class Application extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
- private static final String TAG = "WireGuard/" + Application.class.getSimpleName();
public static final String USER_AGENT = String.format(Locale.ENGLISH, "WireGuard/%s (Android %d; %s; %s; %s %s; %s)", BuildConfig.VERSION_NAME, Build.VERSION.SDK_INT, Build.SUPPORTED_ABIS.length > 0 ? Build.SUPPORTED_ABIS[0] : "unknown ABI", Build.BOARD, Build.MANUFACTURER, Build.MODEL, Build.FINGERPRINT);
-
+ private static final String TAG = "WireGuard/" + Application.class.getSimpleName();
@SuppressWarnings("NullableProblems") private static WeakReference<Application> weakSelf;
private final CompletableFuture<Backend> futureBackend = new CompletableFuture<>();
@SuppressWarnings("NullableProblems") private AsyncWorker asyncWorker;
@Nullable private Backend backend;
+ @SuppressWarnings("NullableProblems") private ModuleLoader moduleLoader;
@SuppressWarnings("NullableProblems") private RootShell rootShell;
@SuppressWarnings("NullableProblems") private SharedPreferences sharedPreferences;
@SuppressWarnings("NullableProblems") private ToolsInstaller toolsInstaller;
- @SuppressWarnings("NullableProblems") private ModuleLoader moduleLoader;
@SuppressWarnings("NullableProblems") private TunnelManager tunnelManager;
public Application() {
@@ -102,6 +101,10 @@ public class Application extends android.app.Application implements SharedPrefer
return get().futureBackend;
}
+ public static ModuleLoader getModuleLoader() {
+ return get().moduleLoader;
+ }
+
public static RootShell getRootShell() {
return get().rootShell;
}
@@ -114,10 +117,6 @@ public class Application extends android.app.Application implements SharedPrefer
return get().toolsInstaller;
}
- public static ModuleLoader getModuleLoader() {
- return get().moduleLoader;
- }
-
public static TunnelManager getTunnelManager() {
return get().tunnelManager;
}
@@ -168,14 +167,14 @@ public class Application extends android.app.Application implements SharedPrefer
}
@Override
- public void onTerminate() {
- sharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
- super.onTerminate();
+ public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
+ if ("multiple_tunnels".equals(key) && backend != null && backend instanceof WgQuickBackend)
+ ((WgQuickBackend) backend).setMultipleTunnels(sharedPreferences.getBoolean(key, false));
}
@Override
- public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
- if ("multiple_tunnels".equals(key) && backend != null && backend instanceof WgQuickBackend)
- ((WgQuickBackend)backend).setMultipleTunnels(sharedPreferences.getBoolean(key, false));
+ public void onTerminate() {
+ sharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
+ super.onTerminate();
}
}
diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java b/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java
index 762efc5d..e2adecc3 100644
--- a/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java
+++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java
@@ -34,8 +34,20 @@ import androidx.databinding.DataBindingUtil;
@NonNullForAll
public class TunnelDetailFragment extends BaseFragment {
@Nullable private TunnelDetailFragmentBinding binding;
- @Nullable private Timer timer;
@Nullable private State lastState = State.TOGGLE;
+ @Nullable private Timer timer;
+
+ private String formatBytes(final long bytes) {
+ if (bytes < 1024)
+ return requireContext().getString(R.string.transfer_bytes, bytes);
+ else if (bytes < 1024 * 1024)
+ return requireContext().getString(R.string.transfer_kibibytes, bytes / 1024.0);
+ else if (bytes < 1024 * 1024 * 1024)
+ return requireContext().getString(R.string.transfer_mibibytes, bytes / (1024.0 * 1024.0));
+ else if (bytes < 1024 * 1024 * 1024 * 1024)
+ return requireContext().getString(R.string.transfer_gibibytes, bytes / (1024.0 * 1024.0 * 1024.0));
+ return requireContext().getString(R.string.transfer_tibibytes, bytes / (1024.0 * 1024.0 * 1024.0) / 1024.0);
+ }
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
@@ -49,27 +61,6 @@ public class TunnelDetailFragment extends BaseFragment {
}
@Override
- public void onStop() {
- super.onStop();
- if (timer != null) {
- timer.cancel();
- timer = null;
- }
- }
-
- @Override
- public void onResume() {
- super.onResume();
- timer = new Timer();
- timer.scheduleAtFixedRate(new TimerTask() {
- @Override
- public void run() {
- updateStats();
- }
- }, 0, 1000);
- }
-
- @Override
public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container,
@Nullable final Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
@@ -87,6 +78,18 @@ public class TunnelDetailFragment extends BaseFragment {
}
@Override
+ public void onResume() {
+ super.onResume();
+ timer = new Timer();
+ timer.scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ updateStats();
+ }
+ }, 0, 1000);
+ }
+
+ @Override
public void onSelectedTunnelChanged(@Nullable final ObservableTunnel oldTunnel, @Nullable final ObservableTunnel newTunnel) {
if (binding == null)
return;
@@ -100,6 +103,15 @@ public class TunnelDetailFragment extends BaseFragment {
}
@Override
+ public void onStop() {
+ super.onStop();
+ if (timer != null) {
+ timer.cancel();
+ timer = null;
+ }
+ }
+
+ @Override
public void onViewStateRestored(@Nullable final Bundle savedInstanceState) {
if (binding == null) {
return;
@@ -110,18 +122,6 @@ public class TunnelDetailFragment extends BaseFragment {
super.onViewStateRestored(savedInstanceState);
}
- private String formatBytes(final long bytes) {
- if (bytes < 1024)
- return requireContext().getString(R.string.transfer_bytes, bytes);
- else if (bytes < 1024*1024)
- return requireContext().getString(R.string.transfer_kibibytes, bytes/1024.0);
- else if (bytes < 1024*1024*1024)
- return requireContext().getString(R.string.transfer_mibibytes, bytes/(1024.0*1024.0));
- else if (bytes < 1024*1024*1024*1024)
- return requireContext().getString(R.string.transfer_gibibytes, bytes/(1024.0*1024.0*1024.0));
- return requireContext().getString(R.string.transfer_tibibytes, bytes/(1024.0*1024.0*1024.0)/1024.0);
- }
-
private void updateStats() {
if (binding == null || !isResumed())
return;
diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java b/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java
index 995a2d59..7ed82f1f 100644
--- a/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java
+++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java
@@ -262,14 +262,6 @@ public class TunnelListFragment extends BaseFragment {
});
}
- private void showSnackbar(final CharSequence message) {
- if (binding != null) {
- final Snackbar snackbar = Snackbar.make(binding.mainContainer, message, Snackbar.LENGTH_LONG);
- snackbar.setAnchorView(binding.createFab);
- snackbar.show();
- }
- }
-
private void onTunnelDeletionFinished(final Integer count, @Nullable final Throwable throwable) {
final String message;
if (throwable == null) {
@@ -337,6 +329,14 @@ public class TunnelListFragment extends BaseFragment {
});
}
+ private void showSnackbar(final CharSequence message) {
+ if (binding != null) {
+ final Snackbar snackbar = Snackbar.make(binding.mainContainer, message, Snackbar.LENGTH_LONG);
+ snackbar.setAnchorView(binding.createFab);
+ snackbar.show();
+ }
+ }
+
private MultiselectableRelativeLayout viewForTunnel(final ObservableTunnel tunnel, final List tunnels) {
return (MultiselectableRelativeLayout) binding.tunnelList.findViewHolderForAdapterPosition(tunnels.indexOf(tunnel)).itemView;
}
diff --git a/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.java b/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.java
index 3a9fa229..b0f8387b 100644
--- a/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.java
+++ b/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.java
@@ -27,12 +27,12 @@ import java9.util.concurrent.CompletionStage;
public class ObservableTunnel extends BaseObservable implements Keyed<String>, Tunnel {
private final TunnelManager manager;
@Nullable private Config config;
- private State state;
private String name;
+ private State state;
@Nullable private Statistics statistics;
ObservableTunnel(final TunnelManager manager, final String name,
- @Nullable final Config config, final State state) {
+ @Nullable final Config config, final State state) {
this.name = name;
this.manager = manager;
this.config = config;
@@ -103,6 +103,11 @@ public class ObservableTunnel extends BaseObservable implements Keyed<String>, T
return name;
}
+ @Override
+ public void onStateChange(final State newState) {
+ onStateChanged(newState);
+ }
+
State onStateChanged(final State state) {
if (state != State.UP)
onStatisticsChanged(null);
@@ -111,11 +116,6 @@ public class ObservableTunnel extends BaseObservable implements Keyed<String>, T
return state;
}
- @Override
- public void onStateChange(final State newState) {
- onStateChanged(newState);
- }
-
@Nullable
Statistics onStatisticsChanged(@Nullable final Statistics statistics) {
this.statistics = statistics;
diff --git a/ui/src/main/java/com/wireguard/android/preference/LogExporterPreference.java b/ui/src/main/java/com/wireguard/android/preference/LogExporterPreference.java
index 43494aaa..32b3e33c 100644
--- a/ui/src/main/java/com/wireguard/android/preference/LogExporterPreference.java
+++ b/ui/src/main/java/com/wireguard/android/preference/LogExporterPreference.java
@@ -47,8 +47,7 @@ public class LogExporterPreference extends Preference {
final Process process = Runtime.getRuntime().exec(new String[]{
"logcat", "-b", "all", "-d", "-v", "threadtime", "*:V"});
try (final BufferedReader stdout = new BufferedReader(new InputStreamReader(process.getInputStream()));
- final BufferedReader stderr = new BufferedReader(new InputStreamReader(process.getErrorStream())))
- {
+ final BufferedReader stderr = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
String line;
while ((line = stdout.readLine()) != null) {
outputFile.getOutputStream().write(line.getBytes());
diff --git a/ui/src/main/java/com/wireguard/android/preference/VersionPreference.java b/ui/src/main/java/com/wireguard/android/preference/VersionPreference.java
index b07df3e5..47266fa8 100644
--- a/ui/src/main/java/com/wireguard/android/preference/VersionPreference.java
+++ b/ui/src/main/java/com/wireguard/android/preference/VersionPreference.java
@@ -28,14 +28,6 @@ import androidx.preference.Preference;
public class VersionPreference extends Preference {
@Nullable private String versionSummary;
- private String getBackendPrettyName(final Context context, final Backend backend) {
- if (backend instanceof GoBackend)
- return context.getString(R.string.type_name_kernel_module);
- if (backend instanceof WgQuickBackend)
- return context.getString(R.string.type_name_go_userspace);
- return "";
- }
-
public VersionPreference(final Context context, final AttributeSet attrs) {
super(context, attrs);
@@ -50,6 +42,14 @@ public class VersionPreference extends Preference {
});
}
+ private String getBackendPrettyName(final Context context, final Backend backend) {
+ if (backend instanceof GoBackend)
+ return context.getString(R.string.type_name_kernel_module);
+ if (backend instanceof WgQuickBackend)
+ return context.getString(R.string.type_name_go_userspace);
+ return "";
+ }
+
@Nullable
@Override
public CharSequence getSummary() {
diff --git a/ui/src/main/java/com/wireguard/android/util/DownloadsFileSaver.java b/ui/src/main/java/com/wireguard/android/util/DownloadsFileSaver.java
index b4772ef4..c1c667f5 100644
--- a/ui/src/main/java/com/wireguard/android/util/DownloadsFileSaver.java
+++ b/ui/src/main/java/com/wireguard/android/util/DownloadsFileSaver.java
@@ -26,30 +26,6 @@ import java.io.OutputStream;
@NonNullForAll
public class DownloadsFileSaver {
- public static class DownloadsFile {
- private Context context;
- private OutputStream outputStream;
- private String fileName;
- private Uri uri;
-
- private DownloadsFile(final Context context, final OutputStream outputStream, final String fileName, final Uri uri) {
- this.context = context;
- this.outputStream = outputStream;
- this.fileName = fileName;
- this.uri = uri;
- }
-
- public OutputStream getOutputStream() { return outputStream; }
- public String getFileName() { return fileName; }
-
- public void delete() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
- context.getContentResolver().delete(uri, null, null);
- else
- new File(fileName).delete();
- }
- }
-
public static DownloadsFile save(final Context context, final String name, final String mimeType, final boolean overwriteExisting) throws Exception {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
final ContentResolver contentResolver = context.getContentResolver();
@@ -89,12 +65,40 @@ public class DownloadsFileSaver {
}
return new DownloadsFile(context, contentStream, path, contentUri);
} else {
- @SuppressWarnings("deprecation")
- final File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
+ @SuppressWarnings("deprecation") final File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
final File file = new File(path, name);
if (!path.isDirectory() && !path.mkdirs())
throw new IOException(context.getString(R.string.create_output_dir_error));
return new DownloadsFile(context, new FileOutputStream(file), file.getAbsolutePath(), null);
}
}
+
+ public static class DownloadsFile {
+ private Context context;
+ private String fileName;
+ private OutputStream outputStream;
+ private Uri uri;
+
+ private DownloadsFile(final Context context, final OutputStream outputStream, final String fileName, final Uri uri) {
+ this.context = context;
+ this.outputStream = outputStream;
+ this.fileName = fileName;
+ this.uri = uri;
+ }
+
+ public void delete() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
+ context.getContentResolver().delete(uri, null, null);
+ else
+ new File(fileName).delete();
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public OutputStream getOutputStream() {
+ return outputStream;
+ }
+ }
}
diff --git a/ui/src/main/java/com/wireguard/android/util/ErrorMessages.java b/ui/src/main/java/com/wireguard/android/util/ErrorMessages.java
index accc7ef7..e266cfed 100644
--- a/ui/src/main/java/com/wireguard/android/util/ErrorMessages.java
+++ b/ui/src/main/java/com/wireguard/android/util/ErrorMessages.java
@@ -51,14 +51,6 @@ public final class ErrorMessages {
BackendException.Reason.TUN_CREATION_ERROR, R.string.tun_create_error,
BackendException.Reason.GO_ACTIVATION_ERROR_CODE, R.string.tunnel_on_error
));
- private static final Map<RootShellException.Reason, Integer> RSE_REASON_MAP = new EnumMap<>(Maps.of(
- RootShellException.Reason.NO_ROOT_ACCESS, R.string.error_root,
- RootShellException.Reason.SHELL_MARKER_COUNT_ERROR, R.string.shell_marker_count_error,
- RootShellException.Reason.SHELL_EXIT_STATUS_READ_ERROR, R.string.shell_exit_status_read_error,
- RootShellException.Reason.SHELL_START_ERROR, R.string.shell_start_error,
- RootShellException.Reason.CREATE_BIN_DIR_ERROR, R.string.create_bin_dir_error,
- RootShellException.Reason.CREATE_TEMP_DIR_ERROR, R.string.create_temp_dir_error
- ));
private static final Map<Format, Integer> KFE_FORMAT_MAP = new EnumMap<>(Maps.of(
Format.BASE64, R.string.key_length_explanation_base64,
Format.BINARY, R.string.key_length_explanation_binary,
@@ -74,6 +66,14 @@ public final class ErrorMessages {
InetNetwork.class, R.string.parse_error_inet_network,
Integer.class, R.string.parse_error_integer
);
+ private static final Map<RootShellException.Reason, Integer> RSE_REASON_MAP = new EnumMap<>(Maps.of(
+ RootShellException.Reason.NO_ROOT_ACCESS, R.string.error_root,
+ RootShellException.Reason.SHELL_MARKER_COUNT_ERROR, R.string.shell_marker_count_error,
+ RootShellException.Reason.SHELL_EXIT_STATUS_READ_ERROR, R.string.shell_exit_status_read_error,
+ RootShellException.Reason.SHELL_START_ERROR, R.string.shell_start_error,
+ RootShellException.Reason.CREATE_BIN_DIR_ERROR, R.string.create_bin_dir_error,
+ RootShellException.Reason.CREATE_TEMP_DIR_ERROR, R.string.create_temp_dir_error
+ ));
private ErrorMessages() {
// Prevent instantiation