Compare commits

..

No commits in common. "7197501cca1d283c646afa2c3bb4dd859f9e723f" and "16b6aceedf90fecdca944de85ceafda566eef448" have entirely different histories.

2 changed files with 12 additions and 20 deletions

View file

@ -14,7 +14,6 @@ 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
@ -25,7 +24,6 @@ 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
@ -196,7 +194,7 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
updateForegroundNotification(title, iconRes)
try {
withContext(Dispatchers.IO + NonCancellable) { // Any LPA-related task must always complete
withContext(Dispatchers.IO) {
this@EuiccChannelManagerService.task()
}
// This update will be sent by the subscriber (as shown below)
@ -206,9 +204,7 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
Log.e(TAG, Log.getStackTraceString(t))
foregroundTaskState.value = ForegroundTaskState.Done(t)
} finally {
if (isActive) {
stopSelf()
}
stopSelf()
}
}

View file

@ -215,22 +215,18 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
lifecycleScope.launch {
ensureEuiccChannelManager()
euiccChannelManagerService.waitForForegroundTask()
val res = doDownloadProfile(server, code, confirmationCode, imei)
if (res == null || res.error != null) {
try {
doDownloadProfile(server, code, confirmationCode, imei)
} catch (e: Exception) {
Log.d(TAG, "Error downloading profile")
if (res?.error != null) {
Log.d(TAG, Log.getStackTraceString(res.error))
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()
}
Toast.makeText(requireContext(), R.string.profile_download_failed, Toast.LENGTH_LONG).show()
dismiss()
}
if (parentFragment is EuiccProfilesChangedListener) {
(parentFragment as EuiccProfilesChangedListener).onEuiccProfilesChanged()
}
dismiss()
}
}
@ -258,7 +254,7 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
}
}.last()
res as? EuiccChannelManagerService.ForegroundTaskState.Done
(res as? EuiccChannelManagerService.ForegroundTaskState.Done)?.error?.let { throw it }
}
override fun onDismiss(dialog: DialogInterface) {