Skip to content

Add 'Use default collection folder' recovery option for collection path mismatch#20362

Merged
david-allison merged 1 commit intoankidroid:mainfrom
Giyutomioka-SS:collection-path-mismatch-17524
Apr 6, 2026
Merged

Add 'Use default collection folder' recovery option for collection path mismatch#20362
david-allison merged 1 commit intoankidroid:mainfrom
Giyutomioka-SS:collection-path-mismatch-17524

Conversation

@Giyutomioka-SS
Copy link
Copy Markdown
Contributor

@Giyutomioka-SS Giyutomioka-SS commented Feb 25, 2026

Purpose / Description

When the stored collection path is wrong or no longer exists (e.g. legacy vs app-specific path), the "Error handling" screen had no way to fix it. This change adds a "Use default collection folder" option on that screen so the user can reset the path to the default and exit. On the next launch the app opens from the correct folder or creates a new collection there.

Fixes

Approach

When the database error dialog appears, we show a new "use default folder" option only if the current folder is not already the default one. If the user taps it, we close the collection, reset the folder path back to default, and exit the app. Next time the app opens, it uses the default folder. This follows the same close-reset-finish pattern already used elsewhere in the app.

How Has This Been Tested?

Reproduced the bug by setting a wrong path in prefs and a fake DB at that path on emulator.

Screen Recording

Screen_recording_20260225_172356.webm

Checklist

Please, go through these checks before submitting the PR.

  • 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

@criticalAY
Copy link
Copy Markdown
Contributor

criticalAY commented Feb 25, 2026

I am not able get how you reproduced it, you edited the pref in data/data...? could you mention the exact steps

@criticalAY criticalAY added the Needs Author Reply Waiting for a reply from the original author label Feb 25, 2026
@Giyutomioka-SS
Copy link
Copy Markdown
Contributor Author

@criticalAY On an Android 14 emulator with fullDebug (com.ichi2.anki.debug):

  1. Install and launch once so a normal collection is created at the default path, then close the app.

  2. Change the stored collection path in prefs to a bad location:

    adb shell run-as com.ichi2.anki.debug \
    "sed -i 's#/storage/emulated/0/AnkiDroid#/storage/emulated/0/Android/com.ichi2.anki.debug/files/AnkiDroid#g' shared_prefs/com.ichi2.anki.debug_preferences.xml"
    
  3. Put a fake DB only at that bad path:

    adb shell 'rm -rf /storage/emulated/0/Android/com.ichi2.anki.debug/files/AnkiDroid && \
    mkdir -p /storage/emulated/0/Android/com.ichi2.anki.debug/files/AnkiDroid && \
    echo "not a real sqlite db" > /storage/emulated/0/Android/com.ichi2.anki.debug/files/AnkiDroid/collection.anki2'
    
  4. Force stop and relaunch the app:

    adb shell am force-stop com.ichi2.anki.debug
    adb shell monkey -p com.ichi2.anki.debug -c android.intent.category.LAUNCHER 1
    
  5. You should see “Collection not opened” then, after tapping Options, the Error handling dialog with the new “Use default collection folder” option.

@Giyutomioka-SS
Copy link
Copy Markdown
Contributor Author

@david-allison, need you pov here, if this is the right way or not?

Copy link
Copy Markdown
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

It would be very useful to add a test, potentially in androidTest here

At minimum, a @NeedsTest should be added.

LGTM other than the exception check

Comment thread AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DatabaseErrorDialog.kt Outdated
@Giyutomioka-SS
Copy link
Copy Markdown
Contributor Author

It would be very useful to add a test, potentially in androidTest here

At minimum, a @NeedsTest should be added.

LGTM other than the exception check

Sure!

@Giyutomioka-SS Giyutomioka-SS force-pushed the collection-path-mismatch-17524 branch 2 times, most recently from cbef9e3 to 3e8255a Compare March 10, 2026 13:05
Copy link
Copy Markdown
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

Sorry this sat, looks awesome!

@david-allison david-allison added Needs Second Approval Has one approval, one more approval to merge and removed Needs Author Reply Waiting for a reply from the original author Needs Review labels Mar 23, 2026
@criticalAY
Copy link
Copy Markdown
Contributor

@Giyutomioka-SS could you rebase and squash lets get it in

@criticalAY criticalAY self-requested a review March 23, 2026 20:58
@Giyutomioka-SS
Copy link
Copy Markdown
Contributor Author

@Giyutomioka-SS could you rebase and squash lets get it in

I’m away from my laptop at the moment. Would you mind squash merging this PR?

@david-allison david-allison added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) squash-merge A squash & force push is required. The PR author may do this to speed up the merge process. and removed Needs Second Approval Has one approval, one more approval to merge labels Mar 26, 2026
@david-allison david-allison self-assigned this Mar 26, 2026
@david-allison david-allison force-pushed the collection-path-mismatch-17524 branch from 3e8255a to b7b5918 Compare April 6, 2026 06:35
@david-allison david-allison removed the squash-merge A squash & force push is required. The PR author may do this to speed up the merge process. label Apr 6, 2026
@david-allison david-allison added this pull request to the merge queue Apr 6, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 6, 2026
@david-allison david-allison added this pull request to the merge queue Apr 6, 2026
Merged via the queue into ankidroid:main with commit 6880468 Apr 6, 2026
15 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 6, 2026

Maintainers: Please Sync Translations to produce a commit with only the automated changes from this PR.

Read more about updating strings on the wiki,

@github-actions github-actions Bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Apr 6, 2026
@github-actions github-actions Bot added this to the 2.24 release milestone Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Collection not opened" is not actionable if the collection path no longer exists

3 participants