diff --git a/app/src/androidTest/kotlin/at/bitfire/davdroid/db/CollectionTest.kt b/app/src/androidTest/kotlin/at/bitfire/davdroid/db/CollectionTest.kt index c46f0818d..fc11cb4d2 100644 --- a/app/src/androidTest/kotlin/at/bitfire/davdroid/db/CollectionTest.kt +++ b/app/src/androidTest/kotlin/at/bitfire/davdroid/db/CollectionTest.kt @@ -7,7 +7,7 @@ package at.bitfire.davdroid.db import android.security.NetworkSecurityPolicy import androidx.test.filters.SmallTest import at.bitfire.dav4jvm.okhttp.DavResource -import at.bitfire.dav4jvm.property.webdav.ResourceType +import at.bitfire.dav4jvm.property.webdav.WebDAV import at.bitfire.davdroid.network.HttpClientBuilder import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest @@ -65,7 +65,7 @@ class CollectionTest { lateinit var info: Collection DavResource(httpClient, server.url("/")) - .propfind(0, ResourceType.NAME) { response, _ -> + .propfind(0, WebDAV.ResourceType) { response, _ -> info = Collection.fromDavResponse(response) ?: throw IllegalArgumentException() } assertEquals(Collection.TYPE_ADDRESSBOOK, info.type) @@ -121,7 +121,7 @@ class CollectionTest { lateinit var info: Collection DavResource(httpClient, server.url("/")) - .propfind(0, ResourceType.NAME) { response, _ -> + .propfind(0, WebDAV.ResourceType) { response, _ -> info = Collection.fromDavResponse(response)!! } assertEquals(Collection.TYPE_CALENDAR, info.type) @@ -157,7 +157,7 @@ class CollectionTest { lateinit var info: Collection DavResource(httpClient, server.url("/")) - .propfind(0, ResourceType.NAME) { response, _ -> + .propfind(0, WebDAV.ResourceType) { response, _ -> info = Collection.fromDavResponse(response)!! } assertEquals(Collection.TYPE_CALENDAR, info.type) @@ -191,7 +191,7 @@ class CollectionTest { lateinit var info: Collection DavResource(httpClient, server.url("/")) - .propfind(0, ResourceType.NAME) { response, _ -> + .propfind(0, WebDAV.ResourceType) { response, _ -> info = Collection.fromDavResponse(response) ?: throw IllegalArgumentException() } assertEquals(Collection.TYPE_WEBCAL, info.type) diff --git a/app/src/androidTest/kotlin/at/bitfire/davdroid/servicedetection/DavResourceFinderTest.kt b/app/src/androidTest/kotlin/at/bitfire/davdroid/servicedetection/DavResourceFinderTest.kt index bc4ee18d6..20d31ab4a 100644 --- a/app/src/androidTest/kotlin/at/bitfire/davdroid/servicedetection/DavResourceFinderTest.kt +++ b/app/src/androidTest/kotlin/at/bitfire/davdroid/servicedetection/DavResourceFinderTest.kt @@ -6,8 +6,8 @@ package at.bitfire.davdroid.servicedetection import android.security.NetworkSecurityPolicy import at.bitfire.dav4jvm.okhttp.DavResource -import at.bitfire.dav4jvm.property.carddav.AddressbookHomeSet -import at.bitfire.dav4jvm.property.webdav.ResourceType +import at.bitfire.dav4jvm.property.carddav.CardDAV +import at.bitfire.dav4jvm.property.webdav.WebDAV import at.bitfire.davdroid.network.HttpClientBuilder import at.bitfire.davdroid.servicedetection.DavResourceFinder.Configuration.ServiceInfo import at.bitfire.davdroid.settings.Credentials @@ -93,8 +93,8 @@ class DavResourceFinderTest { // recognize home set var info = ServiceInfo() DavResource(client, server.url(PATH_CARDDAV + SUBPATH_PRINCIPAL)) - .propfind(0, AddressbookHomeSet.NAME) { response, _ -> - finder.scanResponse(ResourceType.ADDRESSBOOK, response, info) + .propfind(0, CardDAV.AddressbookHomeSet) { response, _ -> + finder.scanResponse(CardDAV.Addressbook, response, info) } assertEquals(0, info.collections.size) assertEquals(1, info.homeSets.size) @@ -103,8 +103,8 @@ class DavResourceFinderTest { // recognize address book info = ServiceInfo() DavResource(client, server.url(PATH_CARDDAV + SUBPATH_ADDRESSBOOK)) - .propfind(0, ResourceType.NAME) { response, _ -> - finder.scanResponse(ResourceType.ADDRESSBOOK, response, info) + .propfind(0, WebDAV.ResourceType) { response, _ -> + finder.scanResponse(CardDAV.Addressbook, response, info) } assertEquals(1, info.collections.size) assertEquals(server.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK/"), info.collections.keys.first()) diff --git a/app/src/androidTest/kotlin/at/bitfire/davdroid/sync/TestSyncManager.kt b/app/src/androidTest/kotlin/at/bitfire/davdroid/sync/TestSyncManager.kt index 6797fe6af..8dbad51fd 100644 --- a/app/src/androidTest/kotlin/at/bitfire/davdroid/sync/TestSyncManager.kt +++ b/app/src/androidTest/kotlin/at/bitfire/davdroid/sync/TestSyncManager.kt @@ -8,6 +8,7 @@ import android.accounts.Account import at.bitfire.dav4jvm.okhttp.DavCollection import at.bitfire.dav4jvm.okhttp.MultiResponseCallback import at.bitfire.dav4jvm.okhttp.Response +import at.bitfire.dav4jvm.property.caldav.CalDAV import at.bitfire.dav4jvm.property.caldav.GetCTag import at.bitfire.davdroid.db.Collection import at.bitfire.davdroid.di.SyncDispatcher @@ -64,7 +65,7 @@ class TestSyncManager @AssistedInject constructor( didQueryCapabilities = true var cTag: SyncState? = null - davCollection.propfind(0, GetCTag.NAME) { response, rel -> + davCollection.propfind(0, CalDAV.GetCTag) { response, rel -> if (rel == Response.HrefRelation.SELF) response[GetCTag::class.java]?.cTag?.let { cTag = SyncState(SyncState.Type.CTAG, it) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt b/app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt index 5fae2b924..85fddb1df 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt @@ -12,6 +12,7 @@ import androidx.room.Index import androidx.room.PrimaryKey import at.bitfire.dav4jvm.okhttp.Response import at.bitfire.dav4jvm.okhttp.UrlUtils +import at.bitfire.dav4jvm.property.caldav.CalDAV import at.bitfire.dav4jvm.property.caldav.CalendarColor import at.bitfire.dav4jvm.property.caldav.CalendarDescription import at.bitfire.dav4jvm.property.caldav.CalendarTimezone @@ -19,6 +20,7 @@ import at.bitfire.dav4jvm.property.caldav.CalendarTimezoneId import at.bitfire.dav4jvm.property.caldav.Source import at.bitfire.dav4jvm.property.caldav.SupportedCalendarComponentSet import at.bitfire.dav4jvm.property.carddav.AddressbookDescription +import at.bitfire.dav4jvm.property.carddav.CardDAV import at.bitfire.dav4jvm.property.push.PushTransports import at.bitfire.dav4jvm.property.push.Topic import at.bitfire.dav4jvm.property.push.WebPush @@ -166,9 +168,9 @@ data class Collection( val url = UrlUtils.withTrailingSlash(dav.href) val type: String = dav[ResourceType::class.java]?.let { resourceType -> when { - resourceType.types.contains(ResourceType.ADDRESSBOOK) -> TYPE_ADDRESSBOOK - resourceType.types.contains(ResourceType.CALENDAR) -> TYPE_CALENDAR - resourceType.types.contains(ResourceType.SUBSCRIBED) -> TYPE_WEBCAL + resourceType.types.contains(CardDAV.Addressbook) -> TYPE_ADDRESSBOOK + resourceType.types.contains(CalDAV.Calendar) -> TYPE_CALENDAR + resourceType.types.contains(CalDAV.Subscribed) -> TYPE_WEBCAL else -> null } } ?: return null diff --git a/app/src/main/kotlin/at/bitfire/davdroid/db/Principal.kt b/app/src/main/kotlin/at/bitfire/davdroid/db/Principal.kt index c76c5f0f3..8c312a095 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/db/Principal.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/db/Principal.kt @@ -12,6 +12,7 @@ import at.bitfire.dav4jvm.okhttp.Response import at.bitfire.dav4jvm.okhttp.UrlUtils import at.bitfire.dav4jvm.property.webdav.DisplayName import at.bitfire.dav4jvm.property.webdav.ResourceType +import at.bitfire.dav4jvm.property.webdav.WebDAV import at.bitfire.davdroid.util.trimToNull import okhttp3.HttpUrl @@ -46,7 +47,7 @@ data class Principal( fun fromDavResponse(serviceId: Long, dav: Response): Principal? { // Check if response is a principal val resourceType = dav[ResourceType::class.java] ?: return null - if (!resourceType.types.contains(ResourceType.PRINCIPAL)) + if (!resourceType.types.contains(WebDAV.Principal)) return null // Try getting the display name of the principal diff --git a/app/src/main/kotlin/at/bitfire/davdroid/push/PushMessageHandler.kt b/app/src/main/kotlin/at/bitfire/davdroid/push/PushMessageHandler.kt index 8c36463bd..3d43bb526 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/push/PushMessageHandler.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/push/PushMessageHandler.kt @@ -7,6 +7,7 @@ package at.bitfire.davdroid.push import androidx.annotation.VisibleForTesting import at.bitfire.dav4jvm.XmlReader import at.bitfire.dav4jvm.XmlUtils +import at.bitfire.dav4jvm.property.push.WebDAVPush import at.bitfire.davdroid.db.Collection.Companion.TYPE_ADDRESSBOOK import at.bitfire.davdroid.repository.AccountRepository import at.bitfire.davdroid.repository.DavCollectionRepository @@ -105,7 +106,7 @@ class PushMessageHandler @Inject constructor( try { parser.setInput(StringReader(message)) - XmlReader(parser).processTag(DavPushMessage.NAME) { + XmlReader(parser).processTag(WebDAVPush.PushMessage) { val pushMessage = DavPushMessage.Factory.create(parser) topic = pushMessage.topic?.topic } diff --git a/app/src/main/kotlin/at/bitfire/davdroid/push/PushRegistrationManager.kt b/app/src/main/kotlin/at/bitfire/davdroid/push/PushRegistrationManager.kt index 475b79d52..3f9cd7a9e 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/push/PushRegistrationManager.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/push/PushRegistrationManager.kt @@ -17,12 +17,7 @@ import at.bitfire.dav4jvm.XmlUtils.insertTag import at.bitfire.dav4jvm.okhttp.DavCollection import at.bitfire.dav4jvm.okhttp.DavResource import at.bitfire.dav4jvm.okhttp.exception.DavException -import at.bitfire.dav4jvm.property.push.AuthSecret -import at.bitfire.dav4jvm.property.push.PushRegister -import at.bitfire.dav4jvm.property.push.PushResource -import at.bitfire.dav4jvm.property.push.Subscription -import at.bitfire.dav4jvm.property.push.SubscriptionPublicKey -import at.bitfire.dav4jvm.property.push.WebPushSubscription +import at.bitfire.dav4jvm.property.push.WebDAVPush import at.bitfire.davdroid.db.Collection import at.bitfire.davdroid.db.Service import at.bitfire.davdroid.di.IoDispatcher @@ -237,26 +232,26 @@ class PushRegistrationManager @Inject constructor( val writer = StringWriter() serializer.setOutput(writer) serializer.startDocument("UTF-8", true) - serializer.insertTag(PushRegister.NAME) { - serializer.insertTag(Subscription.NAME) { + serializer.insertTag(WebDAVPush.PushRegister) { + serializer.insertTag(WebDAVPush.Subscription) { // subscription URL - serializer.insertTag(WebPushSubscription.NAME) { - serializer.insertTag(PushResource.NAME) { + serializer.insertTag(WebDAVPush.WebPushSubscription) { + serializer.insertTag(WebDAVPush.PushResource) { text(endpoint.url) } endpoint.pubKeySet?.let { pubKeySet -> - serializer.insertTag(SubscriptionPublicKey.NAME) { + serializer.insertTag(WebDAVPush.SubscriptionPublicKey) { attribute(null, "type", "p256dh") text(pubKeySet.pubKey) } - serializer.insertTag(AuthSecret.NAME) { + serializer.insertTag(WebDAVPush.AuthSecret) { text(pubKeySet.auth) } } } } // requested expiration - serializer.insertTag(PushRegister.EXPIRES) { + serializer.insertTag(WebDAVPush.Expires) { text(HttpUtils.formatDate(requestedExpiration)) } } diff --git a/app/src/main/kotlin/at/bitfire/davdroid/repository/DavCollectionRepository.kt b/app/src/main/kotlin/at/bitfire/davdroid/repository/DavCollectionRepository.kt index b853a41c9..6dec4270c 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/repository/DavCollectionRepository.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/repository/DavCollectionRepository.kt @@ -12,17 +12,9 @@ import at.bitfire.dav4jvm.okhttp.DavResource import at.bitfire.dav4jvm.okhttp.exception.GoneException import at.bitfire.dav4jvm.okhttp.exception.HttpException import at.bitfire.dav4jvm.okhttp.exception.NotFoundException -import at.bitfire.dav4jvm.property.caldav.CalendarColor -import at.bitfire.dav4jvm.property.caldav.CalendarDescription -import at.bitfire.dav4jvm.property.caldav.CalendarTimezone -import at.bitfire.dav4jvm.property.caldav.CalendarTimezoneId -import at.bitfire.dav4jvm.property.caldav.NS_CALDAV -import at.bitfire.dav4jvm.property.caldav.SupportedCalendarComponentSet -import at.bitfire.dav4jvm.property.carddav.AddressbookDescription -import at.bitfire.dav4jvm.property.carddav.NS_CARDDAV -import at.bitfire.dav4jvm.property.webdav.DisplayName -import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV -import at.bitfire.dav4jvm.property.webdav.ResourceType +import at.bitfire.dav4jvm.property.caldav.CalDAV +import at.bitfire.dav4jvm.property.carddav.CardDAV +import at.bitfire.dav4jvm.property.webdav.WebDAV import at.bitfire.davdroid.Constants import at.bitfire.davdroid.R import at.bitfire.davdroid.db.AppDatabase @@ -318,27 +310,27 @@ class DavCollectionRepository @Inject constructor( setOutput(writer) startDocument("UTF-8", null) - setPrefix("", NS_WEBDAV) - setPrefix("CAL", NS_CALDAV) - setPrefix("CARD", NS_CARDDAV) + setPrefix("", WebDAV.NS_WEBDAV) + setPrefix("CAL", CalDAV.NS_CALDAV) + setPrefix("CARD", CardDAV.NS_CARDDAV) if (addressBook) - startTag(NS_WEBDAV, "mkcol") + startTag(WebDAV.NS_WEBDAV, "mkcol") else - startTag(NS_CALDAV, "mkcalendar") + startTag(CalDAV.NS_CALDAV, "mkcalendar") - insertTag(DavResource.SET) { - insertTag(DavResource.PROP) { - insertTag(ResourceType.NAME) { - insertTag(ResourceType.COLLECTION) + insertTag(WebDAV.Set) { + insertTag(WebDAV.Prop) { + insertTag(WebDAV.ResourceType) { + insertTag(WebDAV.Collection) if (addressBook) - insertTag(ResourceType.ADDRESSBOOK) + insertTag(CardDAV.Addressbook) else - insertTag(ResourceType.CALENDAR) + insertTag(CalDAV.Calendar) } displayName?.let { - insertTag(DisplayName.NAME) { + insertTag(WebDAV.DisplayName) { text(it) } } @@ -346,7 +338,7 @@ class DavCollectionRepository @Inject constructor( if (addressBook) { // addressbook-specific properties description?.let { - insertTag(AddressbookDescription.NAME) { + insertTag(CardDAV.AddressbookDescription) { text(it) } } @@ -354,21 +346,21 @@ class DavCollectionRepository @Inject constructor( } else { // calendar-specific properties description?.let { - insertTag(CalendarDescription.NAME) { + insertTag(CalDAV.CalendarDescription) { text(it) } } color?.let { - insertTag(CalendarColor.NAME) { + insertTag(CalDAV.CalendarColor) { text(DavUtils.ARGBtoCalDAVColor(it)) } } timezoneId?.let { id -> - insertTag(CalendarTimezoneId.NAME) { + insertTag(CalDAV.CalendarTimezoneId) { text(id) } getVTimeZone(id)?.let { vTimezone -> - insertTag(CalendarTimezone.NAME) { + insertTag(CalDAV.CalendarTimezone) { text( // spec requires "an iCalendar object with exactly one VTIMEZONE component" Calendar( @@ -386,19 +378,19 @@ class DavCollectionRepository @Inject constructor( } if (!supportsVEVENT || !supportsVTODO || !supportsVJOURNAL) { - insertTag(SupportedCalendarComponentSet.NAME) { + insertTag(CalDAV.SupportedCalendarComponentSet) { // Only if there's at least one not explicitly supported calendar component set, // otherwise don't include the property, which means "supports everything". if (supportsVEVENT) - insertTag(SupportedCalendarComponentSet.COMP) { + insertTag(CalDAV.Comp) { attribute(null, "name", Component.VEVENT) } if (supportsVTODO) - insertTag(SupportedCalendarComponentSet.COMP) { + insertTag(CalDAV.Comp) { attribute(null, "name", Component.VTODO) } if (supportsVJOURNAL) - insertTag(SupportedCalendarComponentSet.COMP) { + insertTag(CalDAV.Comp) { attribute(null, "name", Component.VJOURNAL) } } @@ -407,9 +399,9 @@ class DavCollectionRepository @Inject constructor( } } if (addressBook) - endTag(NS_WEBDAV, "mkcol") + endTag(WebDAV.NS_WEBDAV, "mkcol") else - endTag(NS_CALDAV, "mkcalendar") + endTag(CalDAV.NS_CALDAV, "mkcalendar") endDocument() } return writer.toString() diff --git a/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/DavResourceFinder.kt b/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/DavResourceFinder.kt index 6e486d913..b3e2298d1 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/DavResourceFinder.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/DavResourceFinder.kt @@ -13,19 +13,15 @@ import at.bitfire.dav4jvm.okhttp.UrlUtils import at.bitfire.dav4jvm.okhttp.exception.DavException import at.bitfire.dav4jvm.okhttp.exception.HttpException import at.bitfire.dav4jvm.okhttp.exception.UnauthorizedException -import at.bitfire.dav4jvm.property.caldav.CalendarColor -import at.bitfire.dav4jvm.property.caldav.CalendarDescription +import at.bitfire.dav4jvm.property.caldav.CalDAV import at.bitfire.dav4jvm.property.caldav.CalendarHomeSet -import at.bitfire.dav4jvm.property.caldav.CalendarTimezone import at.bitfire.dav4jvm.property.caldav.CalendarUserAddressSet -import at.bitfire.dav4jvm.property.caldav.SupportedCalendarComponentSet -import at.bitfire.dav4jvm.property.carddav.AddressbookDescription import at.bitfire.dav4jvm.property.carddav.AddressbookHomeSet +import at.bitfire.dav4jvm.property.carddav.CardDAV import at.bitfire.dav4jvm.property.common.HrefListProperty import at.bitfire.dav4jvm.property.webdav.CurrentUserPrincipal -import at.bitfire.dav4jvm.property.webdav.CurrentUserPrivilegeSet -import at.bitfire.dav4jvm.property.webdav.DisplayName import at.bitfire.dav4jvm.property.webdav.ResourceType +import at.bitfire.dav4jvm.property.webdav.WebDAV import at.bitfire.davdroid.db.Collection import at.bitfire.davdroid.log.StringHandler import at.bitfire.davdroid.network.DnsRecordResolver @@ -230,21 +226,23 @@ class DavResourceFinder @AssistedInject constructor( Service.CARDDAV -> { davBaseURL.propfind( 0, - ResourceType.NAME, DisplayName.NAME, AddressbookDescription.NAME, - AddressbookHomeSet.NAME, - CurrentUserPrincipal.NAME + WebDAV.ResourceType, WebDAV.DisplayName, + WebDAV.CurrentUserPrincipal, + CardDAV.AddressbookHomeSet, + CardDAV.AddressbookDescription ) { response, _ -> - scanResponse(ResourceType.ADDRESSBOOK, response, config) + scanResponse(CardDAV.Addressbook, response, config) } } Service.CALDAV -> { davBaseURL.propfind( 0, - ResourceType.NAME, DisplayName.NAME, CalendarColor.NAME, CalendarDescription.NAME, CalendarTimezone.NAME, CurrentUserPrivilegeSet.NAME, SupportedCalendarComponentSet.NAME, - CalendarHomeSet.NAME, - CurrentUserPrincipal.NAME + WebDAV.ResourceType, WebDAV.DisplayName, + WebDAV.CurrentUserPrincipal, WebDAV.CurrentUserPrivilegeSet, + CalDAV.CalendarHomeSet, + CalDAV.SupportedCalendarComponentSet, CalDAV.CalendarColor, CalDAV.CalendarDescription, CalDAV.CalendarTimezone ) { response, _ -> - scanResponse(ResourceType.CALENDAR, response, config) + scanResponse(CalDAV.Calendar, response, config) } } } @@ -262,7 +260,7 @@ class DavResourceFinder @AssistedInject constructor( fun queryEmailAddress(principal: HttpUrl): List { val mailboxes = LinkedList() try { - DavResource(httpClient, principal, log).propfind(0, CalendarUserAddressSet.NAME) { response, _ -> + DavResource(httpClient, principal, log).propfind(0, CalDAV.CalendarUserAddressSet) { response, _ -> response[CalendarUserAddressSet::class.java]?.let { addressSet -> for (href in addressSet.hrefs) try { @@ -301,11 +299,11 @@ class DavResourceFinder @AssistedInject constructor( val homeSetClass: Class val serviceType: Service when (resourceType) { - ResourceType.ADDRESSBOOK -> { + CardDAV.Addressbook -> { homeSetClass = AddressbookHomeSet::class.java serviceType = Service.CARDDAV } - ResourceType.CALENDAR -> { + CalDAV.Calendar -> { homeSetClass = CalendarHomeSet::class.java serviceType = Service.CALDAV } @@ -326,7 +324,7 @@ class DavResourceFinder @AssistedInject constructor( } // ... and/or a principal? - if (it.types.contains(ResourceType.PRINCIPAL)) + if (it.types.contains(WebDAV.Principal)) principal = davResponse.href } @@ -446,7 +444,7 @@ class DavResourceFinder @AssistedInject constructor( */ fun getCurrentUserPrincipal(url: HttpUrl, service: Service?): HttpUrl? { var principal: HttpUrl? = null - DavResource(httpClient, url, log).propfind(0, CurrentUserPrincipal.NAME) { response, _ -> + DavResource(httpClient, url, log).propfind(0, WebDAV.CurrentUserPrincipal) { response, _ -> response[CurrentUserPrincipal::class.java]?.href?.let { href -> response.requestedUrl.resolve(href)?.let { log.info("Found current-user-principal: $it") diff --git a/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/PrincipalsRefresher.kt b/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/PrincipalsRefresher.kt index 9c1c15934..53c107131 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/PrincipalsRefresher.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/PrincipalsRefresher.kt @@ -6,8 +6,7 @@ package at.bitfire.davdroid.servicedetection import at.bitfire.dav4jvm.okhttp.DavResource import at.bitfire.dav4jvm.okhttp.exception.HttpException -import at.bitfire.dav4jvm.property.webdav.DisplayName -import at.bitfire.dav4jvm.property.webdav.ResourceType +import at.bitfire.dav4jvm.property.webdav.WebDAV import at.bitfire.davdroid.db.AppDatabase import at.bitfire.davdroid.db.Principal import at.bitfire.davdroid.db.Service @@ -36,8 +35,8 @@ class PrincipalsRefresher @AssistedInject constructor( * Principal properties to ask the server for. */ private val principalProperties = arrayOf( - DisplayName.NAME, - ResourceType.NAME + WebDAV.DisplayName, + WebDAV.ResourceType ) /** diff --git a/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/ServiceDetectionUtils.kt b/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/ServiceDetectionUtils.kt index b6f4078ee..3236178e7 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/ServiceDetectionUtils.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/ServiceDetectionUtils.kt @@ -5,19 +5,10 @@ package at.bitfire.davdroid.servicedetection import at.bitfire.dav4jvm.Property -import at.bitfire.dav4jvm.property.caldav.CalendarColor -import at.bitfire.dav4jvm.property.caldav.CalendarDescription -import at.bitfire.dav4jvm.property.caldav.CalendarTimezone -import at.bitfire.dav4jvm.property.caldav.CalendarTimezoneId -import at.bitfire.dav4jvm.property.caldav.Source -import at.bitfire.dav4jvm.property.caldav.SupportedCalendarComponentSet -import at.bitfire.dav4jvm.property.carddav.AddressbookDescription -import at.bitfire.dav4jvm.property.push.PushTransports -import at.bitfire.dav4jvm.property.push.Topic -import at.bitfire.dav4jvm.property.webdav.CurrentUserPrivilegeSet -import at.bitfire.dav4jvm.property.webdav.DisplayName -import at.bitfire.dav4jvm.property.webdav.Owner -import at.bitfire.dav4jvm.property.webdav.ResourceType +import at.bitfire.dav4jvm.property.caldav.CalDAV +import at.bitfire.dav4jvm.property.carddav.CardDAV +import at.bitfire.dav4jvm.property.push.WebDAVPush +import at.bitfire.dav4jvm.property.webdav.WebDAV import at.bitfire.davdroid.db.Collection import at.bitfire.davdroid.db.Service import at.bitfire.davdroid.db.ServiceType @@ -29,24 +20,24 @@ object ServiceDetectionUtils { */ fun collectionQueryProperties(@ServiceType serviceType: String): Array = arrayOf( // generic WebDAV properties - CurrentUserPrivilegeSet.NAME, - DisplayName.NAME, - Owner.NAME, - ResourceType.NAME, - PushTransports.NAME, // WebDAV-Push - Topic.NAME - ) + when (serviceType) { // service-specific CalDAV/CardDAV properties + WebDAV.CurrentUserPrivilegeSet, + WebDAV.DisplayName, + WebDAV.Owner, + WebDAV.ResourceType, + WebDAVPush.Transports, + WebDAVPush.Topic + ) + when (serviceType) { // service-specific CalDAV/CardDAV properties Service.TYPE_CARDDAV -> arrayOf( - AddressbookDescription.NAME + CardDAV.AddressbookDescription ) Service.TYPE_CALDAV -> arrayOf( - CalendarColor.NAME, - CalendarDescription.NAME, - CalendarTimezone.NAME, - CalendarTimezoneId.NAME, - SupportedCalendarComponentSet.NAME, - Source.NAME + CalDAV.CalendarColor, + CalDAV.CalendarDescription, + CalDAV.CalendarTimezone, + CalDAV.CalendarTimezoneId, + CalDAV.SupportedCalendarComponentSet, + CalDAV.Source ) else -> throw IllegalArgumentException() diff --git a/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/ServiceRefresher.kt b/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/ServiceRefresher.kt index e06c24d75..e00ea520e 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/ServiceRefresher.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/servicedetection/ServiceRefresher.kt @@ -8,14 +8,16 @@ import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.okhttp.DavResource import at.bitfire.dav4jvm.okhttp.UrlUtils import at.bitfire.dav4jvm.okhttp.exception.HttpException +import at.bitfire.dav4jvm.property.caldav.CalDAV import at.bitfire.dav4jvm.property.caldav.CalendarHomeSet import at.bitfire.dav4jvm.property.caldav.CalendarProxyReadFor import at.bitfire.dav4jvm.property.caldav.CalendarProxyWriteFor import at.bitfire.dav4jvm.property.carddav.AddressbookHomeSet +import at.bitfire.dav4jvm.property.carddav.CardDAV import at.bitfire.dav4jvm.property.common.HrefListProperty -import at.bitfire.dav4jvm.property.webdav.DisplayName import at.bitfire.dav4jvm.property.webdav.GroupMembership import at.bitfire.dav4jvm.property.webdav.ResourceType +import at.bitfire.dav4jvm.property.webdav.WebDAV import at.bitfire.davdroid.db.HomeSet import at.bitfire.davdroid.db.Service import at.bitfire.davdroid.repository.DavHomeSetRepository @@ -59,18 +61,18 @@ class ServiceRefresher @AssistedInject constructor( */ private val homeSetProperties: Array = arrayOf( // generic WebDAV properties - DisplayName.NAME, - GroupMembership.NAME, - ResourceType.NAME + WebDAV.DisplayName, + WebDAV.GroupMembership, + WebDAV.ResourceType ) + when (service.type) { // service-specific CalDAV/CardDAV properties Service.TYPE_CARDDAV -> arrayOf( - AddressbookHomeSet.NAME, + CardDAV.AddressbookHomeSet, ) Service.TYPE_CALDAV -> arrayOf( - CalendarHomeSet.NAME, - CalendarProxyReadFor.NAME, - CalendarProxyWriteFor.NAME + CalDAV.CalendarHomeSet, + CalDAV.CalendarProxyReadFor, + CalDAV.CalendarProxyWriteFor ) else -> throw IllegalArgumentException() @@ -147,8 +149,8 @@ class ServiceRefresher @AssistedInject constructor( // If current resource is a calendar-proxy-read/write, it's likely that its parent is a principal, too. davResponse[ResourceType::class.java]?.let { resourceType -> val proxyProperties = arrayOf( - ResourceType.CALENDAR_PROXY_READ, - ResourceType.CALENDAR_PROXY_WRITE, + CalDAV.CalendarProxyRead, + CalDAV.CalendarProxyWrite ) if (proxyProperties.any { resourceType.types.contains(it) }) relatedResources += davResponse.href.parent() diff --git a/app/src/main/kotlin/at/bitfire/davdroid/sync/CalendarSyncManager.kt b/app/src/main/kotlin/at/bitfire/davdroid/sync/CalendarSyncManager.kt index 2d22210e8..53c6262db 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/sync/CalendarSyncManager.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/sync/CalendarSyncManager.kt @@ -10,13 +10,13 @@ import at.bitfire.dav4jvm.okhttp.DavCalendar import at.bitfire.dav4jvm.okhttp.MultiResponseCallback import at.bitfire.dav4jvm.okhttp.Response import at.bitfire.dav4jvm.okhttp.exception.DavException +import at.bitfire.dav4jvm.property.caldav.CalDAV import at.bitfire.dav4jvm.property.caldav.CalendarData -import at.bitfire.dav4jvm.property.caldav.GetCTag import at.bitfire.dav4jvm.property.caldav.MaxResourceSize import at.bitfire.dav4jvm.property.caldav.ScheduleTag import at.bitfire.dav4jvm.property.webdav.GetETag import at.bitfire.dav4jvm.property.webdav.SupportedReportSet -import at.bitfire.dav4jvm.property.webdav.SyncToken +import at.bitfire.dav4jvm.property.webdav.WebDAV import at.bitfire.davdroid.Constants import at.bitfire.davdroid.R import at.bitfire.davdroid.db.Collection @@ -109,14 +109,20 @@ class CalendarSyncManager @AssistedInject constructor( SyncException.wrapWithRemoteResourceSuspending(collection.url) { var syncState: SyncState? = null runInterruptible { - davCollection.propfind(0, MaxResourceSize.NAME, SupportedReportSet.NAME, GetCTag.NAME, SyncToken.NAME) { response, relation -> + davCollection.propfind( + 0, + CalDAV.MaxResourceSize, + WebDAV.SupportedReportSet, + CalDAV.GetCTag, + WebDAV.SyncToken + ) { response, relation -> if (relation == Response.HrefRelation.SELF) { response[MaxResourceSize::class.java]?.maxSize?.let { maxSize -> logger.info("Calendar accepts events up to ${Formatter.formatFileSize(context, maxSize)}") } response[SupportedReportSet::class.java]?.let { supported -> - hasCollectionSync = supported.reports.contains(SupportedReportSet.SYNC_COLLECTION) + hasCollectionSync = supported.reports.contains(WebDAV.SyncCollection) } syncState = syncState(response) } diff --git a/app/src/main/kotlin/at/bitfire/davdroid/sync/ContactsSyncManager.kt b/app/src/main/kotlin/at/bitfire/davdroid/sync/ContactsSyncManager.kt index 6f4ba5e30..e0662b2f9 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/sync/ContactsSyncManager.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/sync/ContactsSyncManager.kt @@ -11,15 +11,15 @@ import at.bitfire.dav4jvm.okhttp.DavAddressBook import at.bitfire.dav4jvm.okhttp.MultiResponseCallback import at.bitfire.dav4jvm.okhttp.Response import at.bitfire.dav4jvm.okhttp.exception.DavException -import at.bitfire.dav4jvm.property.caldav.GetCTag +import at.bitfire.dav4jvm.property.caldav.CalDAV import at.bitfire.dav4jvm.property.carddav.AddressData +import at.bitfire.dav4jvm.property.carddav.CardDAV import at.bitfire.dav4jvm.property.carddav.MaxResourceSize import at.bitfire.dav4jvm.property.carddav.SupportedAddressData import at.bitfire.dav4jvm.property.webdav.GetContentType import at.bitfire.dav4jvm.property.webdav.GetETag -import at.bitfire.dav4jvm.property.webdav.ResourceType import at.bitfire.dav4jvm.property.webdav.SupportedReportSet -import at.bitfire.dav4jvm.property.webdav.SyncToken +import at.bitfire.dav4jvm.property.webdav.WebDAV import at.bitfire.davdroid.Constants import at.bitfire.davdroid.R import at.bitfire.davdroid.db.Collection @@ -175,7 +175,14 @@ class ContactsSyncManager @AssistedInject constructor( return SyncException.wrapWithRemoteResourceSuspending(collection.url) { var syncState: SyncState? = null runInterruptible { - davCollection.propfind(0, MaxResourceSize.NAME, SupportedAddressData.NAME, SupportedReportSet.NAME, GetCTag.NAME, SyncToken.NAME) { response, relation -> + davCollection.propfind( + 0, + CardDAV.MaxResourceSize, + CardDAV.SupportedAddressData, + WebDAV.SupportedReportSet, + CalDAV.GetCTag, + WebDAV.SyncToken + ) { response, relation -> if (relation == Response.HrefRelation.SELF) { response[MaxResourceSize::class.java]?.maxSize?.let { maxSize -> logger.info("Address book accepts vCards up to ${Formatter.formatFileSize(context, maxSize)}") @@ -188,7 +195,7 @@ class ContactsSyncManager @AssistedInject constructor( // hasJCard = supported.hasJCard() } response[SupportedReportSet::class.java]?.let { supported -> - hasCollectionSync = supported.reports.contains(SupportedReportSet.SYNC_COLLECTION) + hasCollectionSync = supported.reports.contains(WebDAV.SyncCollection) } syncState = syncState(response) } @@ -317,7 +324,7 @@ class ContactsSyncManager @AssistedInject constructor( override suspend fun listAllRemote(callback: MultiResponseCallback) = SyncException.wrapWithRemoteResourceSuspending(collection.url) { runInterruptible { - davCollection.propfind(1, ResourceType.NAME, GetETag.NAME, callback = callback) + davCollection.propfind(1, WebDAV.ResourceType, WebDAV.GetETag, callback = callback) } } diff --git a/app/src/main/kotlin/at/bitfire/davdroid/sync/JtxSyncManager.kt b/app/src/main/kotlin/at/bitfire/davdroid/sync/JtxSyncManager.kt index 729874c64..2e502034c 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/sync/JtxSyncManager.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/sync/JtxSyncManager.kt @@ -11,11 +11,11 @@ import at.bitfire.dav4jvm.okhttp.DavCalendar import at.bitfire.dav4jvm.okhttp.MultiResponseCallback import at.bitfire.dav4jvm.okhttp.Response import at.bitfire.dav4jvm.okhttp.exception.DavException +import at.bitfire.dav4jvm.property.caldav.CalDAV import at.bitfire.dav4jvm.property.caldav.CalendarData -import at.bitfire.dav4jvm.property.caldav.GetCTag import at.bitfire.dav4jvm.property.caldav.MaxResourceSize import at.bitfire.dav4jvm.property.webdav.GetETag -import at.bitfire.dav4jvm.property.webdav.SyncToken +import at.bitfire.dav4jvm.property.webdav.WebDAV import at.bitfire.davdroid.Constants import at.bitfire.davdroid.R import at.bitfire.davdroid.db.Collection @@ -84,7 +84,7 @@ class JtxSyncManager @AssistedInject constructor( SyncException.wrapWithRemoteResourceSuspending(collection.url) { var syncState: SyncState? = null runInterruptible { - davCollection.propfind(0, GetCTag.NAME, MaxResourceSize.NAME, SyncToken.NAME) { response, relation -> + davCollection.propfind(0, CalDAV.GetCTag, CalDAV.MaxResourceSize, WebDAV.SyncToken) { response, relation -> if (relation == Response.HrefRelation.SELF) { response[MaxResourceSize::class.java]?.maxSize?.let { maxSize -> logger.info("Collection accepts resources up to ${Formatter.formatFileSize(context, maxSize)}") diff --git a/app/src/main/kotlin/at/bitfire/davdroid/sync/SyncManager.kt b/app/src/main/kotlin/at/bitfire/davdroid/sync/SyncManager.kt index 2876bc2bc..6a879bb19 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/sync/SyncManager.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/sync/SyncManager.kt @@ -24,10 +24,13 @@ import at.bitfire.dav4jvm.okhttp.exception.NotFoundException import at.bitfire.dav4jvm.okhttp.exception.PreconditionFailedException import at.bitfire.dav4jvm.okhttp.exception.ServiceUnavailableException import at.bitfire.dav4jvm.okhttp.exception.UnauthorizedException +import at.bitfire.dav4jvm.property.caldav.CalDAV import at.bitfire.dav4jvm.property.caldav.GetCTag import at.bitfire.dav4jvm.property.caldav.ScheduleTag import at.bitfire.dav4jvm.property.webdav.GetETag +import at.bitfire.dav4jvm.property.webdav.ResourceType import at.bitfire.dav4jvm.property.webdav.SyncToken +import at.bitfire.dav4jvm.property.webdav.WebDAV import at.bitfire.davdroid.R import at.bitfire.davdroid.db.Collection import at.bitfire.davdroid.repository.AccountRepository @@ -62,19 +65,19 @@ import javax.net.ssl.SSLHandshakeException /** * Synchronizes a local collection with a remote collection. * - * @param ResourceType type of local resources + * @param LocalType type of local resources * @param CollectionType type of local collection * @param RemoteType type of remote collection * - * @param account account to synchronize - * @param httpClient HTTP client to use for network requests, already authenticated with credentials from [account] - * @param dataType data type to synchronize - * @param syncResult receiver for result of the synchronization (will be updated by [performSync]) - * @param localCollection local collection to synchronize (interface to content provider) - * @param collection collection info in the database - * @param resync whether re-synchronization is requested + * @param account account to synchronize + * @param httpClient HTTP client to use for network requests, already authenticated with credentials from [account] + * @param dataType data type to synchronize + * @param syncResult receiver for result of the synchronization (will be updated by [performSync]) + * @param localCollection local collection to synchronize (interface to content provider) + * @param collection collection info in the database + * @param resync whether re-synchronization is requested */ -abstract class SyncManager, RemoteType: DavCollection>( +abstract class SyncManager, RemoteType: DavCollection>( val account: Account, val httpClient: OkHttpClient, val dataType: SyncDataType, @@ -209,7 +212,7 @@ abstract class SyncManager { // HTTP 403 Forbidden // If and only if the upload failed because of missing permissions, treat it like 412. - if (ex.errors.contains(Error.NEED_PRIVILEGES)) + if (ex.errors.contains(Error(WebDAV.NeedPrivileges))) logger.log(Level.INFO, "Couldn't upload because of missing permissions, ignoring", ex) else throw e @@ -490,7 +493,7 @@ abstract class SyncManager when (relation) { Response.HrefRelation.SELF -> @@ -747,7 +750,7 @@ abstract class SyncManager + davCollection.propfind(0, CalDAV.GetCTag, WebDAV.SyncToken) { response, relation -> if (relation == Response.HrefRelation.SELF) state = syncState(response) } diff --git a/app/src/main/kotlin/at/bitfire/davdroid/sync/TasksSyncManager.kt b/app/src/main/kotlin/at/bitfire/davdroid/sync/TasksSyncManager.kt index 82d62250f..dc14b2ed3 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/sync/TasksSyncManager.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/sync/TasksSyncManager.kt @@ -10,11 +10,11 @@ import at.bitfire.dav4jvm.okhttp.DavCalendar import at.bitfire.dav4jvm.okhttp.MultiResponseCallback import at.bitfire.dav4jvm.okhttp.Response import at.bitfire.dav4jvm.okhttp.exception.DavException +import at.bitfire.dav4jvm.property.caldav.CalDAV import at.bitfire.dav4jvm.property.caldav.CalendarData -import at.bitfire.dav4jvm.property.caldav.GetCTag import at.bitfire.dav4jvm.property.caldav.MaxResourceSize import at.bitfire.dav4jvm.property.webdav.GetETag -import at.bitfire.dav4jvm.property.webdav.SyncToken +import at.bitfire.dav4jvm.property.webdav.WebDAV import at.bitfire.davdroid.Constants import at.bitfire.davdroid.R import at.bitfire.davdroid.db.Collection @@ -86,7 +86,7 @@ class TasksSyncManager @AssistedInject constructor( SyncException.wrapWithRemoteResourceSuspending(collection.url) { var syncState: SyncState? = null runInterruptible { - davCollection.propfind(0, MaxResourceSize.NAME, GetCTag.NAME, SyncToken.NAME) { response, relation -> + davCollection.propfind(0, CalDAV.MaxResourceSize, CalDAV.GetCTag, WebDAV.SyncToken) { response, relation -> if (relation == Response.HrefRelation.SELF) { response[MaxResourceSize::class.java]?.maxSize?.let { maxSize -> logger.info("Calendar accepts tasks up to ${Formatter.formatFileSize(context, maxSize)}") diff --git a/app/src/main/kotlin/at/bitfire/davdroid/webdav/operation/QueryChildDocumentsOperation.kt b/app/src/main/kotlin/at/bitfire/davdroid/webdav/operation/QueryChildDocumentsOperation.kt index 6f70e7bb5..393931e31 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/webdav/operation/QueryChildDocumentsOperation.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/webdav/operation/QueryChildDocumentsOperation.kt @@ -18,6 +18,7 @@ import at.bitfire.dav4jvm.property.webdav.GetLastModified import at.bitfire.dav4jvm.property.webdav.QuotaAvailableBytes import at.bitfire.dav4jvm.property.webdav.QuotaUsedBytes import at.bitfire.dav4jvm.property.webdav.ResourceType +import at.bitfire.dav4jvm.property.webdav.WebDAV import at.bitfire.davdroid.R import at.bitfire.davdroid.db.AppDatabase import at.bitfire.davdroid.db.WebDavDocument @@ -153,7 +154,7 @@ class QueryChildDocumentsOperation @Inject constructor( } val updatedResource = resource.copy( - isDirectory = response[ResourceType::class.java]?.types?.contains(ResourceType.COLLECTION) + isDirectory = response[ResourceType::class.java]?.types?.contains(WebDAV.Collection) ?: resource.isDirectory, displayName = response[DisplayName::class.java]?.displayName, mimeType = response[GetContentType::class.java]?.type?.toMediaTypeOrNull(), @@ -191,15 +192,15 @@ class QueryChildDocumentsOperation @Inject constructor( companion object { val DAV_FILE_FIELDS = arrayOf( - ResourceType.NAME, - CurrentUserPrivilegeSet.NAME, - DisplayName.NAME, - GetETag.NAME, - GetContentType.NAME, - GetContentLength.NAME, - GetLastModified.NAME, - QuotaAvailableBytes.NAME, - QuotaUsedBytes.NAME, + WebDAV.ResourceType, + WebDAV.CurrentUserPrivilegeSet, + WebDAV.DisplayName, + WebDAV.GetETag, + WebDAV.GetContentType, + WebDAV.GetContentLength, + WebDAV.GetLastModified, + WebDAV.QuotaAvailableBytes, + WebDAV.QuotaUsedBytes, ) /** List of currently active [queryChildDocuments] runners. diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c12d7afd1..4694197db 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,7 +19,7 @@ androidx-test-rules = "1.7.0" androidx-test-junit = "1.3.0" androidx-work = "2.11.0" bitfire-cert4android = "42d883e958" -bitfire-dav4jvm = "ad80cdccac" +bitfire-dav4jvm = "acd9bca096" bitfire-synctools = "017187c6d8" compose-accompanist = "0.37.3" compose-bom = "2025.11.01"