Compare commits
3 commits
3b868e4f9a
...
6a2d4d66dd
Author | SHA1 | Date | |
---|---|---|---|
6a2d4d66dd | |||
8ac46bd778 | |||
0961ef70f4 |
3 changed files with 69 additions and 37 deletions
|
@ -88,8 +88,7 @@ open class DefaultEuiccChannelManager(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun findEuiccChannelBySlotBlocking(logicalSlotId: Int): EuiccChannel? =
|
private suspend fun findEuiccChannelBySlot(logicalSlotId: Int): EuiccChannel? =
|
||||||
runBlocking {
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
if (logicalSlotId == EuiccChannelManager.USB_CHANNEL_ID) {
|
if (logicalSlotId == EuiccChannelManager.USB_CHANNEL_ID) {
|
||||||
return@withContext usbChannel
|
return@withContext usbChannel
|
||||||
|
@ -105,6 +104,10 @@ open class DefaultEuiccChannelManager(
|
||||||
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun findEuiccChannelBySlotBlocking(logicalSlotId: Int): EuiccChannel? =
|
||||||
|
runBlocking {
|
||||||
|
findEuiccChannelBySlot(logicalSlotId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun findEuiccChannelByPhysicalSlotBlocking(physicalSlotId: Int): EuiccChannel? =
|
override fun findEuiccChannelByPhysicalSlotBlocking(physicalSlotId: Int): EuiccChannel? =
|
||||||
|
@ -164,7 +167,23 @@ open class DefaultEuiccChannelManager(
|
||||||
portId: Int,
|
portId: Int,
|
||||||
fn: suspend (EuiccChannel) -> R
|
fn: suspend (EuiccChannel) -> R
|
||||||
): R {
|
): R {
|
||||||
val channel = findEuiccChannelByPortBlocking(physicalSlotId, portId)
|
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)
|
||||||
?: throw EuiccChannelManager.EuiccChannelNotFoundException()
|
?: throw EuiccChannelManager.EuiccChannelNotFoundException()
|
||||||
val wrapper = EuiccChannelWrapper(channel)
|
val wrapper = EuiccChannelWrapper(channel)
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -81,6 +81,14 @@ interface EuiccChannelManager {
|
||||||
fn: suspend (EuiccChannel) -> R
|
fn: suspend (EuiccChannel) -> R
|
||||||
): 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
|
* Invalidate all EuiccChannels previously cached by this Manager
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -287,8 +287,8 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
|
||||||
R.drawable.ic_task_sim_card_download
|
R.drawable.ic_task_sim_card_download
|
||||||
) {
|
) {
|
||||||
euiccChannelManager.beginTrackedOperation(slotId, portId) {
|
euiccChannelManager.beginTrackedOperation(slotId, portId) {
|
||||||
val channel = euiccChannelManager.findEuiccChannelByPort(slotId, portId)
|
val res = euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
|
||||||
val res = channel!!.lpa.downloadProfile(
|
channel.lpa.downloadProfile(
|
||||||
smdp,
|
smdp,
|
||||||
matchingId,
|
matchingId,
|
||||||
imei,
|
imei,
|
||||||
|
@ -300,6 +300,7 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
|
||||||
ForegroundTaskState.InProgress(state.progress)
|
ForegroundTaskState.InProgress(state.progress)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
// TODO: Provide more details on the error
|
// TODO: Provide more details on the error
|
||||||
|
@ -321,10 +322,12 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
|
||||||
getString(R.string.task_profile_rename_failure),
|
getString(R.string.task_profile_rename_failure),
|
||||||
R.drawable.ic_task_rename
|
R.drawable.ic_task_rename
|
||||||
) {
|
) {
|
||||||
val res = euiccChannelManager.findEuiccChannelByPort(slotId, portId)!!.lpa.setNickname(
|
val res = euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
|
||||||
|
channel.lpa.setNickname(
|
||||||
iccid,
|
iccid,
|
||||||
name
|
name
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
throw RuntimeException("Profile not renamed")
|
throw RuntimeException("Profile not renamed")
|
||||||
|
@ -342,10 +345,9 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
|
||||||
R.drawable.ic_task_delete
|
R.drawable.ic_task_delete
|
||||||
) {
|
) {
|
||||||
euiccChannelManager.beginTrackedOperation(slotId, portId) {
|
euiccChannelManager.beginTrackedOperation(slotId, portId) {
|
||||||
euiccChannelManager.findEuiccChannelByPort(
|
euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
|
||||||
slotId,
|
channel.lpa.deleteProfile(iccid)
|
||||||
portId
|
}
|
||||||
)!!.lpa.deleteProfile(iccid)
|
|
||||||
|
|
||||||
preferenceRepository.notificationDeleteFlow.first()
|
preferenceRepository.notificationDeleteFlow.first()
|
||||||
}
|
}
|
||||||
|
@ -366,8 +368,10 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
|
||||||
R.drawable.ic_task_switch
|
R.drawable.ic_task_switch
|
||||||
) {
|
) {
|
||||||
euiccChannelManager.beginTrackedOperation(slotId, portId) {
|
euiccChannelManager.beginTrackedOperation(slotId, portId) {
|
||||||
val channel = euiccChannelManager.findEuiccChannelByPort(slotId, portId)!!
|
val (res, refreshed) = euiccChannelManager.withEuiccChannel(
|
||||||
val (res, refreshed) =
|
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
|
||||||
|
@ -378,6 +382,7 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
|
||||||
} else {
|
} else {
|
||||||
Pair(true, true)
|
Pair(true, true)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
throw RuntimeException("Could not switch profile")
|
throw RuntimeException("Could not switch profile")
|
||||||
|
|
Loading…
Add table
Reference in a new issue