Skip to content
Snippets Groups Projects
Verified Commit c134cf46 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Fixes #65

parent eb442ef8
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -35,26 +35,33 @@ class BackendServiceConnection : ServiceConnection {
var context: Context? = null
private var bound: Boolean = false
enum class State {
UNBOUND,
BINDING,
BOUND,
UNBINDING
}
private var state: State = State.UNBOUND
override fun onServiceDisconnected(component: ComponentName?) {
when (component) {
ComponentName(context, QuasselService::class.java) -> {
bound = false
synchronized(this@BackendServiceConnection) {
state = State.UNBOUND
backend.onNext(Optional.empty())
}
}
}
override fun onServiceConnected(component: ComponentName?, binder: IBinder?) {
when (component) {
ComponentName(context, QuasselService::class.java) ->
if (binder is QuasselBinder) {
bound = true
synchronized(this@BackendServiceConnection) {
state = State.BOUND
backend.onNext(Optional.of(binder.backend))
}
}
}
}
fun start(intent: Intent = QuasselService.intent(context!!)) {
context?.startService(intent)
......@@ -62,8 +69,11 @@ class BackendServiceConnection : ServiceConnection {
@Synchronized
fun bind(intent: Intent = QuasselService.intent(context!!), flags: Int = 0) {
if (state == State.UNBOUND || state == State.UNBINDING) {
state = State.BINDING
context?.bindService(intent, this, flags)
}
}
fun stop(intent: Intent = QuasselService.intent(context!!)) {
context?.stopService(intent)
......@@ -71,6 +81,9 @@ class BackendServiceConnection : ServiceConnection {
@Synchronized
fun unbind() {
if (bound) context?.unbindService(this)
if (state == State.BOUND || state == State.BINDING) {
state = State.UNBINDING
context?.unbindService(this)
}
}
}
......@@ -20,6 +20,7 @@
package de.kuschku.malheur
import android.app.Application
import android.os.Build
import android.os.Handler
import android.os.HandlerThread
import android.util.Log
......@@ -85,11 +86,16 @@ object CrashHandler {
}
} catch (e: Throwable) {
e.printStackTrace()
originalHandler?.uncaughtException(activeThread, throwable)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
throwable.addSuppressed(e)
}
}
}.start()
}
Thread.setDefaultUncaughtExceptionHandler(myHandler)
Thread.setDefaultUncaughtExceptionHandler { currentThread, throwable ->
myHandler?.uncaughtException(currentThread, throwable)
originalHandler?.uncaughtException(currentThread, throwable)
}
}
fun handle(throwable: Throwable) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment