Open-source alternative Instagram client on Android. More maintainers needed!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.2 KiB

  1. package awaisomereport;
  2. import android.app.Application;
  3. import androidx.annotation.NonNull;
  4. import awais.instagrabber.BuildConfig;
  5. import awais.instagrabber.fragments.settings.PreferenceKeys;
  6. import io.sentry.SentryLevel;
  7. import io.sentry.android.core.SentryAndroid;
  8. import io.sentry.protocol.Contexts;
  9. import io.sentry.protocol.Device;
  10. import static awais.instagrabber.utils.Utils.settingsHelper;
  11. public class CrashHandler implements ICrashHandler {
  12. private static final String TAG = CrashHandler.class.getSimpleName();
  13. private final Application application;
  14. private final boolean enabled;
  15. public CrashHandler(@NonNull final Application application) {
  16. this.application = application;
  17. if (!settingsHelper.hasPreference(PreferenceKeys.PREF_ENABLE_SENTRY)) {
  18. // disabled by default (change to true if we need enabled by default)
  19. enabled = false;
  20. } else {
  21. enabled = settingsHelper.getBoolean(PreferenceKeys.PREF_ENABLE_SENTRY);
  22. }
  23. if (!enabled) return;
  24. SentryAndroid.init(application, options -> {
  25. options.setDsn(BuildConfig.dsn);
  26. options.setDiagnosticLevel(SentryLevel.ERROR);
  27. options.setBeforeSend((event, hint) -> {
  28. // Removing unneeded info from event
  29. final Contexts contexts = event.getContexts();
  30. final Device device = contexts.getDevice();
  31. device.setName(null);
  32. device.setTimezone(null);
  33. device.setCharging(null);
  34. device.setBootTime(null);
  35. device.setFreeStorage(null);
  36. device.setBatteryTemperature(null);
  37. return event;
  38. });
  39. });
  40. }
  41. @Override
  42. public void uncaughtException(@NonNull final Thread t,
  43. @NonNull final Throwable exception,
  44. @NonNull final Thread.UncaughtExceptionHandler defaultEH) {
  45. // When enabled, Sentry auto captures unhandled exceptions
  46. if (!enabled) {
  47. CrashReporterHelper.startErrorReporterActivity(application, exception);
  48. }
  49. defaultEH.uncaughtException(t, exception);
  50. }
  51. }