diff options
-rw-r--r-- | app/src/main/java/com/wireguard/android/Application.java | 15 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/android/util/ModuleLoader.java | 7 |
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 744986e8..22572d54 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 21ff9c77..524d10a6 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"); |