Skip to content

feat: profile attachBaseContext - #21809

Merged
david-allison merged 2 commits into
ankidroid:mainfrom
criticalAY:profiles/context-attach
Sep 29, 2026
Merged

david-allison merged 2 commits into
ankidroid:mainfrom
criticalAY:profiles/context-attach

Conversation

@criticalAY

@criticalAY criticalAY commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Purpose / Description

ProfileManager and ProfileContextWrapper are fully implemented and tested, but had zero callers in src/main. attachBaseContext appeared nowhere so preparing for wiring data

Fixes

Approach

See commits

How Has This Been Tested?

Added test

Learning (optional, can help others)

The attachBaseContext -> ContentProvider.onCreate -> Application.onCreate ordering is the crux

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

@david-allison

This comment was marked as resolved.

@criticalAY criticalAY added the Multi Profile Anything that is related to AnkiDroid multiple profiles label Sep 10, 2026

@david-allison david-allison 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.

Could you implement this for Activities as well, or is this over-reaching in this PR?

Comment thread AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidApp.kt Outdated
@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Sep 11, 2026
@criticalAY
criticalAY force-pushed the profiles/context-attach branch from f19e552 to 9052098 Compare September 18, 2026 07:18
@criticalAY criticalAY removed the Needs Author Reply Waiting for a reply from the original author label Sep 18, 2026
}
}

private var profileManager: ProfileManager? = null

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.

I'd consider subclassing for this: what do you think? This one would want to get a second opinion before implementation

@david-allison david-allison 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 as an incremental improvement.

Needs thought & testing, as these won't yet work under this implementation for a new profile

  • MetaDB
  • ACRA

@david-allison david-allison added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Sep 18, 2026
@criticalAY
criticalAY force-pushed the profiles/context-attach branch from 9052098 to 296f37b Compare September 18, 2026 15:10
Loads the active profile without throwing, so a caller can fall back to
the base context. Throwing during attachBaseContext would stop the app
from starting at all.

Timber is not planted that early, so the failure is recorded in
attachError for the caller to log once logging is available.

No caller yet.
AnkiDroidApp now routes its preferences, files, cache, databases and
dirs through the active profile. It is set up in attachBaseContext so
content providers, which get the Application itself, see it too.

The framework's base context is left alone. ActivityThread casts it to
ContextImpl when it delivers a manifest broadcast, so handing it a
wrapper crashed every receiver, starting with BootService after boot.

The ACRA sender process skips the setup: it only sends reports, and
it should not write the profile registry from a second process.

Users with only the Default profile are unaffected, since the wrapper
passes everything through for that profile. Attach failures are logged
once Timber is planted.

Assisted-by: Claude Opus 5 [helped with tests]
@criticalAY
criticalAY force-pushed the profiles/context-attach branch from 296f37b to c975487 Compare September 29, 2026 07:50
@david-allison
david-allison added this pull request to the merge queue Sep 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 29, 2026
@david-allison
david-allison added this pull request to the merge queue Sep 29, 2026
Merged via the queue into ankidroid:main with commit a1695c9 Sep 29, 2026
23 checks passed
@github-actions github-actions Bot added this to the 2.26 release milestone Sep 29, 2026
@github-actions github-actions Bot removed the Needs Second Approval Has one approval, one more approval to merge label Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Multi Profile Anything that is related to AnkiDroid multiple profiles

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants