aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app/src/main/java/com/wireguard/android/Application.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/wireguard/android/Application.java')
-rw-r--r--app/src/main/java/com/wireguard/android/Application.java106
1 files changed, 54 insertions, 52 deletions
diff --git a/app/src/main/java/com/wireguard/android/Application.java b/app/src/main/java/com/wireguard/android/Application.java
index d528629a..9921f615 100644
--- a/app/src/main/java/com/wireguard/android/Application.java
+++ b/app/src/main/java/com/wireguard/android/Application.java
@@ -53,18 +53,50 @@ import java9.util.concurrent.CompletableFuture;
compress = true)
public class Application extends android.app.Application {
@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 RootShell rootShell;
@SuppressWarnings("NullableProblems") private SharedPreferences sharedPreferences;
@SuppressWarnings("NullableProblems") private ToolsInstaller toolsInstaller;
@SuppressWarnings("NullableProblems") private TunnelManager tunnelManager;
- @Nullable private Backend backend;
- private final CompletableFuture<Backend> futureBackend = new CompletableFuture<>();
public Application() {
weakSelf = new WeakReference<>(this);
}
+ public static Application get() {
+ return weakSelf.get();
+ }
+
+ public static AsyncWorker getAsyncWorker() {
+ return get().asyncWorker;
+ }
+
+ public static Backend getBackend() {
+ final Application app = get();
+ synchronized (app.futureBackend) {
+ if (app.backend == null) {
+ Backend backend = null;
+ if (new File("/sys/module/wireguard").exists()) {
+ try {
+ app.rootShell.start();
+ backend = new WgQuickBackend(app.getApplicationContext());
+ } catch (final Exception ignored) {
+ }
+ }
+ if (backend == null)
+ backend = new GoBackend(app.getApplicationContext());
+ app.backend = backend;
+ }
+ return app.backend;
+ }
+ }
+
+ public static CompletableFuture<Backend> getBackendAsync() {
+ return get().futureBackend;
+ }
+
/* The ACRA password can be trivially reverse engineered and is open source anyway,
* so there's no point in trying to protect it. However, we do want to at least
* prevent innocent self-builders from uploading stuff to our crash reporter. So, we
@@ -91,12 +123,30 @@ public class Application extends android.app.Application {
return "F-Droid";
}
}
- } catch (final Exception ignored) { }
+ } catch (final Exception ignored) {
+ }
}
- } catch (final Exception ignored) { }
+ } catch (final Exception ignored) {
+ }
return null;
}
+ public static RootShell getRootShell() {
+ return get().rootShell;
+ }
+
+ public static SharedPreferences getSharedPreferences() {
+ return get().sharedPreferences;
+ }
+
+ public static ToolsInstaller getToolsInstaller() {
+ return get().toolsInstaller;
+ }
+
+ public static TunnelManager getTunnelManager() {
+ return get().tunnelManager;
+ }
+
@Override
protected void attachBaseContext(final Context context) {
super.attachBaseContext(context);
@@ -117,54 +167,6 @@ public class Application extends android.app.Application {
}
}
- public static Application get() {
- return weakSelf.get();
- }
-
- public static AsyncWorker getAsyncWorker() {
- return get().asyncWorker;
- }
-
- public static Backend getBackend() {
- final Application app = get();
- synchronized (app.futureBackend) {
- if (app.backend == null) {
- Backend backend = null;
- if (new File("/sys/module/wireguard").exists()) {
- try {
- app.rootShell.start();
- backend = new WgQuickBackend(app.getApplicationContext());
- } catch (final Exception ignored) {
- }
- }
- if (backend == null)
- backend = new GoBackend(app.getApplicationContext());
- app.backend = backend;
- }
- return app.backend;
- }
- }
-
- public static CompletableFuture<Backend> getBackendAsync() {
- return get().futureBackend;
- }
-
- public static RootShell getRootShell() {
- return get().rootShell;
- }
-
- public static SharedPreferences getSharedPreferences() {
- return get().sharedPreferences;
- }
-
- public static ToolsInstaller getToolsInstaller() {
- return get().toolsInstaller;
- }
-
- public static TunnelManager getTunnelManager() {
- return get().tunnelManager;
- }
-
@Override
public void onCreate() {
super.onCreate();