WIP: feat: filter with enabled profile class #112

Closed
septs wants to merge 4 commits from septs:filter-with-enabled into master
4 changed files with 18 additions and 25 deletions

View file

@ -460,10 +460,7 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
R.drawable.ic_task_switch R.drawable.ic_task_switch
) { ) {
euiccChannelManager.beginTrackedOperation(slotId, portId) { euiccChannelManager.beginTrackedOperation(slotId, portId) {
val (res, refreshed) = euiccChannelManager.withEuiccChannel( val (res, refreshed) = euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
slotId,
portId
) { channel ->
if (!channel.lpa.switchProfile(iccid, enable, refresh = true)) { if (!channel.lpa.switchProfile(iccid, enable, refresh = true)) {
// Sometimes, we *can* enable or disable the profile, but we cannot // Sometimes, we *can* enable or disable the profile, but we cannot
// send the refresh command to the modem because the profile somehow // send the refresh command to the modem because the profile somehow

View file

@ -194,8 +194,11 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener,
euiccChannelManager.notifyEuiccProfilesChanged(channel.logicalSlotId) euiccChannelManager.notifyEuiccProfilesChanged(channel.logicalSlotId)
if (unfilteredProfileListFlow.value) if (unfilteredProfileListFlow.value)
channel.lpa.profiles channel.lpa.profiles
else else {
channel.lpa.profiles.operational val clazz = channel.lpa.profiles.enabled?.profileClass
?: LocalProfileInfo.Clazz.Operational
channel.lpa.profiles.filter { it.profileClass == clazz }
}
} }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
@ -227,11 +230,7 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener,
portId, portId,
iccid, iccid,
enable, enable,
reconnectTimeoutMillis = if (isUsb) { reconnectTimeoutMillis = if (isUsb) 0 else 30_000
0
} else {
30 * 1000
}
).waitDone() ).waitDone()
when (err) { when (err) {

View file

@ -11,14 +11,11 @@ const val TAG = "LPAUtils"
val LocalProfileInfo.displayName: String val LocalProfileInfo.displayName: String
get() = nickName.ifEmpty { name } get() = nickName.ifEmpty { name }
val LocalProfileInfo.isEnabled: Boolean val LocalProfileInfo.isEnabled: Boolean
get() = state == LocalProfileInfo.State.Enabled get() = state == LocalProfileInfo.State.Enabled
val List<LocalProfileInfo>.operational: List<LocalProfileInfo> val List<LocalProfileInfo>.enabled: LocalProfileInfo?
get() = filter { get() = firstOrNull { it.isEnabled }
it.profileClass == LocalProfileInfo.Clazz.Operational
}
val List<EuiccChannel>.hasMultipleChips: Boolean val List<EuiccChannel>.hasMultipleChips: Boolean
get() = distinctBy { it.slotId }.size > 1 get() = distinctBy { it.slotId }.size > 1

View file

@ -186,16 +186,16 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
) )
} }
try { return@withEuiccChannelManager try {
return@withEuiccChannelManager euiccChannelManager.withEuiccChannel( euiccChannelManager.withEuiccChannel(slotId, port) { channel ->
slotId,
port
) { channel ->
val filteredProfiles = val filteredProfiles =
if (runBlocking { preferenceRepository.unfilteredProfileListFlow.first() }) if (preferenceRepository.unfilteredProfileListFlow.first())
channel.lpa.profiles channel.lpa.profiles
else else {
channel.lpa.profiles.operational val clazz = channel.lpa.profiles.enabled?.profileClass
?: LocalProfileInfo.Clazz.Operational
channel.lpa.profiles.filter { it.profileClass == clazz }
}
val profiles = filteredProfiles.map { val profiles = filteredProfiles.map {
EuiccProfileInfo.Builder(it.iccid).apply { EuiccProfileInfo.Builder(it.iccid).apply {
setProfileName(it.name) setProfileName(it.name)
@ -224,7 +224,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
) )
} }
} catch (e: EuiccChannelManager.EuiccChannelNotFoundException) { } catch (e: EuiccChannelManager.EuiccChannelNotFoundException) {
return@withEuiccChannelManager GetEuiccProfileInfoListResult( GetEuiccProfileInfoListResult(
RESULT_FIRST_USER, RESULT_FIRST_USER,
arrayOf(), arrayOf(),
true true