From 1b262c917817c62b928d96c3c1f09eff4ea9abd6 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 26 Jul 2018 13:28:34 +0200 Subject: Set ACRA install source --- .../java/com/wireguard/android/Application.java | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'app/src/main/java/com/wireguard') diff --git a/app/src/main/java/com/wireguard/android/Application.java b/app/src/main/java/com/wireguard/android/Application.java index 8dff8a54..7218c606 100644 --- a/app/src/main/java/com/wireguard/android/Application.java +++ b/app/src/main/java/com/wireguard/android/Application.java @@ -69,9 +69,10 @@ public class Application extends android.app.Application { * check the DN of the certs that signed the apk, without even bothering to try * validating that they're authentic. It's a good enough heuristic. */ - private static boolean shouldEnableCrashReporting(final Context context) { + @Nullable + private static String getInstallSource(final Context context) { if (BuildConfig.DEBUG) - return false; + return null; try { final CertificateFactory cf = CertificateFactory.getInstance("X509"); for (final Signature sig : context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures) { @@ -82,21 +83,25 @@ public class Application extends android.app.Application { continue; switch (parts[1]) { case "Google Inc.": + return "Play Store"; case "fdroid.org": - return true; + return "F-Droid"; } } } catch (final Exception ignored) { } } } catch (final Exception ignored) { } - return false; + return null; } @Override protected void attachBaseContext(final Context context) { super.attachBaseContext(context); - if (shouldEnableCrashReporting(context)) + final String installSource = getInstallSource(context); + if (installSource != null) { ACRA.init(this); + ACRA.getErrorReporter().putCustomData("installSource", installSource); + } } public static Application get() { @@ -165,9 +170,11 @@ public class Application extends android.app.Application { asyncWorker.supplyAsync(Application::getBackend).thenAccept(backend -> { futureBackend.complete(backend); - ACRA.getErrorReporter().putCustomData("backend", backend.getClass().getSimpleName()); - asyncWorker.supplyAsync(backend::getVersion).thenAccept(version -> - ACRA.getErrorReporter().putCustomData("backendVersion", version)); + if (ACRA.isInitialised()) { + ACRA.getErrorReporter().putCustomData("backend", backend.getClass().getSimpleName()); + asyncWorker.supplyAsync(backend::getVersion).thenAccept(version -> + ACRA.getErrorReporter().putCustomData("backendVersion", version)); + } }); } } -- cgit v1.2.3-59-g8ed1b