From 07b2a54108d3e6bbff6bff7b0f126d231294fd68 Mon Sep 17 00:00:00 2001 From: septs Date: Wed, 18 Dec 2024 12:10:24 +0800 Subject: [PATCH 1/3] refactor: simplify enabled profile --- .../ui/wizard/DownloadWizardSlotSelectFragment.kt | 2 +- .../src/main/java/im/angry/openeuicc/util/LPAUtils.kt | 11 ++++++----- .../im/angry/openeuicc/service/OpenEuiccService.kt | 10 +++------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardSlotSelectFragment.kt b/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardSlotSelectFragment.kt index 3723aea..5510fb0 100644 --- a/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardSlotSelectFragment.kt +++ b/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardSlotSelectFragment.kt @@ -111,7 +111,7 @@ class DownloadWizardSlotSelectFragment : DownloadWizardActivity.DownloadWizardSt } catch (e: Exception) { "" }, - channel.lpa.profiles.find { it.state == LocalProfileInfo.State.Enabled }?.displayName, + channel.lpa.profiles.enabled?.displayName, channel.intrinsicChannelName, ) } 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..9f95412 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 @@ -16,9 +16,10 @@ val LocalProfileInfo.isEnabled: Boolean get() = state == LocalProfileInfo.State.Enabled val List.operational: List - get() = filter { - it.profileClass == LocalProfileInfo.Clazz.Operational - } + get() = filter { it.profileClass == LocalProfileInfo.Clazz.Operational } + +val List.enabled: LocalProfileInfo? + get() = find { it.isEnabled } val List.hasMultipleChips: Boolean get() = distinctBy { it.slotId }.size > 1 @@ -39,7 +40,7 @@ fun LocalProfileAssistant.switchProfile( * See EuiccManager.waitForReconnect() */ fun LocalProfileAssistant.disableActiveProfile(refresh: Boolean): Boolean = - profiles.find { it.isEnabled }?.let { + profiles.enabled?.let { Log.i(TAG, "Disabling active profile ${it.iccid}") disableProfile(it.iccid, refresh) } ?: true @@ -52,7 +53,7 @@ fun LocalProfileAssistant.disableActiveProfile(refresh: Boolean): Boolean = * disable. */ fun LocalProfileAssistant.disableActiveProfileKeepIccId(refresh: Boolean): String? = - profiles.find { it.isEnabled }?.let { + profiles.enabled?.let { Log.i(TAG, "Disabling active profile ${it.iccid}") if (disableProfile(it.iccid, refresh)) { it.iccid 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..302f9cf 100644 --- a/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt +++ b/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt @@ -246,11 +246,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker { // Check that the profile has been disabled on all slots val enabledAnywhere = ports.any { port -> euiccChannelManager.withEuiccChannel(slotId, port) { channel -> - val profile = channel.lpa.profiles.find { - it.iccid == iccid - } ?: return@withEuiccChannel false - - profile.state == LocalProfileInfo.State.Enabled + channel.lpa.profiles.find { it.iccid == iccid }?.isEnabled ?: false } } @@ -354,8 +350,8 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker { // iccid == null means disabling val foundIccid = euiccChannelManager.withEuiccChannel(foundSlotId, foundPortId) { channel -> - channel.lpa.profiles.find { it.state == LocalProfileInfo.State.Enabled } - }?.iccid ?: return@withEuiccChannelManager RESULT_FIRST_USER + channel.lpa.profiles.enabled?.iccid + } ?: return@withEuiccChannelManager RESULT_FIRST_USER Pair(foundIccid, false) } else { Pair(iccid, true) -- 2.45.3 From a6738357c183eecee906bfc06725aba4941c7a0a Mon Sep 17 00:00:00 2001 From: septs Date: Wed, 18 Dec 2024 12:22:09 +0800 Subject: [PATCH 2/3] refactor: simplify --- .../im/angry/openeuicc/service/OpenEuiccService.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) 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 302f9cf..5d89a82 100644 --- a/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt +++ b/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt @@ -186,13 +186,10 @@ 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 @@ -224,7 +221,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker { ) } } catch (e: EuiccChannelManager.EuiccChannelNotFoundException) { - return@withEuiccChannelManager GetEuiccProfileInfoListResult( + GetEuiccProfileInfoListResult( RESULT_FIRST_USER, arrayOf(), true -- 2.45.3 From 78d2c8da82a533d9f075e0dcfadcb380b504fdda Mon Sep 17 00:00:00 2001 From: septs Date: Wed, 18 Dec 2024 21:33:32 +0800 Subject: [PATCH 3/3] refactor --- .../main/java/im/angry/openeuicc/service/OpenEuiccService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5d89a82..02b3baf 100644 --- a/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt +++ b/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt @@ -243,7 +243,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker { // Check that the profile has been disabled on all slots val enabledAnywhere = ports.any { port -> euiccChannelManager.withEuiccChannel(slotId, port) { channel -> - channel.lpa.profiles.find { it.iccid == iccid }?.isEnabled ?: false + channel.lpa.profiles.enabled?.iccid == iccid } } -- 2.45.3