mirror of
https://github.com/etesync/android
synced 2025-01-23 14:10:54 +00:00
Address books accounts: set initial user data twice for older Android versions
This commit is contained in:
parent
8abbbd122f
commit
8422892708
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user