Compare commits
No commits in common. "6a2d4d66dd8547053ae6d9d1624cf460cdaa850c" and "3b868e4f9abeb8e4746f1be83e2a66bfdfd46da0" have entirely different histories.
6a2d4d66dd
...
3b868e4f9a
3 changed files with 39 additions and 71 deletions
|
@ -88,26 +88,23 @@ open class DefaultEuiccChannelManager(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun findEuiccChannelBySlot(logicalSlotId: Int): EuiccChannel? =
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
if (logicalSlotId == EuiccChannelManager.USB_CHANNEL_ID) {
|
|
||||||
return@withContext usbChannel
|
|
||||||
}
|
|
||||||
|
|
||||||
for (card in uiccCards) {
|
|
||||||
for (port in card.ports) {
|
|
||||||
if (port.logicalSlotIndex == logicalSlotId) {
|
|
||||||
return@withContext tryOpenEuiccChannel(port)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun findEuiccChannelBySlotBlocking(logicalSlotId: Int): EuiccChannel? =
|
override fun findEuiccChannelBySlotBlocking(logicalSlotId: Int): EuiccChannel? =
|
||||||
runBlocking {
|
runBlocking {
|
||||||
findEuiccChannelBySlot(logicalSlotId)
|
withContext(Dispatchers.IO) {
|
||||||
|
if (logicalSlotId == EuiccChannelManager.USB_CHANNEL_ID) {
|
||||||
|
return@withContext usbChannel
|
||||||
|
}
|
||||||
|
|
||||||
|
for (card in uiccCards) {
|
||||||
|
for (port in card.ports) {
|
||||||
|
if (port.logicalSlotIndex == logicalSlotId) {
|
||||||
|
return@withContext tryOpenEuiccChannel(port)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun findEuiccChannelByPhysicalSlotBlocking(physicalSlotId: Int): EuiccChannel? =
|
override fun findEuiccChannelByPhysicalSlotBlocking(physicalSlotId: Int): EuiccChannel? =
|
||||||
|
@ -167,23 +164,7 @@ open class DefaultEuiccChannelManager(
|
||||||
portId: Int,
|
portId: Int,
|
||||||
fn: suspend (EuiccChannel) -> R
|
fn: suspend (EuiccChannel) -> R
|
||||||
): R {
|
): R {
|
||||||
val channel = findEuiccChannelByPort(physicalSlotId, portId)
|
val channel = findEuiccChannelByPortBlocking(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,14 +81,6 @@ 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,20 +287,19 @@ 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 res = euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
|
val channel = euiccChannelManager.findEuiccChannelByPort(slotId, portId)
|
||||||
channel.lpa.downloadProfile(
|
val res = channel!!.lpa.downloadProfile(
|
||||||
smdp,
|
smdp,
|
||||||
matchingId,
|
matchingId,
|
||||||
imei,
|
imei,
|
||||||
confirmationCode,
|
confirmationCode,
|
||||||
object : ProfileDownloadCallback {
|
object : ProfileDownloadCallback {
|
||||||
override fun onStateUpdate(state: ProfileDownloadCallback.DownloadState) {
|
override fun onStateUpdate(state: ProfileDownloadCallback.DownloadState) {
|
||||||
if (state.progress == 0) return
|
if (state.progress == 0) return
|
||||||
foregroundTaskState.value =
|
foregroundTaskState.value =
|
||||||
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
|
||||||
|
@ -322,12 +321,10 @@ 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.withEuiccChannel(slotId, portId) { channel ->
|
val res = euiccChannelManager.findEuiccChannelByPort(slotId, portId)!!.lpa.setNickname(
|
||||||
channel.lpa.setNickname(
|
iccid,
|
||||||
iccid,
|
name
|
||||||
name
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
throw RuntimeException("Profile not renamed")
|
throw RuntimeException("Profile not renamed")
|
||||||
|
@ -345,9 +342,10 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
|
||||||
R.drawable.ic_task_delete
|
R.drawable.ic_task_delete
|
||||||
) {
|
) {
|
||||||
euiccChannelManager.beginTrackedOperation(slotId, portId) {
|
euiccChannelManager.beginTrackedOperation(slotId, portId) {
|
||||||
euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
|
euiccChannelManager.findEuiccChannelByPort(
|
||||||
channel.lpa.deleteProfile(iccid)
|
slotId,
|
||||||
}
|
portId
|
||||||
|
)!!.lpa.deleteProfile(iccid)
|
||||||
|
|
||||||
preferenceRepository.notificationDeleteFlow.first()
|
preferenceRepository.notificationDeleteFlow.first()
|
||||||
}
|
}
|
||||||
|
@ -368,10 +366,8 @@ 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 channel = euiccChannelManager.findEuiccChannelByPort(slotId, portId)!!
|
||||||
slotId,
|
val (res, refreshed) =
|
||||||
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
|
||||||
|
@ -382,7 +378,6 @@ 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