From 332caf1631f9863de3129433f4b25feddc55bc89 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 7 Mar 2019 08:09:16 +0000 Subject: [PATCH] View Collection: add checks if we successfully managed to acquire the provider. --- .../syncadapter/ui/ViewCollectionActivity.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/ViewCollectionActivity.kt b/app/src/main/java/com/etesync/syncadapter/ui/ViewCollectionActivity.kt index 165f9203..150b05c8 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/ViewCollectionActivity.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/ViewCollectionActivity.kt @@ -188,8 +188,11 @@ class ViewCollectionActivity : BaseActivity(), Refreshable { CollectionInfo.Type.CALENDAR -> { try { val providerClient = contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI) + if (providerClient == null) { + return null + } val resource = LocalCalendar.findByName(account, providerClient, LocalCalendar.Factory, info.uid!!) - providerClient!!.release() + providerClient.release() if (resource == null) { return null } @@ -203,7 +206,10 @@ class ViewCollectionActivity : BaseActivity(), Refreshable { CollectionInfo.Type.TASKS -> { try { val providerClient = TaskProvider.acquire(this@ViewCollectionActivity, TaskProvider.ProviderName.OpenTasks) - val resource = LocalTaskList.findByName(account, providerClient!!, LocalTaskList.Factory, info.uid!!) + if (providerClient == null) { + return null + } + val resource = LocalTaskList.findByName(account, providerClient, LocalTaskList.Factory, info.uid!!) if (resource == null) { return null } @@ -215,7 +221,10 @@ class ViewCollectionActivity : BaseActivity(), Refreshable { CollectionInfo.Type.ADDRESS_BOOK -> { try { val providerClient = contentResolver.acquireContentProviderClient(ContactsContract.Contacts.CONTENT_URI) - val resource = LocalAddressBook.findByUid(this@ViewCollectionActivity, providerClient!!, account, info.uid!!) + if (providerClient == null) { + return null + } + val resource = LocalAddressBook.findByUid(this@ViewCollectionActivity, providerClient, account, info.uid!!) providerClient.release() if (resource == null) { return null