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

feat: improve handling of "Anki already open, or media currently syncing"#21501
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

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

Assisted-by: Claude Fable 5
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

Assisted-by: Claude Fable 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AnkiWeb login: Anki already open

1 participant