diff options
author | Samuel Holland <samuel@sholland.org> | 2018-09-05 18:33:42 -0500 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-11-11 21:50:23 -0600 |
commit | a264f7ab36bf1335999d53cb4a0d753c54b231d0 (patch) | |
tree | 8adb020e43111ff0420569c16c8c529f69b6a0e5 /app/src/main/java/com/wireguard/android/Application.java | |
parent | 4e134772d7d2fea02722a87e413947965764fef8 (diff) |
Auto-format the source directories
Blame Jason for writing Java in vim.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/Application.java')
-rw-r--r-- | app/src/main/java/com/wireguard/android/Application.java | 106 |
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(); |