Report on a reused crash dialog sends the older crash

Open Beginner friendly
#23,798 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
73/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
android, kotlin
Domain
mobile

Research direction

Start with AnkiDroid/src/test/java/com/ichi2/anki/analytics/CrashReportDialogReuseTest.kt and the AnkiDroidCrashReportDialog handling of EXTRA_REPORT_FILE when onNewIntent reuses the dialog. Run the reuse test and check which crash file is approved after the second intent; done means the newest crash is reported and the earlier one remains pending.

Written by the indexing model from the issue text.

Description

Assisted-by: Claude Fable 5.2 max

[EXISTING] Report on a reused crash dialog sends the older crash
Subject: [EXISTING] Report on a reused crash dialog sends the older crash

When a second crash reuses a crash dialog left open, Report approves the first crash with the typed comment and leaves the second pending.

⚠️ This issue existed before the PR and should likely be split off into a separate issue.

---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/analytics/CrashReportDialogReuseTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/analytics/CrashReportDialogReuseTest.kt
new file mode 100644
index 0000000000..e33e12eb1e
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/analytics/CrashReportDialogReuseTest.kt
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki.analytics
+
+import android.app.Application
+import android.content.DialogInterface
+import android.content.Intent
+import androidx.test.core.app.ApplicationProvider
+import com.ichi2.anki.acraCoreConfigBuilder
+import com.ichi2.anki.common.crashreporting.CrashReportService
+import com.ichi2.anki.initializeAcraCrashReporter
+import com.ichi2.testutils.EmptyApplication
+import io.mockk.every
+import io.mockk.mockk
+import io.mockk.mockkConstructor
+import io.mockk.mockkStatic
+import io.mockk.unmockkAll
+import org.acra.ACRA
+import org.acra.config.CoreConfigurationBuilder
+import org.acra.file.ReportLocator
+import org.acra.interaction.DialogInteraction
+import org.acra.scheduler.DefaultSenderScheduler
+import org.junit.After
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.Robolectric
+import org.robolectric.RobolectricTestRunner
+import org.robolectric.annotation.Config
+import java.io.File
+import java.util.concurrent.TimeUnit
+import kotlin.test.assertFalse
+
+@RunWith(RobolectricTestRunner::class)
+@Config(application = EmptyApplication::class)
+class CrashReportDialogReuseTest {
+    @After
+    fun tearDown() {
+        unmockkAll()
+    }
+
+    @Test
+    fun `Report on a reused dialog sends the newest crash`() {
+        val application = ApplicationProvider.getApplicationContext<Application>()
+        mockkStatic(ACRA::class)
+        every { ACRA.init(any<Application>(), any<CoreConfigurationBuilder>(), any()) } returns Unit
+        with(application) { initializeAcraCrashReporter() }
+        mockkConstructor(DefaultSenderScheduler::class)
+        every { anyConstructed<DefaultSenderScheduler>().scheduleReportSending(any()) } returns Unit
+        val pending = ReportLocator(application).unapprovedFolder
+        val earlier = File(pending, "earlier.stacktrace").apply { writeText("{}") }
+        val newest = File(pending, "newest.stacktrace").apply { writeText("{}") }
+
+        Robolectric.buildActivity(AnkiDroidCrashReportDialog::class.java, dialogIntent(application, earlier)).setup().use { controller ->
+            // The dialog is singleInstance: a second crash reuses the one left open.
+            controller.newIntent(dialogIntent(application, newest))
+            controller.get().onClick(mockk<DialogInterface>(relaxed = true), DialogInterface.BUTTON_POSITIVE)
+            val deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(5)
+            while (newest.exists() && System.nanoTime() < deadline) Thread.sleep(10)
+
+            assertFalse(newest.exists(), "Report must approve the crash the dialog was last opened for")
+        }
+    }
+
+    private fun dialogIntent(
+        application: Application,
+        report: File,
+    ) = Intent(application, AnkiDroidCrashReportDialog::class.java)
+        .putExtra(DialogInteraction.EXTRA_REPORT_CONFIG, CrashReportService.acraCoreConfigBuilder.build())
+        .putExtra(DialogInteraction.EXTRA_REPORT_FILE, report)
+}

Found while reviewing https://github.com/ankidroid/Anki-Android/pull/23337

Dominant language
Kotlin
Stars
12.3k
Forks
3.1k
Avg merge
2d 1h
Merged PRs (30d)
320

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ankidroid/Anki-Android

All issues in ankidroid/Anki-Android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.