From 84ab0cb16fb5178f9365fe8cb969f2035d8fd684 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 15 Jul 2019 12:55:22 +0100 Subject: [PATCH] Import: check if successfully acquired the provider before trying to import. --- .../ui/importlocal/ImportFragment.kt | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.kt b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.kt index c5b531cc..bd40601d 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.kt @@ -230,7 +230,12 @@ class ImportFragment : DialogFragment() { 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? try { localCalendar = LocalCalendar.findByName(account, provider, LocalCalendar.Factory, info.uid!!) @@ -278,7 +283,12 @@ class ImportFragment : DialogFragment() { 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? try { localTaskList = LocalTaskList.findByName(account, provider, LocalTaskList.Factory, info.uid!!) @@ -323,7 +333,12 @@ class ImportFragment : DialogFragment() { 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!!) if (localAddressBook == null) { throw FileNotFoundException("Failed to load local address book.")