diff --git a/app/src/main/java/com/etesync/syncadapter/resource/LocalAddressBook.kt b/app/src/main/java/com/etesync/syncadapter/resource/LocalAddressBook.kt index 8c84ef02..0518b3e0 100644 --- a/app/src/main/java/com/etesync/syncadapter/resource/LocalAddressBook.kt +++ b/app/src/main/java/com/etesync/syncadapter/resource/LocalAddressBook.kt @@ -249,7 +249,7 @@ class LocalAddressBook( * @return number of "really dirty" contacts */ fun verifyDirty(): Int { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + if (!LocalContact.HASH_HACK) throw IllegalStateException("verifyDirty() should not be called on Android != 7") var reallyDirty = 0 diff --git a/app/src/main/java/com/etesync/syncadapter/resource/LocalContact.kt b/app/src/main/java/com/etesync/syncadapter/resource/LocalContact.kt index 428add3e..e83e1c25 100644 --- a/app/src/main/java/com/etesync/syncadapter/resource/LocalContact.kt +++ b/app/src/main/java/com/etesync/syncadapter/resource/LocalContact.kt @@ -49,6 +49,8 @@ class LocalContact : AndroidContact, LocalAddress { } internal const val COLUMN_HASHCODE = ContactsContract.RawContacts.SYNC3 + + internal val HASH_HACK = Build.VERSION_CODES.N <= Build.VERSION.SDK_INT && Build.VERSION.SDK_INT < Build.VERSION_CODES.O } private var saveAsDirty = false // When true, the resource will be saved as dirty @@ -99,7 +101,7 @@ class LocalContact : AndroidContact, LocalAddress { values.put(AndroidContact.COLUMN_ETAG, eTag) values.put(ContactsContract.RawContacts.DIRTY, 0) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + if (LocalContact.HASH_HACK) { // workaround for Android 7 which sets DIRTY flag when only meta-data is changed val hashCode = dataHashCode() values.put(COLUMN_HASHCODE, hashCode) @@ -170,7 +172,7 @@ class LocalContact : AndroidContact, LocalAddress { * @return hash code of contact data (including group memberships) */ internal fun dataHashCode(): Int { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + if (!LocalContact.HASH_HACK) throw IllegalStateException("dataHashCode() should not be called on Android != 7") // reset contact so that getContact() reads from database @@ -184,7 +186,7 @@ class LocalContact : AndroidContact, LocalAddress { } fun updateHashCode(batch: BatchOperation?) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + if (!LocalContact.HASH_HACK) throw IllegalStateException("updateHashCode() should not be called on Android != 7") val values = ContentValues(1) @@ -203,7 +205,7 @@ class LocalContact : AndroidContact, LocalAddress { } fun getLastHashCode(): Int { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + if (!LocalContact.HASH_HACK) throw IllegalStateException("getLastHashCode() should not be called on Android != 7") addressBook.provider!!.query(rawContactSyncURI(), arrayOf(COLUMN_HASHCODE), null, null, null)?.use { c -> diff --git a/app/src/main/java/com/etesync/syncadapter/resource/LocalGroup.kt b/app/src/main/java/com/etesync/syncadapter/resource/LocalGroup.kt index 85625a0d..f86cc275 100644 --- a/app/src/main/java/com/etesync/syncadapter/resource/LocalGroup.kt +++ b/app/src/main/java/com/etesync/syncadapter/resource/LocalGroup.kt @@ -92,7 +92,7 @@ class LocalGroup : AndroidGroup, LocalAddress { } ?: Constants.log.warning("Group member not found: $uid") } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && Build.VERSION.SDK_INT < Build.VERSION_CODES.O) + if (LocalContact.HASH_HACK) // workaround for Android 7 which sets DIRTY flag when only meta-data is changed changeContactIDs .map { addressBook.findContactByID(it) } diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/ContactsSyncManager.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/ContactsSyncManager.kt index 1b16eb18..6572d198 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/ContactsSyncManager.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/ContactsSyncManager.kt @@ -75,7 +75,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra return false val localAddressBook = localAddressBook() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + if (LocalContact.HASH_HACK) { // workaround for Android 7 which sets DIRTY flag when only meta-data is changed val reallyDirty = localAddressBook.verifyDirty() val deleted = localAddressBook.findDeleted().size @@ -221,7 +221,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra syncResult.stats.numInserts++ } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && local is LocalContact) + if (LocalContact.HASH_HACK && local is LocalContact) // workaround for Android 7 which sets DIRTY flag when only meta-data is changed local.updateHashCode(null)