Commit 602e14d2 authored by Ricki Hirner's avatar Ricki Hirner

Really cancel resource detection when dialog is cancelled

parent 7ed27571
Pipeline #27251291 passed with stages
in 6 minutes and 42 seconds
......@@ -27,6 +27,7 @@ import org.apache.commons.lang3.builder.ReflectionToStringBuilder
import org.xbill.DNS.Lookup
import org.xbill.DNS.Type
import java.io.IOException
import java.io.InterruptedIOException
import java.net.URI
import java.net.URISyntaxException
import java.util.*
......@@ -58,12 +59,6 @@ class DavResourceFinder(
.setForeground(true)
.build()
fun cancel() {
log.warning("Shutting down resource detection")
httpClient.okHttpClient.dispatcher().executorService().shutdown()
httpClient.okHttpClient.connectionPool().evictAll()
}
override fun close() {
settings?.close()
httpClient.close()
......@@ -106,6 +101,7 @@ class DavResourceFinder(
config.principal = getCurrentUserPrincipal(baseURL.resolve("/.well-known/" + service.wellKnownName)!!, service)
} catch(e: Exception) {
log.log(Level.FINE, "Well-known URL detection failed", e)
rethrowIfInterrupted(e)
}
}
} else if (baseURI.scheme.equals("mailto", true)) {
......@@ -124,6 +120,7 @@ class DavResourceFinder(
config.principal = discoverPrincipalUrl(it, service)
} catch(e: Exception) {
log.log(Level.FINE, "$service service discovery failed", e)
rethrowIfInterrupted(e)
}
}
......@@ -144,6 +141,7 @@ class DavResourceFinder(
}
} catch(e: Exception) {
log.log(Level.WARNING, "Couldn't query user email address", e)
rethrowIfInterrupted(e)
}
// return config or null if config doesn't contain useful information
......@@ -181,6 +179,7 @@ class DavResourceFinder(
}
} catch(e: Exception) {
log.log(Level.FINE, "PROPFIND/OPTIONS on user-given URL failed", e)
rethrowIfInterrupted(e)
}
}
......@@ -350,6 +349,7 @@ class DavResourceFinder(
principal?.let { return it }
} catch(e: Exception) {
log.log(Level.WARNING, "No resource found", e)
rethrowIfInterrupted(e)
}
return null
}
......@@ -380,6 +380,11 @@ class DavResourceFinder(
return principal
}
private fun rethrowIfInterrupted(e: Exception) {
if (e is InterruptedIOException || e is InterruptedException)
throw e
}
// data classes
......
......@@ -23,7 +23,7 @@ import at.bitfire.davdroid.R
import at.bitfire.davdroid.log.Logger
import at.bitfire.davdroid.ui.DebugInfoActivity
import at.bitfire.davdroid.ui.setup.DavResourceFinder.Configuration
import kotlin.concurrent.thread
import java.lang.ref.WeakReference
@Suppress("DEPRECATION")
class DetectConfigurationFragment: DialogFragment(), LoaderManager.LoaderCallbacks<Configuration> {
......@@ -41,7 +41,7 @@ class DetectConfigurationFragment: DialogFragment(), LoaderManager.LoaderCallbac
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
override fun onCreateDialog(savedInstancebState: Bundle?): Dialog {
val progress = ProgressDialog(activity)
progress.setTitle(R.string.login_configuration_detection)
progress.setMessage(getString(R.string.login_querying_server))
......@@ -122,21 +122,18 @@ class DetectConfigurationFragment: DialogFragment(), LoaderManager.LoaderCallbac
private val credentials: LoginInfo
): AsyncTaskLoader<Configuration>(context) {
private var resourceFinder: DavResourceFinder? = null
private var workingThread: WeakReference<Thread>? = null
override fun onStartLoading() = forceLoad()
override fun cancelLoadInBackground() {
thread {
resourceFinder?.cancel()
resourceFinder = null
}
Logger.log.warning("Shutting down resource detection")
workingThread?.get()?.interrupt()
}
override fun loadInBackground(): Configuration {
val finder = DavResourceFinder(context, credentials)
resourceFinder = finder
return finder.findInitialConfiguration()
workingThread = WeakReference(Thread.currentThread())
return DavResourceFinder(context, credentials).findInitialConfiguration()
}
}
......
......@@ -9,7 +9,6 @@
package at.bitfire.davdroid.ui.setup
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Menu
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment