Compare commits
3 commits
16b6aceedf
...
7197501cca
Author | SHA1 | Date | |
---|---|---|---|
7197501cca | |||
4709b6994f | |||
349c8179b0 |
2 changed files with 20 additions and 12 deletions
|
@ -14,6 +14,7 @@ import im.angry.openeuicc.common.R
|
|||
import im.angry.openeuicc.core.EuiccChannelManager
|
||||
import im.angry.openeuicc.util.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.NonCancellable
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
|
@ -24,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
|
||||
|
@ -194,7 +196,7 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
|
|||
updateForegroundNotification(title, iconRes)
|
||||
|
||||
try {
|
||||
withContext(Dispatchers.IO) {
|
||||
withContext(Dispatchers.IO + NonCancellable) { // Any LPA-related task must always complete
|
||||
this@EuiccChannelManagerService.task()
|
||||
}
|
||||
// This update will be sent by the subscriber (as shown below)
|
||||
|
@ -204,7 +206,9 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
|
|||
Log.e(TAG, Log.getStackTraceString(t))
|
||||
foregroundTaskState.value = ForegroundTaskState.Done(t)
|
||||
} finally {
|
||||
stopSelf()
|
||||
if (isActive) {
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -215,18 +215,22 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
|
|||
lifecycleScope.launch {
|
||||
ensureEuiccChannelManager()
|
||||
euiccChannelManagerService.waitForForegroundTask()
|
||||
try {
|
||||
doDownloadProfile(server, code, confirmationCode, imei)
|
||||
} catch (e: Exception) {
|
||||
val res = doDownloadProfile(server, code, confirmationCode, imei)
|
||||
|
||||
if (res == null || res.error != null) {
|
||||
Log.d(TAG, "Error downloading profile")
|
||||
Log.d(TAG, Log.getStackTraceString(e))
|
||||
Toast.makeText(context, R.string.profile_download_failed, Toast.LENGTH_LONG).show()
|
||||
} finally {
|
||||
if (parentFragment is EuiccProfilesChangedListener) {
|
||||
(parentFragment as EuiccProfilesChangedListener).onEuiccProfilesChanged()
|
||||
|
||||
if (res?.error != null) {
|
||||
Log.d(TAG, Log.getStackTraceString(res.error))
|
||||
}
|
||||
dismiss()
|
||||
|
||||
Toast.makeText(requireContext(), R.string.profile_download_failed, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
if (parentFragment is EuiccProfilesChangedListener) {
|
||||
(parentFragment as EuiccProfilesChangedListener).onEuiccProfilesChanged()
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,7 +258,7 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
|
|||
}
|
||||
}.last()
|
||||
|
||||
(res as? EuiccChannelManagerService.ForegroundTaskState.Done)?.error?.let { throw it }
|
||||
res as? EuiccChannelManagerService.ForegroundTaskState.Done
|
||||
}
|
||||
|
||||
override fun onDismiss(dialog: DialogInterface) {
|
||||
|
|
Loading…
Add table
Reference in a new issue