Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b9863e2e authored by septs's avatar septs Committed by Peter Cai
Browse files

refactor: profile download callback (#284)

parent 56fbd346
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
package im.angry.openeuicc.core

import net.typeblog.lpac_jni.ProfileDownloadInput
import net.typeblog.lpac_jni.EuiccInfo2
import net.typeblog.lpac_jni.LocalProfileAssistant
import net.typeblog.lpac_jni.LocalProfileInfo
@@ -40,13 +41,8 @@ class LocalProfileAssistantWrapper(orig: LocalProfileAssistant) :

    override fun deleteProfile(iccid: String): Boolean = lpa.deleteProfile(iccid)

    override fun downloadProfile(
        smdp: String,
        matchingId: String?,
        imei: String?,
        confirmationCode: String?,
        callback: ProfileDownloadCallback
    ) = lpa.downloadProfile(smdp, matchingId, imei, confirmationCode, callback)
    override fun downloadProfile(input: ProfileDownloadInput, callback: ProfileDownloadCallback) =
        lpa.downloadProfile(input, callback)

    override fun deleteNotification(seqNumber: Long): Boolean = lpa.deleteNotification(seqNumber)

+7 −20
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeoutOrNull
import kotlinx.coroutines.yield
import net.typeblog.lpac_jni.ProfileDownloadCallback
import net.typeblog.lpac_jni.ProfileDownloadInput

/**
 * An Android Service wrapper for EuiccChannelManager.
@@ -379,13 +379,8 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
    }

    fun launchProfileDownloadTask(
        slotId: Int,
        portId: Int,
        seId: EuiccChannel.SecureElementId,
        smdp: String,
        matchingId: String?,
        confirmationCode: String?,
        imei: String?
        slotId: Int, portId: Int, seId: EuiccChannel.SecureElementId,
        input: ProfileDownloadInput
    ): ForegroundTaskSubscriberFlow =
        launchForegroundTask(
            getString(R.string.task_profile_download),
@@ -394,18 +389,10 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
        ) {
            euiccChannelManager.beginTrackedOperation(slotId, portId, seId) {
                euiccChannelManager.withEuiccChannel(slotId, portId, seId) { channel ->
                    channel.lpa.downloadProfile(
                        smdp,
                        matchingId,
                        imei,
                        confirmationCode,
                        object : ProfileDownloadCallback {
                            override fun onStateUpdate(state: ProfileDownloadCallback.DownloadState) {
                                if (state.progress == 0) return
                                foregroundTaskState.value =
                                    ForegroundTaskState.InProgress(state.progress)
                            }
                        })
                    channel.lpa.downloadProfile(input) { state ->
                        if (state.progress == 0) return@downloadProfile
                        foregroundTaskState.value = ForegroundTaskState.InProgress(state.progress)
                    }
                }

                preferenceRepository.notificationDownloadFlow.first()
+10 −14
Original line number Diff line number Diff line
@@ -18,8 +18,9 @@ import im.angry.openeuicc.util.*
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import net.typeblog.lpac_jni.ProfileDownloadInput
import net.typeblog.lpac_jni.ProfileDownloadState
import net.typeblog.lpac_jni.LocalProfileAssistant
import net.typeblog.lpac_jni.ProfileDownloadCallback

class DownloadWizardProgressFragment : DownloadWizardActivity.DownloadWizardStepFragment() {
    companion object {
@@ -27,11 +28,11 @@ class DownloadWizardProgressFragment : DownloadWizardActivity.DownloadWizardStep
         * An array of LPA-side state types, mapping 1:1 to progressItems
         */
        val LPA_PROGRESS_STATES = arrayOf(
            ProfileDownloadCallback.DownloadState.Preparing,
            ProfileDownloadCallback.DownloadState.Connecting,
            ProfileDownloadCallback.DownloadState.Authenticating,
            ProfileDownloadCallback.DownloadState.Downloading,
            ProfileDownloadCallback.DownloadState.Finalizing,
            ProfileDownloadState.Preparing,
            ProfileDownloadState.Connecting,
            ProfileDownloadState.Authenticating,
            ProfileDownloadState.Downloading,
            ProfileDownloadState.Finalizing,
        )
    }

@@ -166,13 +167,8 @@ class DownloadWizardProgressFragment : DownloadWizardActivity.DownloadWizardStep
            state.downloadStarted = true

            val ret = euiccChannelManagerService.launchProfileDownloadTask(
                slotId,
                portId,
                seId,
                state.smdp,
                state.matchingId,
                state.confirmationCode,
                state.imei
                slotId, portId, seId,
                ProfileDownloadInput(state.smdp, state.matchingId, state.imei, state.confirmationCode)
            )

            state.downloadTaskID = ret.taskId
@@ -183,7 +179,7 @@ class DownloadWizardProgressFragment : DownloadWizardActivity.DownloadWizardStep
    private fun updateProgress(progress: Int) {
        showProgressBar(progress)

        val lpaState = ProfileDownloadCallback.lookupStateFromProgress(progress)
        val lpaState = ProfileDownloadState.lookupStateFromProgress(progress)
        val stateIndex = LPA_PROGRESS_STATES.indexOf(lpaState)

        if (stateIndex > 0) {
+1 −4
Original line number Diff line number Diff line
@@ -37,10 +37,7 @@ interface LocalProfileAssistant {
    fun disableProfile(iccid: String, refresh: Boolean = true): Boolean
    fun deleteProfile(iccid: String): Boolean

    fun downloadProfile(
        smdp: String, matchingId: String?, imei: String?,
        confirmationCode: String?, callback: ProfileDownloadCallback
    )
    fun downloadProfile(input: ProfileDownloadInput, callback: ProfileDownloadCallback)

    fun deleteNotification(seqNumber: Long): Boolean
    fun handleNotification(seqNumber: Long): Boolean
+2 −2
Original line number Diff line number Diff line
@@ -31,9 +31,9 @@ internal object LpacJni {
    external fun es10bDeleteNotification(handle: Long, seqNumber: Long): Int

    // es9p + es10b
    // We do not expose all of the functions because of tediousness :)
    // We do not expose all the functions because of tediousness :)
    external fun downloadProfile(
        handle: Long, smdp: String, matchingId: String?, imei: String?,
        handle: Long, address: String, matchingId: String?, imei: String?,
        confirmationCode: String?, callback: ProfileDownloadCallback
    ): Int

Loading