Add crash report: default disabled

This commit is contained in:
tom79 2019-07-19 15:55:28 +02:00
parent 4516087442
commit 8c9b1cc608
6 changed files with 92 additions and 5 deletions

View File

@ -67,6 +67,7 @@ ext.uploadServiceVersion = "3.5.2"
ext.torrentstreamVersion = "2.5.0"
ext.netCipherVersion = "2.0.0-alpha1"
ext.acraVersion = "5.1.3"
dependencies {
implementation 'androidx.appcompat:appcompat:1.0.2'
@ -113,4 +114,8 @@ dependencies {
implementation 'com.github.adrielcafe:AndroidAudioRecorder:0.3.0'
implementation 'yogesh.firzen:MukkiyaSevaigal:1.0.6'
implementation "ch.acra:acra-mail:$acraVersion"
implementation "ch.acra:acra-limiter:$acraVersion"
implementation "ch.acra:acra-notification:$acraVersion"
}

View File

@ -16,6 +16,8 @@ package app.fedilab.android.activities;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.StrictMode;
import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;
@ -26,6 +28,13 @@ import com.franmontiel.localechanger.LocaleChanger;
import net.gotev.uploadservice.UploadService;
import org.acra.ACRA;
import org.acra.annotation.AcraNotification;
import org.acra.config.CoreConfigurationBuilder;
import org.acra.config.LimiterConfigurationBuilder;
import org.acra.config.MailSenderConfigurationBuilder;
import org.acra.data.StringFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@ -44,6 +53,8 @@ import static app.fedilab.android.helper.Helper.initNetCipher;
* Main application, jobs are launched here.
*/
@AcraNotification(
resIcon = R.mipmap.ic_launcher, resTitle = R.string.crash_title, resChannelName = R.string.set_crash_reports, resText = R.string.crash_message)
public class MainApplication extends MultiDexApplication {
@ -59,9 +70,10 @@ public class MainApplication extends MultiDexApplication {
NotificationsSyncJob.schedule(false);
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
try {
List<Locale> SUPPORTED_LOCALES = new ArrayList<>();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
String defaultLocaleString = sharedpreferences.getString(Helper.SET_DEFAULT_LOCALE_NEW, null);
if( defaultLocaleString != null){
Locale defaultLocale;
@ -77,6 +89,24 @@ public class MainApplication extends MultiDexApplication {
}
LocaleChanger.initialize(getApplicationContext(), SUPPORTED_LOCALES);
}catch (Exception ignored){}
boolean send_crash_reports = sharedpreferences.getBoolean(Helper.SET_SEND_CRASH_REPORTS, false);
if( send_crash_reports) {
CoreConfigurationBuilder ACRABuilder = new CoreConfigurationBuilder(this);
ACRABuilder.setBuildConfigClass(BuildConfig.class).setReportFormat(StringFormat.KEY_VALUE_LIST);
String version = "";
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
version = pInfo.versionName;
} catch (PackageManager.NameNotFoundException ignored) {
}
ACRABuilder.getPluginConfigurationBuilder(MailSenderConfigurationBuilder.class).setReportAsFile(false).setMailTo("support@fedilab.app").setSubject(" Crash Report for Fedilab " + version).setEnabled(true);
ACRABuilder.getPluginConfigurationBuilder(LimiterConfigurationBuilder.class).setEnabled(true);
ACRA.init(this, ACRABuilder);
}
//Initialize upload service
UploadService.NAMESPACE = BuildConfig.APPLICATION_ID;
initNetCipher(this);

View File

@ -740,6 +740,22 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
}
});
boolean send_crash_reports = sharedpreferences.getBoolean(Helper.SET_SEND_CRASH_REPORTS, false);
final CheckBox set_enable_crash_report = rootView.findViewById(R.id.set_enable_crash_report);
set_enable_crash_report.setChecked(send_crash_reports);
set_enable_crash_report.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_SEND_CRASH_REPORTS, set_enable_crash_report.isChecked());
editor.apply();
if( getActivity() != null)
getActivity().recreate();
}
});
int truncate_toots_size = sharedpreferences.getInt(Helper.SET_TRUNCATE_TOOTS_SIZE, 0);
SeekBar set_truncate_size = rootView.findViewById(R.id.set_truncate_size);
set_truncate_size.setMax(20);

View File

@ -358,6 +358,7 @@ public class Helper {
public static final String SET_DISPLAY_CONTENT_AFTER_FM = "set_display_content_after_fm";
public static final String SET_FEATURED_TAGS ="set_featured_tags";
public static final String SET_DISPLAY_NEWS_FROM_FEDILAB ="set_display_news_from_fedilab";
public static final String SET_SEND_CRASH_REPORTS ="set_send_crash_reports";
public static final String SET_FEATURED_TAG_ACTION ="set_featured_tag_action";
public static final String SET_HIDE_DELETE_BUTTON_ON_TAB = "set_hide_delete_notification_on_tab";
public static final String SET_RETRIEVE_METADATA_IF_URL_FROM_EXTERAL = "set_retrieve_metadata_share_from_extras";

View File

@ -928,6 +928,40 @@
</LinearLayout>
</LinearLayout>
<TextView
android:text="@string/set_crash_reports"
android:layout_marginTop="@dimen/settings_checkbox_margin"
android:layout_width="match_parent"
android:textSize="16sp"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/settings_checkbox_margin"
android:layout_marginBottom="@dimen/settings_checkbox_margin"
android:orientation="horizontal">
<CheckBox
android:id="@+id/set_enable_crash_report"
android:layout_width="wrap_content"
android:textSize="16sp"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:textSize="16sp"
android:text="@string/set_enable_crash_report"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:textColor="@color/mastodonC2"
android:text="@string/set_enable_crash_report_indication"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<TextView
android:text="@string/set_attachment_action"

View File

@ -570,9 +570,6 @@
<string name="delete_instance">Delete this instance?</string>
<string name="warning_delete_instance">You are going to delete %s from your followed instances.</string>
<string name="which_language">Translate in</string>
<string name="crash_title">Fedilab has stopped :(</string>
<string name="crash_message">You can send me by email the crash report. It will help to fix it :)\n\nYou can add additional content. Thank you!</string>
<string name="send_crash_report">Ask for sending crash reports by email?</string>
<string name="follow_instance">Follow instance</string>
<string name="toast_instance_already_added">You already follow this instance!</string>
<string name="toast_instance_followed">The instance is followed!</string>
@ -1118,7 +1115,11 @@
<string name="add_instances">Add an instance</string>
<string name="export_instances">Export instances</string>
<string name="import_instances">Import instances</string>
<string name="set_crash_reports">Crash reports</string>
<string name="set_enable_crash_report">Enable crash reports</string>
<string name="set_enable_crash_report_indication">If enabled, a crash report will be created locally and then you will be able to share it.</string>
<string name="crash_title">Fedilab has stopped :(</string>
<string name="crash_message">You can send me by email the crash report. It will help to fix it :)\n\nYou can add additional content. Thank you!</string>
<plurals name="number_of_vote">
<item quantity="one">%d vote</item>
<item quantity="other">%d votes</item>