mirror of
https://github.com/home-assistant/android
synced 2024-10-15 12:32:54 +00:00
Fix Thread sync throwing exception sometimes crashing app (#3634)
- Thread credential syncing uses the provided CoroutineScope to run other functions that throw exceptions. When using a normal Job a thrown exception will mean that everything in that scope is cancelled and propagates, even if caught. That isn't wanted so use a SupervisorJob instead when running this function to make sure that when caught nothing else stops.
This commit is contained in:
parent
be022a5272
commit
e53533ed4a
|
@ -10,6 +10,7 @@ import io.homeassistant.companion.android.thread.ThreadManager
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
@ -62,7 +63,7 @@ class DeveloperSettingsPresenterImpl @Inject constructor(
|
||||||
override fun runThreadDebug(context: Context, serverId: Int) {
|
override fun runThreadDebug(context: Context, serverId: Int) {
|
||||||
mainScope.launch {
|
mainScope.launch {
|
||||||
try {
|
try {
|
||||||
when (val syncResult = threadManager.syncPreferredDataset(context, serverId, this)) {
|
when (val syncResult = threadManager.syncPreferredDataset(context, serverId, CoroutineScope(coroutineContext + SupervisorJob()))) {
|
||||||
is ThreadManager.SyncResult.ServerUnsupported ->
|
is ThreadManager.SyncResult.ServerUnsupported ->
|
||||||
view.onThreadDebugResult(context.getString(commonR.string.thread_debug_result_unsupported_server), false)
|
view.onThreadDebugResult(context.getString(commonR.string.thread_debug_result_unsupported_server), false)
|
||||||
is ThreadManager.SyncResult.OnlyOnServer -> {
|
is ThreadManager.SyncResult.OnlyOnServer -> {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import io.homeassistant.companion.android.util.UrlUtil
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
@ -333,7 +334,7 @@ class WebViewPresenterImpl @Inject constructor(
|
||||||
|
|
||||||
mainScope.launch {
|
mainScope.launch {
|
||||||
val deviceThreadIntent = try {
|
val deviceThreadIntent = try {
|
||||||
when (val result = threadUseCase.syncPreferredDataset(context, serverId, this)) {
|
when (val result = threadUseCase.syncPreferredDataset(context, serverId, CoroutineScope(coroutineContext + SupervisorJob()))) {
|
||||||
is ThreadManager.SyncResult.OnlyOnDevice -> result.exportIntent
|
is ThreadManager.SyncResult.OnlyOnDevice -> result.exportIntent
|
||||||
is ThreadManager.SyncResult.AllHaveCredentials -> result.exportIntent
|
is ThreadManager.SyncResult.AllHaveCredentials -> result.exportIntent
|
||||||
else -> null
|
else -> null
|
||||||
|
|
Loading…
Reference in a new issue