Bugsnag integration

This commit is contained in:
M66B
2019-05-10 08:53:45 +02:00
parent 55fc2e4641
commit defb8dd657
7 changed files with 73 additions and 3 deletions

View File

@@ -37,9 +37,14 @@ import android.os.Handler;
import android.os.RemoteException;
import android.webkit.CookieManager;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.preference.PreferenceManager;
import com.bugsnag.android.BeforeSend;
import com.bugsnag.android.Bugsnag;
import com.bugsnag.android.Report;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -68,6 +73,7 @@ public class ApplicationEx extends Application {
@Override
public void onCreate() {
super.onCreate();
logMemory("App create version=" + BuildConfig.VERSION_NAME);
prev = Thread.getDefaultUncaughtExceptionHandler();
@@ -91,6 +97,30 @@ public class ApplicationEx extends Application {
}
});
// https://docs.bugsnag.com/platforms/android/sdk/
com.bugsnag.android.Configuration config =
new com.bugsnag.android.Configuration("9d2d57476a0614974449a3ec33f2604a");
if (BuildConfig.DEBUG)
config.setReleaseStage("development");
else if (BuildConfig.BETA_RELEASE)
config.setReleaseStage(BuildConfig.PLAY_STORE_RELEASE ? "beta/play" : "beta");
else
config.setReleaseStage(BuildConfig.PLAY_STORE_RELEASE ? "stable/play" : "stable");
config.setIgnoreClasses(new String[]{"javax.mail.MessageRemovedException"});
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
config.beforeSend(new BeforeSend() {
@Override
public boolean run(@NonNull Report report) {
return prefs.getBoolean("crash_reports", false); // opt-out
}
});
Bugsnag.init(this, config);
upgrade(this);
createNotificationChannels();

View File

@@ -50,6 +50,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swParanoid;
private TextView tvParanoidHint;
private SwitchCompat swUpdates;
private SwitchCompat swCrashReports;
private SwitchCompat swDebug;
private TextView tvLastCleanup;
@@ -57,7 +58,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private Group grpSearchLocal;
private final static String[] RESET_OPTIONS = new String[]{
"badge", "subscriptions", "search_local", "english", "authentication", "paranoid", "updates", "debug"
"badge", "subscriptions", "search_local", "english", "authentication", "paranoid", "updates", "crash_reports", "debug"
};
private final static String[] RESET_QUESTIONS = new String[]{
@@ -82,6 +83,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swParanoid = view.findViewById(R.id.swParanoid);
tvParanoidHint = view.findViewById(R.id.tvParanoidHint);
swUpdates = view.findViewById(R.id.swUpdates);
swCrashReports = view.findViewById(R.id.swCrashReports);
swDebug = view.findViewById(R.id.swDebug);
tvLastCleanup = view.findViewById(R.id.tvLastCleanup);
@@ -162,6 +164,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
swCrashReports.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("crash_reports", checked).apply();
}
});
swDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@@ -229,6 +238,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swParanoid.setChecked(prefs.getBoolean("paranoid", true));
swUpdates.setChecked(prefs.getBoolean("updates", true));
swUpdates.setVisibility(Helper.isPlayStoreInstall(getContext()) ? View.GONE : View.VISIBLE);
swCrashReports.setChecked(prefs.getBoolean("crash_reports", false));
swDebug.setChecked(prefs.getBoolean("debug", false));
grpSearchLocal.setVisibility(Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M ? View.GONE : View.VISIBLE);

View File

@@ -23,6 +23,9 @@ import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import com.bugsnag.android.Bugsnag;
import com.bugsnag.android.Severity;
import java.lang.reflect.Array;
import java.util.Set;
@@ -45,18 +48,22 @@ public class Log {
}
public static int w(Throwable ex) {
Bugsnag.notify(ex, Severity.WARNING);
return android.util.Log.w(TAG, ex + "\n" + android.util.Log.getStackTraceString(ex));
}
public static int e(Throwable ex) {
Bugsnag.notify(ex, Severity.ERROR);
return android.util.Log.e(TAG, ex + "\n" + android.util.Log.getStackTraceString(ex));
}
public static int w(String prefix, Throwable ex) {
Bugsnag.notify(ex, Severity.WARNING);
return android.util.Log.w(TAG, prefix + " " + ex + "\n" + android.util.Log.getStackTraceString(ex));
}
public static int e(String prefix, Throwable ex) {
Bugsnag.notify(ex, Severity.ERROR);
return android.util.Log.e(TAG, prefix + " " + ex + "\n" + android.util.Log.getStackTraceString(ex));
}