flip 'never send crash reports' to positive

This commit is contained in:
Daniel Gultsch 2024-04-08 08:10:13 +02:00
parent dc0a139392
commit e84d66874c
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
7 changed files with 45 additions and 31 deletions

View file

@ -40,6 +40,8 @@ public class AppSettings {
public static final String USE_TOR = "use_tor"; public static final String USE_TOR = "use_tor";
public static final String CHANNEL_DISCOVERY_METHOD = "channel_discovery_method"; public static final String CHANNEL_DISCOVERY_METHOD = "channel_discovery_method";
public static final String SEND_CRASH_REPORTS = "send_crash_reports";
private final Context context; private final Context context;
public AppSettings(final Context context) { public AppSettings(final Context context) {
@ -73,7 +75,10 @@ public class AppSettings {
public void setNotificationTone(final Uri uri) { public void setNotificationTone(final Uri uri) {
final SharedPreferences sharedPreferences = final SharedPreferences sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(context); 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() { public boolean isBTBVEnabled() {
@ -101,6 +106,17 @@ public class AppSettings {
public String getOmemo() { public String getOmemo() {
final SharedPreferences sharedPreferences = final SharedPreferences sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(context); 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();
} }
} }

View file

@ -10,11 +10,14 @@ import androidx.appcompat.app.AppCompatDelegate;
import com.google.android.material.color.DynamicColors; import com.google.android.material.color.DynamicColors;
import com.google.android.material.color.DynamicColorsOptions; import com.google.android.material.color.DynamicColorsOptions;
import eu.siacs.conversations.utils.ExceptionHelper;
public class Conversations extends Application { public class Conversations extends Application {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
ExceptionHelper.init(getApplicationContext());
applyThemeSettings(); applyThemeSettings();
} }

View file

@ -485,7 +485,6 @@ public abstract class XmppActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
metrics = getResources().getDisplayMetrics(); metrics = getResources().getDisplayMetrics();
ExceptionHelper.init(getApplicationContext());
EmojiInitializationService.execute(this); EmojiInitializationService.execute(this);
this.isCameraFeatureAvailable = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY); this.isCameraFeatureAvailable = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
} }

View file

@ -1,17 +1,22 @@
package eu.siacs.conversations.utils; package eu.siacs.conversations.utils;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.Signature; import android.content.pm.Signature;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import androidx.appcompat.app.AlertDialog;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; 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.BufferedReader;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
@ -21,47 +26,38 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Locale; 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 { public class ExceptionHelper {
private static final String FILENAME = "stacktrace.txt"; private static final String FILENAME = "stacktrace.txt";
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); 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) { if (Thread.getDefaultUncaughtExceptionHandler() instanceof ExceptionHandler) {
return; return;
} }
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(context)); Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(context));
} }
public static boolean checkForCrash(XmppActivity activity) { public static boolean checkForCrash(final XmppActivity activity) {
try { try {
final XmppConnectionService service = activity == null ? null : activity.xmppConnectionService; final XmppConnectionService service = activity == null ? null : activity.xmppConnectionService;
if (service == null) { if (service == null) {
return false; return false;
} }
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); final AppSettings appSettings = new AppSettings(activity);
boolean neverSend = preferences.getBoolean("never_send", false); if (!appSettings.isSendCrashReports() || Config.BUG_REPORTS == null) {
if (neverSend || Config.BUG_REPORTS == null) {
return false; return false;
} }
final Account account = AccountUtils.getFirstEnabled(service); final Account account = AccountUtils.getFirstEnabled(service);
if (account == null) { if (account == null) {
return false; return false;
} }
FileInputStream file = activity.openFileInput(FILENAME); final FileInputStream file = activity.openFileInput(FILENAME);
InputStreamReader inputStreamReader = new InputStreamReader(file); final InputStreamReader inputStreamReader = new InputStreamReader(file);
BufferedReader stacktrace = new BufferedReader(inputStreamReader); final BufferedReader stacktrace = new BufferedReader(inputStreamReader);
final StringBuilder report = new StringBuilder(); final StringBuilder report = new StringBuilder();
PackageManager pm = activity.getPackageManager(); final PackageManager pm = activity.getPackageManager();
PackageInfo packageInfo; final PackageInfo packageInfo;
try { try {
packageInfo = pm.getPackageInfo(activity.getPackageName(), PackageManager.GET_SIGNATURES); packageInfo = pm.getPackageInfo(activity.getPackageName(), PackageManager.GET_SIGNATURES);
final String versionName = packageInfo.versionName; final String versionName = packageInfo.versionName;
@ -94,7 +90,7 @@ public class ExceptionHelper {
Message message = new Message(conversation, report.toString(), Message.ENCRYPTION_NONE); Message message = new Message(conversation, report.toString(), Message.ENCRYPTION_NONE);
service.sendMessage(message); 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(); builder.create().show();
return true; return true;
} catch (final IOException ignored) { } catch (final IOException ignored) {

View file

@ -33,7 +33,7 @@
<bool name="away_when_screen_off">false</bool> <bool name="away_when_screen_off">false</bool>
<bool name="autojoin">true</bool> <bool name="autojoin">true</bool>
<bool name="enable_foreground_service">true</bool> <bool name="enable_foreground_service">true</bool>
<bool name="never_send">false</bool> <bool name="send_crash_reports">true</bool>
<bool name="validate_hostname">false</bool> <bool name="validate_hostname">false</bool>
<bool name="show_qr_code_scan">true</bool> <bool name="show_qr_code_scan">true</bool>
<bool name="show_individual_search_options">true</bool> <bool name="show_individual_search_options">true</bool>

View file

@ -125,7 +125,7 @@
<string name="pref_notification_grace_period">Grace Period</string> <string name="pref_notification_grace_period">Grace Period</string>
<string name="pref_notification_grace_period_summary">The length of time notifications are silenced after detecting activity on one of your other devices.</string> <string name="pref_notification_grace_period_summary">The length of time notifications are silenced after detecting activity on one of your other devices.</string>
<string name="pref_advanced_options">Advanced</string> <string name="pref_advanced_options">Advanced</string>
<string name="pref_never_send_crash">Never send crash reports</string> <string name="pref_send_crash_reports">Send crash reports</string>
<string name="pref_never_send_crash_summary">By sending in stack traces you are helping the development</string> <string name="pref_never_send_crash_summary">By sending in stack traces you are helping the development</string>
<string name="pref_confirm_messages">Confirm Messages</string> <string name="pref_confirm_messages">Confirm Messages</string>
<string name="pref_confirm_messages_summary">Let your contacts know when you have received and read their messages</string> <string name="pref_confirm_messages_summary">Let your contacts know when you have received and read their messages</string>

View file

@ -62,11 +62,11 @@
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/pref_category_application"> <PreferenceCategory android:title="@string/pref_category_application">
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="@bool/never_send" android:defaultValue="@bool/send_crash_reports"
android:icon="@drawable/ic_report_24dp" android:icon="@drawable/ic_report_24dp"
android:key="never_send" android:key="send_crash_reports"
android:summary="@string/pref_never_send_crash_summary" android:summary="@string/pref_never_send_crash_summary"
android:title="@string/pref_never_send_crash" /> android:title="@string/pref_send_crash_reports" />
</PreferenceCategory> </PreferenceCategory>