This repository was archived by the owner on May 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Support UnknownProperties and GroupMembership #438
Merged
rfc2822
merged 9 commits into
main
from
422-contacts-rewrite-provide-all-davx-functionality-in-synctools
May 25, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
53bd0f0
Move UnknownProperties and GroupMembership from synctools to davx5-ose
rfc2822 37de6b0
Don't initialize handlers/builders in davx5-ose anymore (everything i…
rfc2822 3da24a5
Add ...Contract to UnknownProperty and CachedGroupMembership definitions
rfc2822 6361822
Minor changes, revert mistaken copyright changes
rfc2822 9897a59
Update copyright
rfc2822 aa19446
Fix test
rfc2822 1e8b0cc
Minor changes
rfc2822 3770574
Simplify handler/builder creation
rfc2822 b3192a5
Add KDoc
rfc2822 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...idTest/kotlin/at/bitfire/synctools/mapping/contacts/builder/GroupMembershipBuilderTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * This file is part of bitfireAT/synctools which is released under GPLv3. | ||
| * Copyright © All Contributors. See the LICENSE and AUTHOR files in the root directory for details. | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| */ | ||
|
|
||
| package at.bitfire.synctools.mapping.contacts.builder | ||
|
|
||
| import android.Manifest | ||
| import android.accounts.Account | ||
| import android.content.ContentProviderClient | ||
| import android.net.Uri | ||
| import android.provider.ContactsContract | ||
| import android.provider.ContactsContract.CommonDataKinds.GroupMembership | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import androidx.test.rule.GrantPermissionRule | ||
| import at.bitfire.synctools.mapping.contacts.Contact | ||
| import at.bitfire.synctools.storage.contacts.TestAddressBook | ||
| import at.bitfire.synctools.vcard.GroupMethod | ||
| import org.junit.AfterClass | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.BeforeClass | ||
| import org.junit.ClassRule | ||
| import org.junit.Test | ||
|
|
||
| class GroupMembershipBuilderTest { | ||
|
|
||
| @Test | ||
| fun testCategories_GroupsAsCategories() { | ||
| val addressBook = TestAddressBook(account, provider) | ||
| val contact = Contact().apply { | ||
| categories += "TEST GROUP" | ||
| } | ||
| GroupMembershipBuilder(Uri.EMPTY, null, contact, addressBook, GroupMethod.CATEGORIES, false).build().also { result -> | ||
| assertEquals(1, result.size) | ||
| assertEquals(GroupMembership.CONTENT_ITEM_TYPE, result[0].values[GroupMembership.MIMETYPE]) | ||
| assertEquals(addressBook.findOrCreateGroup("TEST GROUP"), result[0].values[GroupMembership.GROUP_ROW_ID]) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun testCategories_GroupsAsVCards() { | ||
| val addressBook = TestAddressBook(account, provider) | ||
| val contact = Contact().apply { | ||
| categories += "TEST GROUP" | ||
| } | ||
| GroupMembershipBuilder(Uri.EMPTY, null, contact, addressBook, GroupMethod.GROUP_VCARDS, false).build().also { result -> | ||
| // group membership is constructed during post-processing | ||
| assertEquals(0, result.size) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| companion object { | ||
|
|
||
| @JvmField | ||
| @ClassRule | ||
| val permissionRule = GrantPermissionRule.grant(Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS)!! | ||
|
|
||
| val account = Account("GroupMembershipBuilderTest", "at.bitfire.vcard4android") | ||
|
|
||
| private lateinit var provider: ContentProviderClient | ||
|
|
||
| @BeforeClass | ||
| @JvmStatic | ||
| fun connect() { | ||
| val context = InstrumentationRegistry.getInstrumentation().context | ||
| provider = context.contentResolver.acquireContentProviderClient(ContactsContract.AUTHORITY)!! | ||
| } | ||
|
|
||
| @AfterClass | ||
| @JvmStatic | ||
| fun disconnect() { | ||
| provider.close() | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
67 changes: 67 additions & 0 deletions
67
.../kotlin/at/bitfire/synctools/mapping/contacts/handler/CachedGroupMembershipHandlerTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * This file is part of bitfireAT/synctools which is released under GPLv3. | ||
| * Copyright © All Contributors. See the LICENSE and AUTHOR files in the root directory for details. | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| */ | ||
|
|
||
| package at.bitfire.synctools.mapping.contacts.handler | ||
|
|
||
| import android.Manifest | ||
| import android.accounts.Account | ||
| import android.content.ContentProviderClient | ||
| import android.content.ContentValues | ||
| import android.provider.ContactsContract | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import androidx.test.rule.GrantPermissionRule | ||
| import at.bitfire.synctools.mapping.contacts.Contact | ||
| import at.bitfire.synctools.storage.contacts.AndroidContact | ||
| import at.bitfire.synctools.storage.contacts.CachedGroupMembershipContract | ||
| import at.bitfire.synctools.storage.contacts.TestAddressBook | ||
| import at.bitfire.synctools.vcard.GroupMethod | ||
| import org.junit.AfterClass | ||
| import org.junit.Assert.assertArrayEquals | ||
| import org.junit.BeforeClass | ||
| import org.junit.ClassRule | ||
| import org.junit.Test | ||
|
|
||
| class CachedGroupMembershipHandlerTest { | ||
|
|
||
| @Test | ||
| fun testMembership() { | ||
| val addressBook = TestAddressBook(account, provider) | ||
| val contact = Contact() | ||
| val androidContact = AndroidContact(addressBook, contact, null, null) | ||
| CachedGroupMembershipHandler(androidContact, GroupMethod.GROUP_VCARDS).handle(ContentValues().apply { | ||
| put(CachedGroupMembershipContract.GROUP_ID, 123456) | ||
| put(CachedGroupMembershipContract.RAW_CONTACT_ID, 789) | ||
| }, contact) | ||
| assertArrayEquals(arrayOf(123456L), androidContact.cachedGroupMemberships.toArray()) | ||
| } | ||
|
|
||
|
|
||
| companion object { | ||
|
|
||
| @JvmField | ||
| @ClassRule | ||
| val permissionRule = GrantPermissionRule.grant(Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS)!! | ||
|
|
||
| val account = Account("CachedGroupMembershipHandlerTest", "at.bitfire.vcard4android") | ||
|
|
||
| private lateinit var provider: ContentProviderClient | ||
|
|
||
| @BeforeClass | ||
| @JvmStatic | ||
| fun connect() { | ||
| val context = InstrumentationRegistry.getInstrumentation().context | ||
| provider = context.contentResolver.acquireContentProviderClient(ContactsContract.AUTHORITY)!! | ||
| } | ||
|
|
||
| @AfterClass | ||
| @JvmStatic | ||
| fun disconnect() { | ||
| provider.close() | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
85 changes: 85 additions & 0 deletions
85
...idTest/kotlin/at/bitfire/synctools/mapping/contacts/handler/GroupMembershipHandlerTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * This file is part of bitfireAT/synctools which is released under GPLv3. | ||
| * Copyright © All Contributors. See the LICENSE and AUTHOR files in the root directory for details. | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| */ | ||
|
|
||
| package at.bitfire.synctools.mapping.contacts.handler | ||
|
|
||
| import android.Manifest | ||
| import android.accounts.Account | ||
| import android.content.ContentProviderClient | ||
| import android.content.ContentValues | ||
| import android.provider.ContactsContract | ||
| import android.provider.ContactsContract.CommonDataKinds.GroupMembership | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import androidx.test.rule.GrantPermissionRule | ||
| import at.bitfire.synctools.mapping.contacts.Contact | ||
| import at.bitfire.synctools.storage.contacts.AndroidContact | ||
| import at.bitfire.synctools.storage.contacts.CachedGroupMembershipContract | ||
| import at.bitfire.synctools.storage.contacts.TestAddressBook | ||
| import at.bitfire.synctools.vcard.GroupMethod | ||
| import org.junit.AfterClass | ||
| import org.junit.Assert.assertArrayEquals | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.BeforeClass | ||
| import org.junit.ClassRule | ||
| import org.junit.Test | ||
|
|
||
| class GroupMembershipHandlerTest { | ||
|
|
||
| @Test | ||
| fun testMembership_GroupsAsCategories() { | ||
| val addressBook = TestAddressBook(account, provider) | ||
| val groupId = addressBook.findOrCreateGroup("TEST GROUP") | ||
|
|
||
| val contact = Contact() | ||
| val androidContact = AndroidContact(addressBook, contact, null, null) | ||
| GroupMembershipHandler(androidContact, GroupMethod.CATEGORIES).handle(ContentValues().apply { | ||
| put(GroupMembership.GROUP_ROW_ID, groupId) | ||
| put(CachedGroupMembershipContract.RAW_CONTACT_ID, -1) | ||
| }, contact) | ||
| assertArrayEquals(arrayOf(groupId), androidContact.groupMemberships.toArray()) | ||
| assertArrayEquals(arrayOf("TEST GROUP"), contact.categories.toArray()) | ||
| } | ||
|
|
||
| @Test | ||
| fun testMembership_GroupsAsVCards() { | ||
| val addressBook = TestAddressBook(account, provider) | ||
| val contact = Contact() | ||
| val androidContact = AndroidContact(addressBook, contact, null, null) | ||
| GroupMembershipHandler(androidContact, GroupMethod.GROUP_VCARDS).handle(ContentValues().apply { | ||
| put(GroupMembership.GROUP_ROW_ID, 12345L) // group doesn't have to really exist for GROUP_VCARDS | ||
| put(CachedGroupMembershipContract.RAW_CONTACT_ID, -1) | ||
| }, contact) | ||
| assertArrayEquals(arrayOf(12345L), androidContact.groupMemberships.toArray()) | ||
| assertTrue(contact.categories.isEmpty()) | ||
| } | ||
|
|
||
|
|
||
| companion object { | ||
|
|
||
| @JvmField | ||
| @ClassRule | ||
| val permissionRule = GrantPermissionRule.grant(Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS)!! | ||
|
|
||
| val account = Account("GroupMembershipHandlerTest", "at.bitfire.vcard4android") | ||
|
|
||
| private lateinit var provider: ContentProviderClient | ||
|
|
||
| @BeforeClass | ||
| @JvmStatic | ||
| fun connect() { | ||
| val context = InstrumentationRegistry.getInstrumentation().context | ||
| provider = context.contentResolver.acquireContentProviderClient(ContactsContract.AUTHORITY)!! | ||
| } | ||
|
|
||
| @AfterClass | ||
| @JvmStatic | ||
| fun disconnect() { | ||
| provider.close() | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
lib/src/main/kotlin/at/bitfire/synctools/mapping/contacts/builder/GroupMembershipBuilder.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * This file is part of bitfireAT/synctools which is released under GPLv3. | ||
| * Copyright © All Contributors. See the LICENSE and AUTHOR files in the root directory for details. | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| */ | ||
|
|
||
| package at.bitfire.synctools.mapping.contacts.builder | ||
|
|
||
| import android.net.Uri | ||
| import android.provider.ContactsContract.CommonDataKinds.GroupMembership | ||
| import at.bitfire.synctools.mapping.contacts.Contact | ||
| import at.bitfire.synctools.storage.BatchOperation | ||
| import at.bitfire.synctools.storage.contacts.AndroidAddressBook | ||
| import at.bitfire.synctools.vcard.GroupMethod | ||
| import java.util.LinkedList | ||
|
|
||
| class GroupMembershipBuilder( | ||
| dataRowUri: Uri, | ||
| rawContactId: Long?, | ||
| contact: Contact, | ||
| val addressBook: AndroidAddressBook<*, *>, | ||
| val groupMethod: GroupMethod, | ||
| readOnly: Boolean | ||
| ) : DataRowBuilder(Factory.MIME_TYPE, dataRowUri, rawContactId, contact, readOnly) { | ||
|
|
||
| override fun build(): List<BatchOperation.CpoBuilder> { | ||
| val result = LinkedList<BatchOperation.CpoBuilder>() | ||
|
|
||
| if (groupMethod == GroupMethod.CATEGORIES) | ||
| for (category in contact.categories) | ||
| result += newDataRow().withValue(GroupMembership.GROUP_ROW_ID, addressBook.findOrCreateGroup(category)) | ||
| else { | ||
|
rfc2822 marked this conversation as resolved.
|
||
| // GroupMethod.GROUP_VCARDS -> memberships are handled by AndroidGroups (and not by the members = AndroidContacts, which we are processing here) | ||
| // TODO: CATEGORIES <-> unknown properties | ||
| } | ||
|
|
||
| return result | ||
| } | ||
|
|
||
|
|
||
| class Factory(val addressBook: AndroidAddressBook<*, *>, val groupMethod: GroupMethod) : DataRowBuilder.Factory<GroupMembershipBuilder> { | ||
| companion object { | ||
| const val MIME_TYPE = GroupMembership.CONTENT_ITEM_TYPE | ||
| } | ||
|
|
||
| override fun mimeType() = MIME_TYPE | ||
| override fun newInstance(dataRowUri: Uri, rawContactId: Long?, contact: Contact, readOnly: Boolean) = | ||
| GroupMembershipBuilder(dataRowUri, rawContactId, contact, addressBook, groupMethod, readOnly) | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.