0
0
mirror of https://github.com/etesync/android.git synced 2024-09-20 04:42:28 +02:00

Address books accounts: set initial user data twice for older Android versions

This commit is contained in:
Ricki Hirner 2019-06-20 12:26:19 +02:00 committed by Tom Hacohen
parent 8abbbd122f
commit 8422892708

View File

@ -45,8 +45,19 @@ class LocalAddressBook(
val accountManager = AccountManager.get(context)
val account = Account(accountName(mainAccount, info), App.addressBookAccountType)
if (!accountManager.addAccountExplicitly(account, null, initialUserData(mainAccount, info.uid!!)))
throw ContactsStorageException("Couldn't create address book account")
val userData = initialUserData(mainAccount, info.uid!!)
Logger.log.log(Level.INFO, "Creating local address book $account", userData)
if (!accountManager.addAccountExplicitly(account, null, userData))
throw IllegalStateException("Couldn't create address book account")
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
// Android < 7 seems to lose the initial user data sometimes, so set it a second time
// https://forums.bitfire.at/post/11644
userData.keySet().forEach { key ->
accountManager.setUserData(account, key, userData.getString(key))
}
}
val addressBook = LocalAddressBook(context, account, provider)
ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true)
@ -119,7 +130,7 @@ class LocalAddressBook(
if (name != null && type != null)
return Account(name, type)
else
throw IllegalStateException("Address book doesn't exist anymore")
throw IllegalStateException("No main account assigned to address book account")
}
}
set(newMainAccount) {