aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-10-18 11:28:41 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-10-18 13:06:54 +0200
commitf04d5b01959aea206c9d9441eab86abccc00d0c9 (patch)
treed3e940ec1ca7c67c8df6ce0ec9768f7f0b4d8336
parentSuppress depreciation warnings (diff)
downloadwireguard-android-f04d5b01959aea206c9d9441eab86abccc00d0c9.tar.xz
wireguard-android-f04d5b01959aea206c9d9441eab86abccc00d0c9.zip
Application: put user agent in log to help debugging
-rw-r--r--app/src/main/java/com/wireguard/android/Application.java15
-rw-r--r--app/src/main/java/com/wireguard/android/util/ModuleLoader.java7
2 files changed, 16 insertions, 6 deletions
diff --git a/app/src/main/java/com/wireguard/android/Application.java b/app/src/main/java/com/wireguard/android/Application.java
index 744986e..22572d5 100644
--- a/app/src/main/java/com/wireguard/android/Application.java
+++ b/app/src/main/java/com/wireguard/android/Application.java
@@ -12,6 +12,8 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
+import android.util.Log;
+
import androidx.preference.PreferenceManager;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDelegate;
@@ -26,12 +28,22 @@ import com.wireguard.android.util.ModuleLoader;
import com.wireguard.android.util.RootShell;
import com.wireguard.android.util.ToolsInstaller;
-import java.io.File;
import java.lang.ref.WeakReference;
+import java.util.Locale;
import java9.util.concurrent.CompletableFuture;
public class Application extends android.app.Application {
+ private static final String TAG = "WireGuard/" + Application.class.getSimpleName();
+ public static final String USER_AGENT;
+
+ static {
+ String preferredAbi = "unknown ABI";
+ if (Build.SUPPORTED_ABIS.length > 0)
+ preferredAbi = Build.SUPPORTED_ABIS[0];
+ USER_AGENT = String.format(Locale.ENGLISH, "WireGuard/%s (Android %d; %s; %s; %s %s; %s)", BuildConfig.VERSION_NAME, Build.VERSION.SDK_INT, preferredAbi, Build.BOARD, Build.MANUFACTURER, Build.MODEL, Build.FINGERPRINT);
+ }
+
@SuppressWarnings("NullableProblems") private static WeakReference<Application> weakSelf;
private final CompletableFuture<Backend> futureBackend = new CompletableFuture<>();
@SuppressWarnings("NullableProblems") private AsyncWorker asyncWorker;
@@ -123,6 +135,7 @@ public class Application extends android.app.Application {
@Override
public void onCreate() {
+ Log.i(TAG, USER_AGENT);
super.onCreate();
asyncWorker = new AsyncWorker(AsyncTask.SERIAL_EXECUTOR, new Handler(Looper.getMainLooper()));
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 21ff9c7..524d10a 100644
--- a/app/src/main/java/com/wireguard/android/util/ModuleLoader.java
+++ b/app/src/main/java/com/wireguard/android/util/ModuleLoader.java
@@ -10,7 +10,6 @@ import android.system.OsConstants;
import android.util.Base64;
import com.wireguard.android.Application;
-import com.wireguard.android.BuildConfig;
import com.wireguard.android.util.RootShell.NoRootException;
import net.i2p.crypto.eddsa.EdDSAEngine;
@@ -130,10 +129,8 @@ public class ModuleLoader {
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));
- final String userAgent = String.format("WireGuard/%s (Android)", BuildConfig.VERSION_NAME); //TODO: expand a bit
-
HttpURLConnection connection = (HttpURLConnection)new URL(MODULE_LIST_URL).openConnection();
- connection.setRequestProperty("User-Agent", userAgent);
+ connection.setRequestProperty("User-Agent", Application.USER_AGENT);
connection.connect();
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK)
throw new IOException("Hash list could not be found");
@@ -150,7 +147,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", userAgent);
+ connection.setRequestProperty("User-Agent", Application.USER_AGENT);
connection.connect();
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK)
throw new IOException("Module file could not be found, despite being on hash list");