From d0223c6eab8f58799c8c3ff0e67f5974c237e01c Mon Sep 17 00:00:00 2001 From: Carey Metcalfe Date: Fri, 13 Oct 2017 19:54:41 -0400 Subject: Fix crash on startup when building without environment variables - Adds a check for the `CAST_APPLICATION_ID` variable in `CastCompat`. If it's null, casting will be disabled. - Without a `PASTEBIN_DEV_KEY` sending logs would result in a generic "Failed to gather logs" message. This commit changes the message to something more accurate. --- app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java | 4 ++++ .../main/java/github/daneren2005/dsub/util/EnvironmentVariables.java | 4 ++-- app/src/main/java/github/daneren2005/dsub/util/compat/CastCompat.java | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java index 82e50b76..e7c7f1fb 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java @@ -270,6 +270,10 @@ public class MainFragment extends SelectRecyclerFragment { } private void getLogs() { + if (EnvironmentVariables.PASTEBIN_DEV_KEY == null) { + Util.toast(context, "No PASTEBIN_DEV_KEY configured - can't upload logs"); + return; + } try { final PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); new LoadingTask(context) { diff --git a/app/src/main/java/github/daneren2005/dsub/util/EnvironmentVariables.java b/app/src/main/java/github/daneren2005/dsub/util/EnvironmentVariables.java index 710d5232..8af74f07 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/EnvironmentVariables.java +++ b/app/src/main/java/github/daneren2005/dsub/util/EnvironmentVariables.java @@ -16,6 +16,6 @@ package github.daneren2005.dsub.util; public final class EnvironmentVariables { - public static final String PASTEBIN_DEV_KEY = ""; - public static final String CAST_APPLICATION_ID = ""; + public static final String PASTEBIN_DEV_KEY = null; + public static final String CAST_APPLICATION_ID = null; } diff --git a/app/src/main/java/github/daneren2005/dsub/util/compat/CastCompat.java b/app/src/main/java/github/daneren2005/dsub/util/compat/CastCompat.java index 415106db..08bac263 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/compat/CastCompat.java +++ b/app/src/main/java/github/daneren2005/dsub/util/compat/CastCompat.java @@ -27,6 +27,9 @@ import github.daneren2005.dsub.util.EnvironmentVariables; public final class CastCompat { static { + if (EnvironmentVariables.CAST_APPLICATION_ID == null) { + throw new RuntimeException("CAST_APPLICATION_ID not provided"); + } try { Class.forName("com.google.android.gms.cast.CastDevice"); } catch (Exception ex) { -- cgit v1.2.3