Skip to content
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

[BUG]: CardContentProvider uses the wrong authority uri in parallel builds #17309

Open
3 of 4 tasks
iamllama opened this issue Oct 26, 2024 · 1 comment · May be fixed by #17310
Open
3 of 4 tasks

[BUG]: CardContentProvider uses the wrong authority uri in parallel builds #17309

iamllama opened this issue Oct 26, 2024 · 1 comment · May be fixed by #17310

Comments

@iamllama
Copy link

iamllama commented Oct 26, 2024

Checked for duplicates?

  • This issue is not a duplicate

Does it also happen in the desktop version?

  • This bug does not occur in the latest version of Anki Desktop

What are the steps to reproduce this bug?

  1. Follow the instructions in https://github.com/ankidroid/Anki-Android/wiki/AnkiDroid-API, namely Gradle dependency and Manifest changes required on Android SDK 30+, while replacing com.ichi2.anki with com.ichi2.anki.a (or another parallel build)
  2. Execute a query with the content resolver, e.g.
val res: Cursor? = contentResolver.query(
    FlashCardsContract.Note.CONTENT_URI_V2,
    FlashCardsContract.Note.DEFAULT_PROJECTION,
    null,
    null,
    "${FlashCardsContract.Note._ID} desc"
);

Expected behaviour

A non-null Cursor is expected. Instead, the following error message is logged: Failed to find provider info for com.ichi2.anki.flashcards

This is because AnkiDroid.A's manifest has set CardContentProvider's authority uri to ${applicationId}.flashcards, which in the parallel build expands to com.ichi2.anki.a.flashcards.

<provider
android:name=".provider.CardContentProvider"
android:authorities="${applicationId}.flashcards"
android:enabled="true"
android:exported="true"
>
<meta-data android:name="com.ichi2.anki.provider.spec" android:value="2" />
</provider>

If I try using that instead of FlashCardsContract.Note.CONTENT_URI_V2, i.e.

val res: Cursor? = contentResolver.query(
    Uri.parse("content://com.ichi2.anki.a.flashcards/notes_v2"),
    FlashCardsContract.Note.DEFAULT_PROJECTION,
    null,
    null,
    "${FlashCardsContract.Note._ID} desc"
);

the following exception is thrown:

FATAL EXCEPTION: main
Process: com.blah.app, PID: 15508
java.lang.IllegalArgumentException: uri content://com.ichi2.anki.a.flashcards/notes_v2 is not supported
	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:172)
	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
	at android.content.ContentProviderProxy.query(ContentProviderNative.java:481)
	at android.content.ContentResolver.query(ContentResolver.java:1226)
	at android.content.ContentResolver.query(ContentResolver.java:1158)
	at android.content.ContentResolver.query(ContentResolver.java:1114)
	at com.blah.app.MainActivity.stuff(MainActivity.kt:33)
        ...

The parallel build's content provider now responds, but since it still matches on the incorrect FlashCardsContract.AUTHORITY, the uri is deemed invalid

else -> throw IllegalArgumentException("uri $uri is not supported")

Debug info

AnkiDroid Version = 2.19beta6 (638d0e2)

Backend Version = 0.1.42-anki24.06.3 (24.06.3 d678e39350a2d243242a69f4e22f5192b04398f2)

Android Version = 12 (SDK 31)

(Optional) Anything else you want to share?

One way might be to have CardContentProvider construct its own copy of FlashCardsContract.AUTHORITY using R.string.applicationId BuildConfig.APPLICATION_ID, before passing it to the matcher

fun addUri(path: String, code: Int) = sUriMatcher.addURI(FlashCardsContract.AUTHORITY, path, code)

Research

  • I have checked the manual and the FAQ and could not find a solution to my issue
  • (Optional) I have confirmed the issue is not resolved in the latest alpha release (instructions)
Copy link

welcome bot commented Oct 26, 2024

Hello! 👋 Thanks for logging this issue. Please remember we are all volunteers here, so some patience may be required before we can get to the issue. Also remember that the fastest way to get resolution on an issue is to propose a change directly, https://github.com/ankidroid/Anki-Android/wiki/Contributing

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

Successfully merging a pull request may close this issue.

1 participant