aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app/src/main/java/com/wireguard/android/util/ModuleLoader.java
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-03-08 20:20:29 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2020-03-08 20:23:25 -0600
commit7a4af834c213672c65c89b14c75229bf5f2ea4ab (patch)
tree64fad45abe8f1586449b2f1090547d6d57f5b934 /app/src/main/java/com/wireguard/android/util/ModuleLoader.java
parentGoBackend: setConfigureIntent does nothing (diff)
downloadwireguard-android-7a4af834c213672c65c89b14c75229bf5f2ea4ab.tar.xz
wireguard-android-7a4af834c213672c65c89b14c75229bf5f2ea4ab.zip
Backend: do not use singletons
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/util/ModuleLoader.java')
-rw-r--r--app/src/main/java/com/wireguard/android/util/ModuleLoader.java15
1 files changed, 9 insertions, 6 deletions
diff --git a/app/src/main/java/com/wireguard/android/util/ModuleLoader.java b/app/src/main/java/com/wireguard/android/util/ModuleLoader.java
index 7c943d26..bf094a5e 100644
--- a/app/src/main/java/com/wireguard/android/util/ModuleLoader.java
+++ b/app/src/main/java/com/wireguard/android/util/ModuleLoader.java
@@ -9,7 +9,6 @@ import android.content.Context;
import android.system.OsConstants;
import android.util.Base64;
-import com.wireguard.android.Application;
import com.wireguard.android.util.RootShell.RootShellException;
import net.i2p.crypto.eddsa.EdDSAEngine;
@@ -43,12 +42,16 @@ public class ModuleLoader {
private static final String MODULE_URL = "https://download.wireguard.com/android-module/%s";
private static final String MODULE_NAME = "wireguard-%s.ko";
+ private final RootShell rootShell;
+ private final String userAgent;
private final File moduleDir;
private final File tmpDir;
- public ModuleLoader(final Context context) {
+ public ModuleLoader(final Context context, final RootShell rootShell, final String userAgent) {
moduleDir = new File(context.getCacheDir(), "kmod");
tmpDir = new File(context.getCacheDir(), "tmp");
+ this.rootShell = rootShell;
+ this.userAgent = userAgent;
}
public boolean moduleMightExist() {
@@ -56,7 +59,7 @@ public class ModuleLoader {
}
public void loadModule() throws IOException, RootShellException {
- Application.getRootShell().run(null, String.format("insmod \"%s/wireguard-$(sha256sum /proc/version|cut -d ' ' -f 1).ko\"", moduleDir.getAbsolutePath()));
+ rootShell.run(null, String.format("insmod \"%s/wireguard-$(sha256sum /proc/version|cut -d ' ' -f 1).ko\"", moduleDir.getAbsolutePath()));
}
public static boolean isModuleLoaded() {
@@ -124,12 +127,12 @@ public class ModuleLoader {
public Integer download() throws IOException, RootShellException, NoSuchAlgorithmException {
final List<String> output = new ArrayList<>();
- Application.getRootShell().run(output, "sha256sum /proc/version|cut -d ' ' -f 1");
+ rootShell.run(output, "sha256sum /proc/version|cut -d ' ' -f 1");
if (output.size() != 1 || output.get(0).length() != 64)
throw new InvalidParameterException("Invalid sha256 of /proc/version");
final String moduleName = String.format(MODULE_NAME, output.get(0));
HttpURLConnection connection = (HttpURLConnection)new URL(MODULE_LIST_URL).openConnection();
- connection.setRequestProperty("User-Agent", Application.USER_AGENT);
+ connection.setRequestProperty("User-Agent", userAgent);
connection.connect();
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK)
throw new IOException("Hash list could not be found");
@@ -146,7 +149,7 @@ public class ModuleLoader {
if (!modules.containsKey(moduleName))
return OsConstants.ENOENT;
connection = (HttpURLConnection)new URL(String.format(MODULE_URL, moduleName)).openConnection();
- connection.setRequestProperty("User-Agent", Application.USER_AGENT);
+ connection.setRequestProperty("User-Agent", userAgent);
connection.connect();
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK)
throw new IOException("Module file could not be found, despite being on hash list");