diff --git a/src/main/java/eu/siacs/conversations/AppSettings.java b/src/main/java/eu/siacs/conversations/AppSettings.java index 80b5ceaa0..ac239ff5c 100644 --- a/src/main/java/eu/siacs/conversations/AppSettings.java +++ b/src/main/java/eu/siacs/conversations/AppSettings.java @@ -40,6 +40,8 @@ public class AppSettings { public static final String USE_TOR = "use_tor"; public static final String CHANNEL_DISCOVERY_METHOD = "channel_discovery_method"; + public static final String SEND_CRASH_REPORTS = "send_crash_reports"; + private final Context context; public AppSettings(final Context context) { @@ -73,7 +75,10 @@ public class AppSettings { public void setNotificationTone(final Uri uri) { final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); - sharedPreferences.edit().putString(NOTIFICATION_RINGTONE, uri == null ? null : uri.toString()).apply(); + sharedPreferences + .edit() + .putString(NOTIFICATION_RINGTONE, uri == null ? null : uri.toString()) + .apply(); } public boolean isBTBVEnabled() { @@ -101,6 +106,17 @@ public class AppSettings { public String getOmemo() { final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); - return sharedPreferences.getString(OMEMO, context.getString(R.string.omemo_setting_default)); + return sharedPreferences.getString( + OMEMO, context.getString(R.string.omemo_setting_default)); + } + + public boolean isSendCrashReports() { + return getBooleanPreference(SEND_CRASH_REPORTS, R.bool.send_crash_reports); + } + + public void setSendCrashReports(boolean value) { + final SharedPreferences sharedPreferences = + PreferenceManager.getDefaultSharedPreferences(context); + sharedPreferences.edit().putBoolean(SEND_CRASH_REPORTS, value).apply(); } } diff --git a/src/main/java/eu/siacs/conversations/Conversations.java b/src/main/java/eu/siacs/conversations/Conversations.java index d5fe8069c..65ef020a7 100644 --- a/src/main/java/eu/siacs/conversations/Conversations.java +++ b/src/main/java/eu/siacs/conversations/Conversations.java @@ -10,11 +10,14 @@ import androidx.appcompat.app.AppCompatDelegate; import com.google.android.material.color.DynamicColors; import com.google.android.material.color.DynamicColorsOptions; +import eu.siacs.conversations.utils.ExceptionHelper; + public class Conversations extends Application { @Override public void onCreate() { super.onCreate(); + ExceptionHelper.init(getApplicationContext()); applyThemeSettings(); } diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index b9b09d0e0..b408deadc 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -485,7 +485,6 @@ public abstract class XmppActivity extends ActionBarActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); metrics = getResources().getDisplayMetrics(); - ExceptionHelper.init(getApplicationContext()); EmojiInitializationService.execute(this); this.isCameraFeatureAvailable = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY); } diff --git a/src/main/java/eu/siacs/conversations/utils/ExceptionHelper.java b/src/main/java/eu/siacs/conversations/utils/ExceptionHelper.java index b538666c3..a804f013b 100644 --- a/src/main/java/eu/siacs/conversations/utils/ExceptionHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/ExceptionHelper.java @@ -1,17 +1,22 @@ package eu.siacs.conversations.utils; import android.content.Context; -import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.Signature; -import android.preference.PreferenceManager; import android.util.Log; -import androidx.appcompat.app.AlertDialog; - import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import eu.siacs.conversations.AppSettings; +import eu.siacs.conversations.Config; +import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Conversation; +import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.services.XmppConnectionService; +import eu.siacs.conversations.ui.XmppActivity; + import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; @@ -21,47 +26,38 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; -import eu.siacs.conversations.Config; -import eu.siacs.conversations.R; -import eu.siacs.conversations.entities.Account; -import eu.siacs.conversations.entities.Conversation; -import eu.siacs.conversations.entities.Message; -import eu.siacs.conversations.services.XmppConnectionService; -import eu.siacs.conversations.ui.XmppActivity; - public class ExceptionHelper { private static final String FILENAME = "stacktrace.txt"; private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); - public static void init(Context context) { + public static void init(final Context context) { if (Thread.getDefaultUncaughtExceptionHandler() instanceof ExceptionHandler) { return; } Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(context)); } - public static boolean checkForCrash(XmppActivity activity) { + public static boolean checkForCrash(final XmppActivity activity) { try { final XmppConnectionService service = activity == null ? null : activity.xmppConnectionService; if (service == null) { return false; } - final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); - boolean neverSend = preferences.getBoolean("never_send", false); - if (neverSend || Config.BUG_REPORTS == null) { + final AppSettings appSettings = new AppSettings(activity); + if (!appSettings.isSendCrashReports() || Config.BUG_REPORTS == null) { return false; } final Account account = AccountUtils.getFirstEnabled(service); if (account == null) { return false; } - FileInputStream file = activity.openFileInput(FILENAME); - InputStreamReader inputStreamReader = new InputStreamReader(file); - BufferedReader stacktrace = new BufferedReader(inputStreamReader); + final FileInputStream file = activity.openFileInput(FILENAME); + final InputStreamReader inputStreamReader = new InputStreamReader(file); + final BufferedReader stacktrace = new BufferedReader(inputStreamReader); final StringBuilder report = new StringBuilder(); - PackageManager pm = activity.getPackageManager(); - PackageInfo packageInfo; + final PackageManager pm = activity.getPackageManager(); + final PackageInfo packageInfo; try { packageInfo = pm.getPackageInfo(activity.getPackageName(), PackageManager.GET_SIGNATURES); final String versionName = packageInfo.versionName; @@ -94,7 +90,7 @@ public class ExceptionHelper { Message message = new Message(conversation, report.toString(), Message.ENCRYPTION_NONE); service.sendMessage(message); }); - builder.setNegativeButton(activity.getText(R.string.send_never), (dialog, which) -> preferences.edit().putBoolean("never_send", true).apply()); + builder.setNegativeButton(activity.getText(R.string.send_never), (dialog, which) -> appSettings.setSendCrashReports(false)); builder.create().show(); return true; } catch (final IOException ignored) { diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index 929aee1a3..898e3fafa 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -33,7 +33,7 @@ false true true - false + true false true true diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 48be180d0..becda5496 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -125,7 +125,7 @@ Grace Period The length of time notifications are silenced after detecting activity on one of your other devices. Advanced - Never send crash reports + Send crash reports By sending in stack traces you are helping the development Confirm Messages Let your contacts know when you have received and read their messages diff --git a/src/main/res/xml/preferences_privacy.xml b/src/main/res/xml/preferences_privacy.xml index b425c35cd..61b121fbd 100644 --- a/src/main/res/xml/preferences_privacy.xml +++ b/src/main/res/xml/preferences_privacy.xml @@ -62,11 +62,11 @@ + android:title="@string/pref_send_crash_reports" />