diff --git a/app-common/src/main/java/im/angry/openeuicc/core/EuiccChannelManager.kt b/app-common/src/main/java/im/angry/openeuicc/core/EuiccChannelManager.kt index 59c3aa9..0657c98 100644 --- a/app-common/src/main/java/im/angry/openeuicc/core/EuiccChannelManager.kt +++ b/app-common/src/main/java/im/angry/openeuicc/core/EuiccChannelManager.kt @@ -135,16 +135,6 @@ open class EuiccChannelManager(protected val context: Context) { } } - fun findAllEuiccChannelsByPhysicalSlotBlocking(physicalSlotId: Int): List? = runBlocking { - if (!checkPrivileges()) return@runBlocking null - for (card in tm.uiccCardsInfoCompat) { - if (card.physicalSlotIndex != physicalSlotId) continue - return@runBlocking card.ports.mapNotNull { tryOpenEuiccChannel(it) } - .ifEmpty { null } - } - return@runBlocking null - } - fun findEuiccChannelByPortBlocking(physicalSlotId: Int, portId: Int): EuiccChannel? = runBlocking { if (!checkPrivileges()) return@runBlocking null withContext(Dispatchers.IO) { 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 cba4bc8..d98fca8 100644 --- a/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt +++ b/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt @@ -27,10 +27,6 @@ class OpenEuiccService : EuiccService() { openEuiccApplication.euiccChannelManager .findEuiccChannelByPortBlocking(slotId, portId) - private fun findAllChannels(physicalSlotId: Int): List? = - openEuiccApplication.euiccChannelManager - .findAllEuiccChannelsByPhysicalSlotBlocking(physicalSlotId) - override fun onGetEid(slotId: Int): String? = findChannel(slotId)?.lpa?.eID @@ -145,25 +141,23 @@ class OpenEuiccService : EuiccService() { override fun onDeleteSubscription(slotId: Int, iccid: String): Int { Log.i(TAG, "onDeleteSubscription slotId=$slotId iccid=$iccid") try { - val channels = findAllChannels(slotId) ?: return RESULT_FIRST_USER + val channel = findChannel(slotId) ?: return RESULT_FIRST_USER - if (!channels[0].profileExists(iccid)) { + if (!channel.profileExists(iccid)) { return RESULT_FIRST_USER } - // If the profile is enabled by ANY channel (port), we cannot delete it - channels.forEach { channel -> - val profile = channel.lpa.profiles.find { - it.iccid == iccid - } ?: return RESULT_FIRST_USER + val profile = channel.lpa.profiles.find { + it.iccid == iccid + } ?: return RESULT_FIRST_USER - if (profile.state == LocalProfileInfo.State.Enabled) { - // Must disable the profile first - return RESULT_FIRST_USER - } + if (profile.state == LocalProfileInfo.State.Enabled) { + // Must disable the profile first + // TODO: Need to check "other port" as well for MEP + return RESULT_FIRST_USER } - return if (channels[0].lpa.deleteProfile(iccid)) { + return if (channel.lpa.deleteProfile(iccid)) { RESULT_OK } else { RESULT_FIRST_USER diff --git a/app/src/main/java/im/angry/openeuicc/ui/SlotMappingFragment.kt b/app/src/main/java/im/angry/openeuicc/ui/SlotMappingFragment.kt index 57d39c7..2816153 100644 --- a/app/src/main/java/im/angry/openeuicc/ui/SlotMappingFragment.kt +++ b/app/src/main/java/im/angry/openeuicc/ui/SlotMappingFragment.kt @@ -98,9 +98,7 @@ class SlotMappingFragment: DialogFragment(), OnMenuItemClickListener { lifecycleScope.launch(Dispatchers.Main) { try { withContext(Dispatchers.IO) { - // Use the utility method from PrivilegedTelephonyUtils to ensure - // unmapped ports have all profiles disabled - tm.updateSimSlotMapping(openEuiccApplication.euiccChannelManager, adapter.mappings) + tm.simSlotMapping = adapter.mappings } } catch (e: Exception) { Toast.makeText(requireContext(), R.string.slot_mapping_failure, Toast.LENGTH_LONG).show() diff --git a/app/src/main/java/im/angry/openeuicc/util/PrivilegedTelephonyUtils.kt b/app/src/main/java/im/angry/openeuicc/util/PrivilegedTelephonyUtils.kt index a875d8a..28b9623 100644 --- a/app/src/main/java/im/angry/openeuicc/util/PrivilegedTelephonyUtils.kt +++ b/app/src/main/java/im/angry/openeuicc/util/PrivilegedTelephonyUtils.kt @@ -2,9 +2,6 @@ package im.angry.openeuicc.util import android.telephony.SubscriptionManager import android.telephony.TelephonyManager -import android.telephony.UiccSlotMapping -import im.angry.openeuicc.core.EuiccChannelManager -import net.typeblog.lpac_jni.LocalProfileInfo import java.lang.Exception val TelephonyManager.supportsDSDS: Boolean @@ -16,34 +13,6 @@ var TelephonyManager.dsdsEnabled: Boolean switchMultiSimConfig(if (value) { 2 } else {1}) } -// Disable eSIM profiles before switching the slot mapping -// This ensures that unmapped eSIM ports never have "ghost" profiles enabled -fun TelephonyManager.updateSimSlotMapping(euiccManager: EuiccChannelManager, newMapping: Collection) { - val unmapped = simSlotMapping.filterNot { mapping -> - // If the same physical slot + port pair is not found in the new mapping, it is unmapped - newMapping.any { - it.physicalSlotIndex == mapping.physicalSlotIndex && it.portIndex == mapping.portIndex - } - } - - val undo = unmapped.mapNotNull { mapping -> - euiccManager.findEuiccChannelByPortBlocking(mapping.physicalSlotIndex, mapping.portIndex)?.let { channel -> - channel.lpa.profiles.find { it.state == LocalProfileInfo.State.Enabled }?.let { profile -> - channel.lpa.disableProfile(profile.iccid) - return@mapNotNull { channel.lpa.enableProfile(profile.iccid) } - } - } - } - - try { - simSlotMapping = newMapping - } catch (e: Exception) { - e.printStackTrace() - undo.forEach { it() } // Undo what we just did - throw e // Rethrow for caller to handle - } -} - fun SubscriptionManager.tryRefreshCachedEuiccInfo(cardId: Int) { if (cardId != 0) { try {