Search in sources :

Example 1 with CrashReportData

use of org.acra.data.CrashReportData in project libretorrent by proninyaroslav.

the class ErrorReportActivity method getStackTrace.

private String getStackTrace() {
    Intent i = getIntent();
    if (i == null)
        return null;
    CrashReportData crashReportData;
    try {
        crashReportData = helper.getReportData();
    } catch (IOException e) {
        return null;
    }
    return crashReportData.getString(ReportField.STACK_TRACE);
}
Also used : CrashReportData(org.acra.data.CrashReportData) Intent(android.content.Intent) IOException(java.io.IOException)

Example 2 with CrashReportData

use of org.acra.data.CrashReportData 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 3 with CrashReportData

use of org.acra.data.CrashReportData 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

CrashReportData (org.acra.data.CrashReportData)3 UiThreadTest (androidx.test.annotation.UiThreadTest)2 AnkiDroidApp (com.ichi2.anki.AnkiDroidApp)2 ReportBuilder (org.acra.builder.ReportBuilder)2 ACRAConfigurationException (org.acra.config.ACRAConfigurationException)2 LimitingReportAdministrator (org.acra.config.LimitingReportAdministrator)2 CrashReportDataFactory (org.acra.data.CrashReportDataFactory)2 Test (org.junit.Test)2 Intent (android.content.Intent)1 IOException (java.io.IOException)1