Skip to content

feat: improve handling of "Anki already open, or media currently syncing" - #21501

Open
david-allison wants to merge 3 commits into
ankidroid:mainfrom
david-allison:21051
Open

david-allison wants to merge 3 commits into
ankidroid:mainfrom
david-allison:21051

Conversation

@david-allison

@david-allison david-allison commented Aug 15, 2026 •

Copy link
Copy Markdown
Member

Note

Assisted-by: Claude Fable 5

Purpose / Description

  • A user was not given guidance when this occurred
  • There was no way to open 'AnkiDroid directory' from these errors

Fixes

Approach

  • Define a CollectionLockedException, replacing BackendDbLockedException
  • Update the string
  • Display the error in a dialog
  • Add 'Settings' button, opening 'Advanced Settings'

How Has This Been Tested?

Unit tested
Screenshot 2026-08-15 at 15 05 37

Index: AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt b/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
--- a/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt	(revision 36eb6ffad29bfe3db410eae31adc844cc95bac53)
+++ b/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt	(date 1786802726064)
@@ -510,6 +510,24 @@
 
         setViewBinding(binding)
         enableToolbar()
+
+        // TEMP (#21051): manual testing of the locked-collection dialogs. DO NOT COMMIT
+        // 1. Uncomment the next line, relaunch -> 'Database Locked' startup dialog:
+         CollectionManager.emulatedOpenFailure = CollectionManager.CollectionOpenFailure.LOCKED
+        // 2. Or long-press the toolbar to toggle the lock at runtime, then:
+        //    - tap Sync (or open a deck) -> runtime error dialog
+        //    - Settings - Sync - AnkiWeb account - Log in -> login error dialog
+        // Force-stop the app to clear the emulated lock if the UI becomes unreachable.
+        findViewById<Toolbar>(R.id.toolbar).setOnLongClickListener {
+            CollectionManager.emulatedOpenFailure =
+                if (CollectionManager.emulatedOpenFailure == null) {
+                    CollectionManager.CollectionOpenFailure.LOCKED
+                } else {
+                    null
+                }
+            showThemedToast(this, "emulated lock: ${CollectionManager.emulatedOpenFailure != null}", true)
+            true
+        }
         // TODO This method is run on every activity recreation, which can happen often.
         //  It seems that the original idea was for this to only run once, on app start.
         //  This method triggers backups, sync, and may re-show dialogs

Learning (optional, can help others)

  • The error string is hardcoded upstream.
  • It is not possible for media syncing to cause this

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@github-actions

Copy link
Copy Markdown
Contributor

Important

Maintainers: This PR contains Strings changes

  1. Sync Translations before merging this PR and wait for the action to complete
  2. Review and merge the auto-generated PR in order to sync all user-submitted translations
  3. Sync Translations again and merge the PR so the huge automated string changes caused by merging this PR are by themselves and easy to review

@david-allison
david-allison force-pushed the 21051 branch 3 times, most recently from 6d567f3 to 9bc8dc4 Compare August 15, 2026 21:00

@mikehardy mikehardy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Locked-collection UX looks coherent — retype → guidance → Settings→Advanced across startup, runtime, and login. Good improvement for the "Anki already open / media syncing" path.

@mikehardy
mikehardy added this pull request to the merge queue Sep 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 24, 2026
@david-allison

Copy link
Copy Markdown
Member Author

@mikehardy pending strings, let's leave this for now

@david-allison david-allison added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Review labels Sep 24, 2026
@mikehardy
mikehardy added this pull request to the merge queue Sep 28, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 28, 2026
@mikehardy
mikehardy added this pull request to the merge queue Sep 28, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 28, 2026
@mikehardy
mikehardy added this pull request to the merge queue Sep 28, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 28, 2026
@david-allison david-allison reopened this Sep 28, 2026
@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Sep 28, 2026
@david-allison

Copy link
Copy Markdown
Member Author

@david-allison david-allison removed the Needs Author Reply Waiting for a reply from the original author label Sep 29, 2026
@lukstbit
lukstbit added this pull request to the merge queue Sep 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 30, 2026
@david-allison david-allison reopened this Sep 30, 2026
@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Sep 30, 2026
The backend string: 'Anki already open, or media currently syncing'
doesn't explain this on Android - the other app likely launched on boot,
 (and upstream is much less likely to have parallel apps).

In AnkiDroid, it is not possible for 'media syncing' to be the cause of
this error.

CollectionManager now rethrows `BackendDbLockedException` as
`CollectionLockedException`, with better user-facing guidance.

Also:
* a locked collection no longer files a crash report
* the login screen shows the guidance in a dialog rather than
  truncating it in a snackbar

Fixes 21051

GPT-6 resolved the rebase conflict and updated the locked-collection message references to CommonString. GPT-6 also updated locked-collection exception assertions and registered the error dialog test activity for cleanup.

Assisted-by: Claude Fable 5
Assisted-by: GPT-6
The `CollectionLockedException` guidance is truncated by the login
screen's snackbar, so show it in a dialog.

Part of 21051

Assisted-by: Claude Fable 5
Allows a user to change 'AnkiDroid directory'

Part of 21051

GPT-6 updated the Settings button labels to CommonString after rebasing. GPT-6 also registered the Settings dialog test activity for cleanup.

Assisted-by: Claude Fable 5
Assisted-by: GPT-6
@david-allison david-allison removed the Needs Author Reply Waiting for a reply from the original author label Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Snapshot diff report vs main. Open screenshot-diff for diffs.

  • SharedDecksScreenshotTest: 1 change
All 1 changed screenshots

SharedDecksScreenshotTest

  • download_compare.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) Strings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AnkiWeb login: Anki already open

2 participants