1
0
mirror of https://github.com/etesync/android synced 2024-12-23 15:18:14 +00:00

Import: check if successfully acquired the provider before trying to import.

This commit is contained in:
Tom Hacohen 2019-07-15 12:55:22 +01:00
parent dbbb6a357c
commit 84ab0cb16f

View File

@ -230,7 +230,12 @@ class ImportFragment : DialogFragment() {
finishParsingFile(events.size) finishParsingFile(events.size)
val provider = context.contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI)!! val provider = context.contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI)
if (provider == null) {
result.e = Exception("Failed to acquire calendar content provider.")
return result
}
val localCalendar: LocalCalendar? val localCalendar: LocalCalendar?
try { try {
localCalendar = LocalCalendar.findByName(account, provider, LocalCalendar.Factory, info.uid!!) localCalendar = LocalCalendar.findByName(account, provider, LocalCalendar.Factory, info.uid!!)
@ -278,7 +283,12 @@ class ImportFragment : DialogFragment() {
finishParsingFile(tasks.size) finishParsingFile(tasks.size)
val provider = TaskProvider.acquire(context, TaskProvider.ProviderName.OpenTasks)!! val provider = TaskProvider.acquire(context, TaskProvider.ProviderName.OpenTasks)
if (provider == null) {
result.e = Exception("Failed to acquire tasks content provider.")
return result
}
val localTaskList: LocalTaskList? val localTaskList: LocalTaskList?
try { try {
localTaskList = LocalTaskList.findByName(account, provider, LocalTaskList.Factory, info.uid!!) localTaskList = LocalTaskList.findByName(account, provider, LocalTaskList.Factory, info.uid!!)
@ -323,7 +333,12 @@ class ImportFragment : DialogFragment() {
finishParsingFile(contacts.size) finishParsingFile(contacts.size)
val provider = context.contentResolver.acquireContentProviderClient(ContactsContract.RawContacts.CONTENT_URI)!! val provider = context.contentResolver.acquireContentProviderClient(ContactsContract.RawContacts.CONTENT_URI)
if (provider == null) {
result.e = Exception("Failed to acquire contacts content provider.")
return result
}
val localAddressBook = LocalAddressBook.findByUid(context, provider, account, info.uid!!) val localAddressBook = LocalAddressBook.findByUid(context, provider, account, info.uid!!)
if (localAddressBook == null) { if (localAddressBook == null) {
throw FileNotFoundException("Failed to load local address book.") throw FileNotFoundException("Failed to load local address book.")