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

Fix CardContentProvider to support parallel builds #17310

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,12 @@ class CardContentProvider : ContentProvider() {
return sanitized.toTypedArray()
}

// Follows the format in the manifest
private const val AUTHORITY = "${BuildConfig.APPLICATION_ID}.flashcards"
private const val PERMISSION = "${BuildConfig.APPLICATION_ID}.permission.READ_WRITE_DATABASE"

init {
fun addUri(path: String, code: Int) = sUriMatcher.addURI(FlashCardsContract.AUTHORITY, path, code)
fun addUri(path: String, code: Int) = sUriMatcher.addURI(AUTHORITY, path, code)
// Here you can see all the URIs at a glance
addUri("notes", NOTES)
addUri("notes_v2", NOTES_V2)
Expand Down Expand Up @@ -1230,16 +1234,16 @@ class CardContentProvider : ContentProvider() {

private fun hasReadWritePermission(): Boolean {
return if (BuildConfig.DEBUG) { // Allow self-calling of the provider only in debug builds (e.g. for unit tests)
context!!.checkCallingOrSelfPermission(FlashCardsContract.READ_WRITE_PERMISSION) == PackageManager.PERMISSION_GRANTED
context!!.checkCallingOrSelfPermission(PERMISSION) == PackageManager.PERMISSION_GRANTED
} else {
context!!.checkCallingPermission(FlashCardsContract.READ_WRITE_PERMISSION) == PackageManager.PERMISSION_GRANTED
context!!.checkCallingPermission(PERMISSION) == PackageManager.PERMISSION_GRANTED
}
}

/** Returns true if the calling package is known to be "rogue" and should be blocked.
* Calling package might be rogue if it has not declared #READ_WRITE_PERMISSION in its manifest */
private fun knownRogueClient(): Boolean =
!context!!.arePermissionsDefinedInManifest(callingPackage!!, FlashCardsContract.READ_WRITE_PERMISSION)
!context!!.arePermissionsDefinedInManifest(callingPackage!!, PERMISSION)
}

/** replaces [anki:play...] with [sound:] */
Expand Down