浏览代码

Don't call stopSelf() if the coroutine is cancelled

Peter Cai 1 年之前
父节点
当前提交
4709b6994f
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      app-common/src/main/java/im/angry/openeuicc/service/EuiccChannelManagerService.kt

+ 4 - 1
app-common/src/main/java/im/angry/openeuicc/service/EuiccChannelManagerService.kt

@@ -25,6 +25,7 @@ import kotlinx.coroutines.flow.onCompletion
 import kotlinx.coroutines.flow.onStart
 import kotlinx.coroutines.flow.takeWhile
 import kotlinx.coroutines.flow.transformWhile
+import kotlinx.coroutines.isActive
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.withContext
 import kotlinx.coroutines.withTimeoutOrNull
@@ -205,7 +206,9 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
                 Log.e(TAG, Log.getStackTraceString(t))
                 foregroundTaskState.value = ForegroundTaskState.Done(t)
             } finally {
-                stopSelf()
+                if (isActive) {
+                    stopSelf()
+                }
             }
         }