Compare commits

..

No commits in common. "6a2d4d66dd8547053ae6d9d1624cf460cdaa850c" and "3b868e4f9abeb8e4746f1be83e2a66bfdfd46da0" have entirely different histories.

3 changed files with 39 additions and 71 deletions

View file

@ -88,7 +88,8 @@ open class DefaultEuiccChannelManager(
}
}
private suspend fun findEuiccChannelBySlot(logicalSlotId: Int): EuiccChannel? =
override fun findEuiccChannelBySlotBlocking(logicalSlotId: Int): EuiccChannel? =
runBlocking {
withContext(Dispatchers.IO) {
if (logicalSlotId == EuiccChannelManager.USB_CHANNEL_ID) {
return@withContext usbChannel
@ -104,10 +105,6 @@ open class DefaultEuiccChannelManager(
null
}
override fun findEuiccChannelBySlotBlocking(logicalSlotId: Int): EuiccChannel? =
runBlocking {
findEuiccChannelBySlot(logicalSlotId)
}
override fun findEuiccChannelByPhysicalSlotBlocking(physicalSlotId: Int): EuiccChannel? =
@ -167,23 +164,7 @@ open class DefaultEuiccChannelManager(
portId: Int,
fn: suspend (EuiccChannel) -> R
): R {
val channel = findEuiccChannelByPort(physicalSlotId, portId)
?: throw EuiccChannelManager.EuiccChannelNotFoundException()
val wrapper = EuiccChannelWrapper(channel)
try {
return withContext(Dispatchers.IO) {
fn(wrapper)
}
} finally {
wrapper.invalidateWrapper()
}
}
override suspend fun <R> withEuiccChannel(
logicalSlotId: Int,
fn: suspend (EuiccChannel) -> R
): R {
val channel = findEuiccChannelBySlot(logicalSlotId)
val channel = findEuiccChannelByPortBlocking(physicalSlotId, portId)
?: throw EuiccChannelManager.EuiccChannelNotFoundException()
val wrapper = EuiccChannelWrapper(channel)
try {

View file

@ -81,14 +81,6 @@ interface EuiccChannelManager {
fn: suspend (EuiccChannel) -> R
): R
/**
* Same as withEuiccChannel(Int, Int, (EuiccChannel) -> R) but instead uses logical slot ID
*/
suspend fun <R> withEuiccChannel(
logicalSlotId: Int,
fn: suspend (EuiccChannel) -> R
): R
/**
* Invalidate all EuiccChannels previously cached by this Manager
*/

View file

@ -287,8 +287,8 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
R.drawable.ic_task_sim_card_download
) {
euiccChannelManager.beginTrackedOperation(slotId, portId) {
val res = euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
channel.lpa.downloadProfile(
val channel = euiccChannelManager.findEuiccChannelByPort(slotId, portId)
val res = channel!!.lpa.downloadProfile(
smdp,
matchingId,
imei,
@ -300,7 +300,6 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
ForegroundTaskState.InProgress(state.progress)
}
})
}
if (!res) {
// TODO: Provide more details on the error
@ -322,12 +321,10 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
getString(R.string.task_profile_rename_failure),
R.drawable.ic_task_rename
) {
val res = euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
channel.lpa.setNickname(
val res = euiccChannelManager.findEuiccChannelByPort(slotId, portId)!!.lpa.setNickname(
iccid,
name
)
}
if (!res) {
throw RuntimeException("Profile not renamed")
@ -345,9 +342,10 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
R.drawable.ic_task_delete
) {
euiccChannelManager.beginTrackedOperation(slotId, portId) {
euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
channel.lpa.deleteProfile(iccid)
}
euiccChannelManager.findEuiccChannelByPort(
slotId,
portId
)!!.lpa.deleteProfile(iccid)
preferenceRepository.notificationDeleteFlow.first()
}
@ -368,10 +366,8 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
R.drawable.ic_task_switch
) {
euiccChannelManager.beginTrackedOperation(slotId, portId) {
val (res, refreshed) = euiccChannelManager.withEuiccChannel(
slotId,
portId
) { channel ->
val channel = euiccChannelManager.findEuiccChannelByPort(slotId, portId)!!
val (res, refreshed) =
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
@ -382,7 +378,6 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
} else {
Pair(true, true)
}
}
if (!res) {
throw RuntimeException("Could not switch profile")