diff --git a/app-common/src/main/java/im/angry/openeuicc/service/EuiccChannelManagerService.kt b/app-common/src/main/java/im/angry/openeuicc/service/EuiccChannelManagerService.kt index c4d16df..d9f051a 100644 --- a/app-common/src/main/java/im/angry/openeuicc/service/EuiccChannelManagerService.kt +++ b/app-common/src/main/java/im/angry/openeuicc/service/EuiccChannelManagerService.kt @@ -460,10 +460,7 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker { R.drawable.ic_task_switch ) { euiccChannelManager.beginTrackedOperation(slotId, portId) { - val (res, refreshed) = euiccChannelManager.withEuiccChannel( - slotId, - portId - ) { channel -> + val (res, refreshed) = euiccChannelManager.withEuiccChannel(slotId, portId) { channel -> if (!channel.lpa.switchProfile(iccid, enable, refresh = true)) { // Sometimes, we *can* enable or disable the profile, but we cannot // send the refresh command to the modem because the profile somehow diff --git a/app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt b/app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt index 8e7b158..819be62 100644 --- a/app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt +++ b/app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt @@ -194,8 +194,11 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener, euiccChannelManager.notifyEuiccProfilesChanged(channel.logicalSlotId) if (unfilteredProfileListFlow.value) channel.lpa.profiles - else - channel.lpa.profiles.operational + else { + val clazz = channel.lpa.profiles.enabled?.profileClass + ?: LocalProfileInfo.Clazz.Operational + channel.lpa.profiles.filter { it.profileClass == clazz } + } } withContext(Dispatchers.Main) { @@ -227,11 +230,7 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener, portId, iccid, enable, - reconnectTimeoutMillis = if (isUsb) { - 0 - } else { - 30 * 1000 - } + reconnectTimeoutMillis = if (isUsb) 0 else 30_000 ).waitDone() when (err) { diff --git a/app-common/src/main/java/im/angry/openeuicc/util/LPAUtils.kt b/app-common/src/main/java/im/angry/openeuicc/util/LPAUtils.kt index 0fe44c1..f868b68 100644 --- a/app-common/src/main/java/im/angry/openeuicc/util/LPAUtils.kt +++ b/app-common/src/main/java/im/angry/openeuicc/util/LPAUtils.kt @@ -11,14 +11,11 @@ const val TAG = "LPAUtils" val LocalProfileInfo.displayName: String get() = nickName.ifEmpty { name } - val LocalProfileInfo.isEnabled: Boolean get() = state == LocalProfileInfo.State.Enabled -val List.operational: List - get() = filter { - it.profileClass == LocalProfileInfo.Clazz.Operational - } +val List.enabled: LocalProfileInfo? + get() = firstOrNull { it.isEnabled } val List.hasMultipleChips: Boolean get() = distinctBy { it.slotId }.size > 1 diff --git a/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt b/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt index 3c522c5..4867da3 100644 --- a/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt +++ b/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt @@ -186,16 +186,16 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker { ) } - try { - return@withEuiccChannelManager euiccChannelManager.withEuiccChannel( - slotId, - port - ) { channel -> + return@withEuiccChannelManager try { + euiccChannelManager.withEuiccChannel(slotId, port) { channel -> val filteredProfiles = - if (runBlocking { preferenceRepository.unfilteredProfileListFlow.first() }) + if (preferenceRepository.unfilteredProfileListFlow.first()) channel.lpa.profiles - else - channel.lpa.profiles.operational + else { + val clazz = channel.lpa.profiles.enabled?.profileClass + ?: LocalProfileInfo.Clazz.Operational + channel.lpa.profiles.filter { it.profileClass == clazz } + } val profiles = filteredProfiles.map { EuiccProfileInfo.Builder(it.iccid).apply { setProfileName(it.name) @@ -224,7 +224,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker { ) } } catch (e: EuiccChannelManager.EuiccChannelNotFoundException) { - return@withEuiccChannelManager GetEuiccProfileInfoListResult( + GetEuiccProfileInfoListResult( RESULT_FIRST_USER, arrayOf(), true