-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix CardContentProvider to support parallel builds #17310
base: main
Are you sure you want to change the base?
Conversation
First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible. |
The existing changes are enough to get the content provider working on parallel builds as long as users construct their own uris. All the provided uris in It doesn't seem ideal to publish parallel builds of the api lib along with ankidroid, because they'd only differ by authority and end-user apps would have to anticipate and import all variants that they might use. But then that's where the tests and apps get the content uris from, so there has to be some way to specify the suffix.
I'd be in favour of option 3, seeing as how it anticipates the arrival of profiles, were it not for the fact that android only allows one content provider per authority 🤔 |
I don't think there is a way around parallel builds or debug etc installing separate ContentProviders - they must do that because this is how we test entirely different code, not just for some future state where there are multiple profiles living under a single ContentProvider (option 3) But, what about....discovery? Any API consumer could take advantage of multiple AnkiDroid installs (debug, parallel, whatever) if it knows they are possible and queries for all the ContentProviders that answer the AnkiDroid API, and allows the user to pick, then uses the correct URIs as a dymamic thing after pick Could that work? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR seems sensible to me as a start, and perhaps content provider discover can solve the problem on client side of selecting the right URI
One doubt:
Is FlashCardsContract.AUTHORITY and/or FlashCardsContract.READ_WRITE_PERMISSION still in use then?
Perhaps those constants should be changed where they are defined instead of leaving them behind and building fresh constants from the possibly-different package name here ?
TIL 😅! An app could get all authorities via packageManager!!.queryIntentContentProviders(Intent("com.ichi2.anki.CARD_CONTENT_PROVIDER"), 0).mapNotNull{ it?.providerInfo?.authority } for example, with
They're still used in Anki-Android/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/ContentProviderTest.kt Line 638 in e9fe007
where FlashCardsContract.Model.CONTENT_URI is constructed using FlashCardsContract.AUTHORITY
These tests currently don't fail because Anki-Android/api/build.gradle.kts Lines 34 to 42 in e9fe007
which sets BuildConfig and in turn:Anki-Android/api/src/main/java/com/ichi2/anki/FlashCardsContract.kt Lines 90 to 91 in e9fe007
|
Also, following Would it be better for all non-debug builds to use the suffix-less In any case, apps can request runtime perms for each parallel build it finds via discovery |
If you can please please avoid merge commits as they make the commit history very difficult to read - we typically rebase in this repo, and we rebase almost 100% of the time for complicated functionality, with the commits broken into independent "ideas" implemented one commit at a time for easier review. Review is frequently the blocker for merging PRs so doing this - using small atomic commits that each do one thing, and using rebase commits, can frequently speed up getting features in |
Undid the merge, sorry about that!! |
No worries at all, it's really nice to have someone taking a good look at the ContentProvider and I think there are going to be some really good advances from all of this. Most repos just merge away but we're just picky I guess 😆 . Cheers |
I've added convenience methods to let apps (that want to support parallel builds) construct content uris for the provider. This should also allow apps that rely on the existing hardcoded content uris to continue to work as normal. Now, instead of using And in Anki-Android/AnkiDroid/src/main/java/com/ichi2/anki/provider/CardContentProvider.kt Lines 140 to 141 in 26b876d
Would this work? 🤔 |
Purpose / Description
CardContentProvider is currently broken for parallel builds
Fixes
Approach
Makes the authority uri and permission rely on the application id, instead of being hardcoded for the release and debug builds.
Work still needs to be done to update the relevant tests, but I don't know how to get at the build config in there 🤔
How Has This Been Tested?
Tested on the debug build
Checklist
Please, go through these checks before submitting the PR.