Browse Source

Move ProfileDownloadException to LPA

Peter Cai 1 year ago
parent
commit
5476e335b1

+ 1 - 5
app-common/src/main/java/im/angry/openeuicc/core/LocalProfileAssistantWrapper.kt

@@ -1,7 +1,6 @@
 package im.angry.openeuicc.core
 package im.angry.openeuicc.core
 
 
 import net.typeblog.lpac_jni.EuiccInfo2
 import net.typeblog.lpac_jni.EuiccInfo2
-import net.typeblog.lpac_jni.HttpInterface
 import net.typeblog.lpac_jni.LocalProfileAssistant
 import net.typeblog.lpac_jni.LocalProfileAssistant
 import net.typeblog.lpac_jni.LocalProfileInfo
 import net.typeblog.lpac_jni.LocalProfileInfo
 import net.typeblog.lpac_jni.LocalProfileNotification
 import net.typeblog.lpac_jni.LocalProfileNotification
@@ -20,9 +19,6 @@ class LocalProfileAssistantWrapper(orig: LocalProfileAssistant) :
             return _inner!!
             return _inner!!
         }
         }
 
 
-    override val lastHttpResponse: HttpInterface.HttpResponse?
-        get() = lpa.lastHttpResponse
-
     override val valid: Boolean
     override val valid: Boolean
         get() = lpa.valid
         get() = lpa.valid
     override val profiles: List<LocalProfileInfo>
     override val profiles: List<LocalProfileInfo>
@@ -50,7 +46,7 @@ class LocalProfileAssistantWrapper(orig: LocalProfileAssistant) :
         imei: String?,
         imei: String?,
         confirmationCode: String?,
         confirmationCode: String?,
         callback: ProfileDownloadCallback
         callback: ProfileDownloadCallback
-    ): Boolean = lpa.downloadProfile(smdp, matchingId, imei, confirmationCode, callback)
+    ) = lpa.downloadProfile(smdp, matchingId, imei, confirmationCode, callback)
 
 
     override fun deleteNotification(seqNumber: Long): Boolean = lpa.deleteNotification(seqNumber)
     override fun deleteNotification(seqNumber: Long): Boolean = lpa.deleteNotification(seqNumber)
 
 

+ 1 - 12
app-common/src/main/java/im/angry/openeuicc/service/EuiccChannelManagerService.kt

@@ -35,7 +35,6 @@ import kotlinx.coroutines.launch
 import kotlinx.coroutines.withContext
 import kotlinx.coroutines.withContext
 import kotlinx.coroutines.withTimeoutOrNull
 import kotlinx.coroutines.withTimeoutOrNull
 import kotlinx.coroutines.yield
 import kotlinx.coroutines.yield
-import net.typeblog.lpac_jni.HttpInterface
 import net.typeblog.lpac_jni.ProfileDownloadCallback
 import net.typeblog.lpac_jni.ProfileDownloadCallback
 
 
 /**
 /**
@@ -371,10 +370,6 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
             .collect()
             .collect()
     }
     }
 
 
-    data class ProfileDownloadException(
-        val lastHttpResponse: HttpInterface.HttpResponse?
-    ) : Exception("Failed to download profile")
-
     fun launchProfileDownloadTask(
     fun launchProfileDownloadTask(
         slotId: Int,
         slotId: Int,
         portId: Int,
         portId: Int,
@@ -390,7 +385,7 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
         ) {
         ) {
             euiccChannelManager.beginTrackedOperation(slotId, portId) {
             euiccChannelManager.beginTrackedOperation(slotId, portId) {
                 euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
                 euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
-                    val res = channel.lpa.downloadProfile(
+                    channel.lpa.downloadProfile(
                         smdp,
                         smdp,
                         matchingId,
                         matchingId,
                         imei,
                         imei,
@@ -402,12 +397,6 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
                                     ForegroundTaskState.InProgress(state.progress)
                                     ForegroundTaskState.InProgress(state.progress)
                             }
                             }
                         })
                         })
-
-                    if (!res) {
-                        throw ProfileDownloadException(
-                            channel.lpa.lastHttpResponse
-                        )
-                    }
                 }
                 }
 
 
                 preferenceRepository.notificationDownloadFlow.first()
                 preferenceRepository.notificationDownloadFlow.first()

+ 2 - 2
app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardActivity.kt

@@ -11,9 +11,9 @@ import androidx.core.view.WindowInsetsCompat
 import androidx.core.view.updatePadding
 import androidx.core.view.updatePadding
 import androidx.fragment.app.Fragment
 import androidx.fragment.app.Fragment
 import im.angry.openeuicc.common.R
 import im.angry.openeuicc.common.R
-import im.angry.openeuicc.service.EuiccChannelManagerService
 import im.angry.openeuicc.ui.BaseEuiccAccessActivity
 import im.angry.openeuicc.ui.BaseEuiccAccessActivity
 import im.angry.openeuicc.util.*
 import im.angry.openeuicc.util.*
+import net.typeblog.lpac_jni.LocalProfileAssistant
 
 
 class DownloadWizardActivity: BaseEuiccAccessActivity() {
 class DownloadWizardActivity: BaseEuiccAccessActivity() {
     data class DownloadWizardState(
     data class DownloadWizardState(
@@ -25,7 +25,7 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() {
         var imei: String?,
         var imei: String?,
         var downloadStarted: Boolean,
         var downloadStarted: Boolean,
         var downloadTaskID: Long,
         var downloadTaskID: Long,
-        var downloadError: EuiccChannelManagerService.ProfileDownloadException?,
+        var downloadError: LocalProfileAssistant.ProfileDownloadException?,
     )
     )
 
 
     private lateinit var state: DownloadWizardState
     private lateinit var state: DownloadWizardState

+ 2 - 1
app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardProgressFragment.kt

@@ -17,6 +17,7 @@ import im.angry.openeuicc.util.*
 import kotlinx.coroutines.flow.collect
 import kotlinx.coroutines.flow.collect
 import kotlinx.coroutines.flow.onEach
 import kotlinx.coroutines.flow.onEach
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.launch
+import net.typeblog.lpac_jni.LocalProfileAssistant
 import net.typeblog.lpac_jni.ProfileDownloadCallback
 import net.typeblog.lpac_jni.ProfileDownloadCallback
 
 
 class DownloadWizardProgressFragment : DownloadWizardActivity.DownloadWizardStepFragment() {
 class DownloadWizardProgressFragment : DownloadWizardActivity.DownloadWizardStepFragment() {
@@ -122,7 +123,7 @@ class DownloadWizardProgressFragment : DownloadWizardActivity.DownloadWizardStep
                         }
                         }
 
 
                         state.downloadError =
                         state.downloadError =
-                            it.error as? EuiccChannelManagerService.ProfileDownloadException
+                            it.error as? LocalProfileAssistant.ProfileDownloadException
 
 
                         isDone = true
                         isDone = true
                         refreshButtons()
                         refreshButtons()

+ 5 - 2
libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/LocalProfileAssistant.kt

@@ -3,13 +3,16 @@ package net.typeblog.lpac_jni
 import net.typeblog.lpac_jni.HttpInterface.HttpResponse
 import net.typeblog.lpac_jni.HttpInterface.HttpResponse
 
 
 interface LocalProfileAssistant {
 interface LocalProfileAssistant {
+    data class ProfileDownloadException(
+        val lastHttpResponse: HttpResponse?
+    ) : Exception("Failed to download profile")
+
     val valid: Boolean
     val valid: Boolean
     val profiles: List<LocalProfileInfo>
     val profiles: List<LocalProfileInfo>
     val notifications: List<LocalProfileNotification>
     val notifications: List<LocalProfileNotification>
     val eID: String
     val eID: String
     // Extended EuiccInfo for use with LUIs, containing information such as firmware version
     // Extended EuiccInfo for use with LUIs, containing information such as firmware version
     val euiccInfo2: EuiccInfo2?
     val euiccInfo2: EuiccInfo2?
-    val lastHttpResponse: HttpResponse?
 
 
     /**
     /**
      * Set the max segment size (mss) for all es10x commands. This can help with removable
      * Set the max segment size (mss) for all es10x commands. This can help with removable
@@ -25,7 +28,7 @@ interface LocalProfileAssistant {
     fun deleteProfile(iccid: String): Boolean
     fun deleteProfile(iccid: String): Boolean
 
 
     fun downloadProfile(smdp: String, matchingId: String?, imei: String?,
     fun downloadProfile(smdp: String, matchingId: String?, imei: String?,
-                        confirmationCode: String?, callback: ProfileDownloadCallback): Boolean
+                        confirmationCode: String?, callback: ProfileDownloadCallback)
 
 
     fun deleteNotification(seqNumber: Long): Boolean
     fun deleteNotification(seqNumber: Long): Boolean
     fun handleNotification(seqNumber: Long): Boolean
     fun handleNotification(seqNumber: Long): Boolean

+ 7 - 6
libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/impl/LocalProfileAssistantImpl.kt

@@ -34,9 +34,6 @@ class LocalProfileAssistantImpl(
         LpacJni.euiccSetMss(contextHandle, mss)
         LpacJni.euiccSetMss(contextHandle, mss)
     }
     }
 
 
-    override val lastHttpResponse: HttpInterface.HttpResponse?
-        get() = httpInterface.lastHttpResponse
-
     override val valid: Boolean
     override val valid: Boolean
         get() = !finalized && apduInterface.valid && try {
         get() = !finalized && apduInterface.valid && try {
             // If we can read both eID and euiccInfo2 properly, we are likely looking at
             // If we can read both eID and euiccInfo2 properly, we are likely looking at
@@ -147,15 +144,19 @@ class LocalProfileAssistantImpl(
 
 
     @Synchronized
     @Synchronized
     override fun downloadProfile(smdp: String, matchingId: String?, imei: String?,
     override fun downloadProfile(smdp: String, matchingId: String?, imei: String?,
-                                 confirmationCode: String?, callback: ProfileDownloadCallback): Boolean {
-        return LpacJni.downloadProfile(
+                                 confirmationCode: String?, callback: ProfileDownloadCallback) {
+        val res = LpacJni.downloadProfile(
             contextHandle,
             contextHandle,
             smdp,
             smdp,
             matchingId,
             matchingId,
             imei,
             imei,
             confirmationCode,
             confirmationCode,
             callback
             callback
-        ) == 0
+        )
+
+        if (res != 0) {
+            throw LocalProfileAssistant.ProfileDownloadException(httpInterface.lastHttpResponse)
+        }
     }
     }
 
 
     @Synchronized
     @Synchronized