mirror of
https://github.com/etesync/android
synced 2025-02-02 19:01:06 +00:00
Fix issue with sync on devices that don't require the hash hack.
This commit also unifies the handling so such issues don't recur.
This commit is contained in:
parent
3057a7944c
commit
633e1228f0
@ -249,7 +249,7 @@ class LocalAddressBook(
|
|||||||
* @return number of "really dirty" contacts
|
* @return number of "really dirty" contacts
|
||||||
*/
|
*/
|
||||||
fun verifyDirty(): Int {
|
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")
|
throw IllegalStateException("verifyDirty() should not be called on Android != 7")
|
||||||
|
|
||||||
var reallyDirty = 0
|
var reallyDirty = 0
|
||||||
|
@ -49,6 +49,8 @@ class LocalContact : AndroidContact, LocalAddress {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal const val COLUMN_HASHCODE = ContactsContract.RawContacts.SYNC3
|
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
|
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(AndroidContact.COLUMN_ETAG, eTag)
|
||||||
values.put(ContactsContract.RawContacts.DIRTY, 0)
|
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
|
// workaround for Android 7 which sets DIRTY flag when only meta-data is changed
|
||||||
val hashCode = dataHashCode()
|
val hashCode = dataHashCode()
|
||||||
values.put(COLUMN_HASHCODE, hashCode)
|
values.put(COLUMN_HASHCODE, hashCode)
|
||||||
@ -170,7 +172,7 @@ class LocalContact : AndroidContact, LocalAddress {
|
|||||||
* @return hash code of contact data (including group memberships)
|
* @return hash code of contact data (including group memberships)
|
||||||
*/
|
*/
|
||||||
internal fun dataHashCode(): Int {
|
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")
|
throw IllegalStateException("dataHashCode() should not be called on Android != 7")
|
||||||
|
|
||||||
// reset contact so that getContact() reads from database
|
// reset contact so that getContact() reads from database
|
||||||
@ -184,7 +186,7 @@ class LocalContact : AndroidContact, LocalAddress {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateHashCode(batch: BatchOperation?) {
|
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")
|
throw IllegalStateException("updateHashCode() should not be called on Android != 7")
|
||||||
|
|
||||||
val values = ContentValues(1)
|
val values = ContentValues(1)
|
||||||
@ -203,7 +205,7 @@ class LocalContact : AndroidContact, LocalAddress {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getLastHashCode(): Int {
|
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")
|
throw IllegalStateException("getLastHashCode() should not be called on Android != 7")
|
||||||
|
|
||||||
addressBook.provider!!.query(rawContactSyncURI(), arrayOf(COLUMN_HASHCODE), null, null, null)?.use { c ->
|
addressBook.provider!!.query(rawContactSyncURI(), arrayOf(COLUMN_HASHCODE), null, null, null)?.use { c ->
|
||||||
|
@ -92,7 +92,7 @@ class LocalGroup : AndroidGroup, LocalAddress {
|
|||||||
} ?: Constants.log.warning("Group member not found: $uid")
|
} ?: 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
|
// workaround for Android 7 which sets DIRTY flag when only meta-data is changed
|
||||||
changeContactIDs
|
changeContactIDs
|
||||||
.map { addressBook.findContactByID(it) }
|
.map { addressBook.findContactByID(it) }
|
||||||
|
@ -75,7 +75,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
|||||||
return false
|
return false
|
||||||
val localAddressBook = localAddressBook()
|
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
|
// workaround for Android 7 which sets DIRTY flag when only meta-data is changed
|
||||||
val reallyDirty = localAddressBook.verifyDirty()
|
val reallyDirty = localAddressBook.verifyDirty()
|
||||||
val deleted = localAddressBook.findDeleted().size
|
val deleted = localAddressBook.findDeleted().size
|
||||||
@ -221,7 +221,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
|||||||
syncResult.stats.numInserts++
|
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
|
// workaround for Android 7 which sets DIRTY flag when only meta-data is changed
|
||||||
local.updateHashCode(null)
|
local.updateHashCode(null)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user