Search in sources :

Example 1 with ReportBuilder

use of org.acra.builder.ReportBuilder in project acra by ACRA.

the class ErrorReporter method handleException.

/**
     * Send a report for a {@link Throwable} with the reporting interaction mode
     * configured by the developer.
     *
     * @param e
     *            The {@link Throwable} to be reported. If null the report will
     *            contain a new Exception("Report requested by developer").
     * @param endApplication
     *            Set this to true if you want the application to be ended after
     *            sending the report.
     */
@SuppressWarnings("unused")
public void handleException(@Nullable Throwable e, boolean endApplication) {
    performDeprecatedReportPriming();
    final ReportBuilder builder = new ReportBuilder();
    builder.exception(e);
    if (endApplication) {
        builder.endApplication();
    }
    builder.build(reportExecutor);
}
Also used : ReportBuilder(org.acra.builder.ReportBuilder)

Example 2 with ReportBuilder

use of org.acra.builder.ReportBuilder in project acra by ACRA.

the class ErrorReporter method handleSilentException.

/**
     * Mark this report as silent as send it.
     *
     * @param e The {@link Throwable} to be reported. If null the report will
     *          contain a new Exception("Report requested by developer").
     */
@SuppressWarnings("unused")
public void handleSilentException(@Nullable Throwable e) {
    performDeprecatedReportPriming();
    new ReportBuilder().exception(e).sendSilently().build(reportExecutor);
}
Also used : ReportBuilder(org.acra.builder.ReportBuilder)

Example 3 with ReportBuilder

use of org.acra.builder.ReportBuilder in project AnkiChinaAndroid by ankichinateam.

the class ACRATest method testCrashReportLimit.

@Test
public void testCrashReportLimit() throws Exception {
    // To test ACRA switch on  reporting, plant a production tree, and trigger a report
    Timber.plant(new AnkiDroidApp.ProductionCrashReportingTree());
    // set up as if the user had prefs saved to full auto
    setReportConfig(FEEDBACK_REPORT_ALWAYS);
    // If the user is set to always, then it's production, with interaction mode toast
    // will be useful with ACRA 5.2.0
    setAcraConfig("Production");
    // The same class/method combo is only sent once, so we face a new method each time (should test that system later)
    Exception crash = new Exception("testCrashReportSend at " + System.currentTimeMillis());
    StackTraceElement[] trace = new StackTraceElement[] { new StackTraceElement("Class", "Method" + (int) System.currentTimeMillis(), "File", (int) System.currentTimeMillis()) };
    crash.setStackTrace(trace);
    // one send should work
    CrashReportData crashData = new CrashReportDataFactory(InstrumentationRegistry.getInstrumentation().getTargetContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build()).createCrashData(new ReportBuilder().exception(crash));
    assertTrue(new LimitingReportAdministrator().shouldSendReport(InstrumentationRegistry.getInstrumentation().getTargetContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build(), crashData));
    // A second send should not work
    assertFalse(new LimitingReportAdministrator().shouldSendReport(InstrumentationRegistry.getInstrumentation().getTargetContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build(), crashData));
    // Now let's clear data
    AnkiDroidApp.deleteACRALimiterData(InstrumentationRegistry.getInstrumentation().getTargetContext());
    // A third send should work again
    assertTrue(new LimitingReportAdministrator().shouldSendReport(InstrumentationRegistry.getInstrumentation().getTargetContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build(), crashData));
}
Also used : CrashReportData(org.acra.data.CrashReportData) ReportBuilder(org.acra.builder.ReportBuilder) LimitingReportAdministrator(org.acra.config.LimitingReportAdministrator) AnkiDroidApp(com.ichi2.anki.AnkiDroidApp) CrashReportDataFactory(org.acra.data.CrashReportDataFactory) ACRAConfigurationException(org.acra.config.ACRAConfigurationException) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 4 with ReportBuilder

use of org.acra.builder.ReportBuilder in project Anki-Android by ankidroid.

the class ACRATest method testCrashReportLimit.

@Test
public void testCrashReportLimit() throws Exception {
    // To test ACRA switch on  reporting, plant a production tree, and trigger a report
    Timber.plant(new AnkiDroidApp.ProductionCrashReportingTree());
    // set up as if the user had prefs saved to full auto
    setReportConfig(FEEDBACK_REPORT_ALWAYS);
    // If the user is set to always, then it's production, with interaction mode toast
    // will be useful with ACRA 5.2.0
    setAcraConfig("Production");
    // The same class/method combo is only sent once, so we face a new method each time (should test that system later)
    Exception crash = new Exception("testCrashReportSend at " + System.currentTimeMillis());
    StackTraceElement[] trace = new StackTraceElement[] { new StackTraceElement("Class", "Method" + (int) System.currentTimeMillis(), "File", (int) System.currentTimeMillis()) };
    crash.setStackTrace(trace);
    // one send should work
    CrashReportData crashData = new CrashReportDataFactory(getTestContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build()).createCrashData(new ReportBuilder().exception(crash));
    assertTrue(new LimitingReportAdministrator().shouldSendReport(getTestContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build(), crashData));
    // A second send should not work
    assertFalse(new LimitingReportAdministrator().shouldSendReport(getTestContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build(), crashData));
    // Now let's clear data
    AnkiDroidApp.deleteACRALimiterData(getTestContext());
    // A third send should work again
    assertTrue(new LimitingReportAdministrator().shouldSendReport(getTestContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build(), crashData));
}
Also used : CrashReportData(org.acra.data.CrashReportData) ReportBuilder(org.acra.builder.ReportBuilder) LimitingReportAdministrator(org.acra.config.LimitingReportAdministrator) AnkiDroidApp(com.ichi2.anki.AnkiDroidApp) CrashReportDataFactory(org.acra.data.CrashReportDataFactory) ACRAConfigurationException(org.acra.config.ACRAConfigurationException) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Aggregations

ReportBuilder (org.acra.builder.ReportBuilder)4 UiThreadTest (androidx.test.annotation.UiThreadTest)2 AnkiDroidApp (com.ichi2.anki.AnkiDroidApp)2 ACRAConfigurationException (org.acra.config.ACRAConfigurationException)2 LimitingReportAdministrator (org.acra.config.LimitingReportAdministrator)2 CrashReportData (org.acra.data.CrashReportData)2 CrashReportDataFactory (org.acra.data.CrashReportDataFactory)2 Test (org.junit.Test)2