Compare commits
No commits in common. "7197501cca1d283c646afa2c3bb4dd859f9e723f" and "16b6aceedf90fecdca944de85ceafda566eef448" have entirely different histories.
7197501cca
...
16b6aceedf
2 changed files with 12 additions and 20 deletions
|
@ -14,7 +14,6 @@ import im.angry.openeuicc.common.R
|
||||||
import im.angry.openeuicc.core.EuiccChannelManager
|
import im.angry.openeuicc.core.EuiccChannelManager
|
||||||
import im.angry.openeuicc.util.*
|
import im.angry.openeuicc.util.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.NonCancellable
|
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
@ -25,7 +24,6 @@ import kotlinx.coroutines.flow.onCompletion
|
||||||
import kotlinx.coroutines.flow.onStart
|
import kotlinx.coroutines.flow.onStart
|
||||||
import kotlinx.coroutines.flow.takeWhile
|
import kotlinx.coroutines.flow.takeWhile
|
||||||
import kotlinx.coroutines.flow.transformWhile
|
import kotlinx.coroutines.flow.transformWhile
|
||||||
import kotlinx.coroutines.isActive
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.coroutines.withTimeoutOrNull
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
|
@ -196,7 +194,7 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
|
||||||
updateForegroundNotification(title, iconRes)
|
updateForegroundNotification(title, iconRes)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
withContext(Dispatchers.IO + NonCancellable) { // Any LPA-related task must always complete
|
withContext(Dispatchers.IO) {
|
||||||
this@EuiccChannelManagerService.task()
|
this@EuiccChannelManagerService.task()
|
||||||
}
|
}
|
||||||
// This update will be sent by the subscriber (as shown below)
|
// This update will be sent by the subscriber (as shown below)
|
||||||
|
@ -206,11 +204,9 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
|
||||||
Log.e(TAG, Log.getStackTraceString(t))
|
Log.e(TAG, Log.getStackTraceString(t))
|
||||||
foregroundTaskState.value = ForegroundTaskState.Done(t)
|
foregroundTaskState.value = ForegroundTaskState.Done(t)
|
||||||
} finally {
|
} finally {
|
||||||
if (isActive) {
|
|
||||||
stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// We should be the only task running, so we can subscribe to foregroundTaskState
|
// We should be the only task running, so we can subscribe to foregroundTaskState
|
||||||
// until we encounter ForegroundTaskState.Done.
|
// until we encounter ForegroundTaskState.Done.
|
||||||
|
|
|
@ -215,24 +215,20 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
ensureEuiccChannelManager()
|
ensureEuiccChannelManager()
|
||||||
euiccChannelManagerService.waitForForegroundTask()
|
euiccChannelManagerService.waitForForegroundTask()
|
||||||
val res = doDownloadProfile(server, code, confirmationCode, imei)
|
try {
|
||||||
|
doDownloadProfile(server, code, confirmationCode, imei)
|
||||||
if (res == null || res.error != null) {
|
} catch (e: Exception) {
|
||||||
Log.d(TAG, "Error downloading profile")
|
Log.d(TAG, "Error downloading profile")
|
||||||
|
Log.d(TAG, Log.getStackTraceString(e))
|
||||||
if (res?.error != null) {
|
Toast.makeText(context, R.string.profile_download_failed, Toast.LENGTH_LONG).show()
|
||||||
Log.d(TAG, Log.getStackTraceString(res.error))
|
} finally {
|
||||||
}
|
|
||||||
|
|
||||||
Toast.makeText(requireContext(), R.string.profile_download_failed, Toast.LENGTH_LONG).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parentFragment is EuiccProfilesChangedListener) {
|
if (parentFragment is EuiccProfilesChangedListener) {
|
||||||
(parentFragment as EuiccProfilesChangedListener).onEuiccProfilesChanged()
|
(parentFragment as EuiccProfilesChangedListener).onEuiccProfilesChanged()
|
||||||
}
|
}
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun doDownloadProfile(
|
private suspend fun doDownloadProfile(
|
||||||
server: String,
|
server: String,
|
||||||
|
@ -258,7 +254,7 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
|
||||||
}
|
}
|
||||||
}.last()
|
}.last()
|
||||||
|
|
||||||
res as? EuiccChannelManagerService.ForegroundTaskState.Done
|
(res as? EuiccChannelManagerService.ForegroundTaskState.Done)?.error?.let { throw it }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDismiss(dialog: DialogInterface) {
|
override fun onDismiss(dialog: DialogInterface) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue