Deleting Default leaves its approved crash reports queued

Open
#23,792 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
57/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
android, kotlin
Domain
backend, mobile

Research direction

Start with the regression test in AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/DefaultProfileCrashReportDeletionTest.kt and trace ProfileManager.deleteProfile(ProfileId.DEFAULT). The test sets up an approved crash report and expects it to be removed when Default is deleted. Done when that test passes and the other profiles' reports remain unaffected.

Written by the indexing model from the issue text.

Description

code-scan

Assisted-by: GPT-6.1-Terra xhigh & GPT-6.2-Sol xhigh

[EXISTING] Deleting Default leaves its approved crash reports queued

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

Subject: [EXISTING] Deleting Default leaves its approved crash reports queued

Deleting the default profile leaves its approved crash reports in the shared sender queue.

---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/DefaultProfileCrashReportDeletionTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/DefaultProfileCrashReportDeletionTest.kt
new file mode 100644
index 0000000000..c99eeb3b01
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/DefaultProfileCrashReportDeletionTest.kt
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki.multiprofile
+
+import android.content.Context
+import androidx.core.content.edit
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import org.acra.ReportField
+import org.acra.data.CrashReportData
+import org.acra.file.CrashReportPersister
+import org.acra.file.ReportLocator
+import org.junit.After
+import org.junit.Assert.assertFalse
+import org.junit.Test
+import org.junit.runner.RunWith
+import java.io.File
+
+@RunWith(AndroidJUnit4::class)
+class DefaultProfileCrashReportDeletionTest {
+    @After
+    fun tearDown() {
+        ProfileManager.resetForTesting()
+    }
+
+    @Test
+    fun `deleting default removes its approved crash reports`() {
+        val context = ApplicationProvider.getApplicationContext<Context>()
+        val registry = context.getSharedPreferences(ProfileManager.PROFILE_REGISTRY_FILENAME, Context.MODE_PRIVATE)
+        registry.edit(commit = true) { clear() }
+        val manager = ProfileManager.create(context)
+        val other = manager.createNewProfile(ProfileName.fromTrustedSource("Other"))
+        val report = File(ReportLocator(context).approvedFolder, "default-test.stacktrace")
+        CrashReportPersister().store(
+            CrashReportData().apply { put(ReportField.FILE_PATH, context.filesDir.absolutePath) },
+            report,
+        )
+        registry.edit(commit = true) { putString(ProfileManager.PREF_LAST_ACTIVE_PROFILE_ID, other.value) }
+
+        ProfileManager.create(context).deleteProfile(ProfileId.DEFAULT)
+
+        assertFalse("Deleting Default must remove its approved report", report.exists())
+    }
+}

Originally posted by @david-allison in https://github.com/ankidroid/Anki-Android/pull/23337#pullrequestreview-6064307283

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

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.