Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ class AddressBooksSyncAdapterService : SyncAdapterService() {
val etebaseLocalCache = EtebaseLocalCache.getInstance(context, account.name)
val collections: List<CachedCollection>
synchronized(etebaseLocalCache) {
val httpClient = HttpClient.Builder(context, settings).setForeground(false).build()
val etebase = EtebaseLocalCache.getEtebase(context, httpClient.okHttpClient, settings)
val colMgr = etebase.collectionManager
// Close the client so cert4android's CustomCertManager unbinds its service
// (otherwise the ServiceConnection leaks on every address-book sync).
HttpClient.Builder(context, settings).setForeground(false).build().use { httpClient ->
val etebase = EtebaseLocalCache.getEtebase(context, httpClient.okHttpClient, settings)
val colMgr = etebase.collectionManager

collections = etebaseLocalCache.collectionList(colMgr).filter { it.collectionType == Constants.ETEBASE_TYPE_ADDRESS_BOOK }
collections = etebaseLocalCache.collectionList(colMgr).filter { it.collectionType == Constants.ETEBASE_TYPE_ADDRESS_BOOK }
}
}

for (collection in collections) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ class CalendarsSyncAdapterService : SyncAdapterService() {
val etebaseLocalCache = EtebaseLocalCache.getInstance(context, account.name)
val collections: List<CachedCollection>
synchronized(etebaseLocalCache) {
val httpClient = HttpClient.Builder(context, settings).setForeground(false).build()
val etebase = EtebaseLocalCache.getEtebase(context, httpClient.okHttpClient, settings)
val colMgr = etebase.collectionManager
// Close the client so cert4android's CustomCertManager unbinds its service
// (otherwise the ServiceConnection leaks on every calendar sync).
HttpClient.Builder(context, settings).setForeground(false).build().use { httpClient ->
val etebase = EtebaseLocalCache.getEtebase(context, httpClient.okHttpClient, settings)
val colMgr = etebase.collectionManager

collections = etebaseLocalCache.collectionList(colMgr).filter { it.collectionType == Constants.ETEBASE_TYPE_CALENDAR }
collections = etebaseLocalCache.collectionList(colMgr).filter { it.collectionType == Constants.ETEBASE_TYPE_CALENDAR }
}
}

for (collection in collections) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,20 +313,24 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
return null
}

val resourceClient = HttpClient.Builder(context).setForeground(false).build().okHttpClient
// Close the client so cert4android's CustomCertManager unbinds its service
// (otherwise the ServiceConnection leaks for every external resource fetched).
HttpClient.Builder(context).setForeground(false).build().use { httpClient ->
val resourceClient = httpClient.okHttpClient

try {
val response = resourceClient.newCall(Request.Builder()
.get()
.url(httpUrl)
.build()).execute()

val body = response.body
if (body != null) {
return body.bytes()
try {
val response = resourceClient.newCall(Request.Builder()
.get()
.url(httpUrl)
.build()).execute()

val body = response.body
if (body != null) {
return body.bytes()
}
} catch (e: IOException) {
Logger.log.log(Level.SEVERE, "Couldn't download external resource", e)
}
} catch (e: IOException) {
Logger.log.log(Level.SEVERE, "Couldn't download external resource", e)
}

return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,14 @@ class TasksSyncAdapterService: SyncAdapterService() {
val etebaseLocalCache = EtebaseLocalCache.getInstance(context, account.name)
val collections: List<CachedCollection>
synchronized(etebaseLocalCache) {
val httpClient = HttpClient.Builder(context, settings).setForeground(false).build()
val etebase = EtebaseLocalCache.getEtebase(context, httpClient.okHttpClient, settings)
val colMgr = etebase.collectionManager
// Close the client so cert4android's CustomCertManager unbinds its service
// (otherwise the ServiceConnection leaks on every task-list sync).
HttpClient.Builder(context, settings).setForeground(false).build().use { httpClient ->
val etebase = EtebaseLocalCache.getEtebase(context, httpClient.okHttpClient, settings)
val colMgr = etebase.collectionManager

collections = etebaseLocalCache.collectionList(colMgr).filter { it.collectionType == Constants.ETEBASE_TYPE_TASKS }
collections = etebaseLocalCache.collectionList(colMgr).filter { it.collectionType == Constants.ETEBASE_TYPE_TASKS }
}
}

for (collection in collections) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.etesync.syncadapter.ui.etebase

import android.accounts.Account
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
Expand Down Expand Up @@ -61,6 +62,10 @@ class NewAccountWizardActivity : BaseActivity() {


fun reportErrorHelper(context: Context, e: Throwable) {
// Don't add a dialog window to an activity that is already finishing/destroyed
// (the wizard may navigate away while this coroutine resumes) — it would leak the window.
if (context is Activity && (context.isFinishing || context.isDestroyed))
return
AlertDialog.Builder(context)
.setIcon(R.drawable.ic_info_dark)
.setTitle(R.string.exception)
Expand Down