Browse Source

ui: wizard: Show HTTP exception in diagnostics

Peter Cai 1 year ago
parent
commit
26d037048d

+ 10 - 0
app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardDiagnosticsFragment.kt

@@ -69,6 +69,16 @@ class DownloadWizardDiagnosticsFragment : DownloadWizardActivity.DownloadWizardS
                     str
                     str
                 }
                 }
             )
             )
+
+            ret.appendLine()
+        }
+
+        err.lastHttpException?.let { e ->
+            ret.appendLine(getString(R.string.download_wizard_diagnostics_last_http_exception))
+            ret.appendLine()
+            ret.appendLine("${e.javaClass.name}: ${e.message}")
+            ret.appendLine(e.stackTrace.joinToString("\n"))
+            ret.appendLine()
         }
         }
 
 
         ret.toString()
         ret.toString()

+ 1 - 0
app-common/src/main/res/values/strings.xml

@@ -84,6 +84,7 @@
     <string name="download_wizard_diagnostics">Error diagnostics</string>
     <string name="download_wizard_diagnostics">Error diagnostics</string>
     <string name="download_wizard_diagnostics_last_http_status">Last HTTP status: %d</string>
     <string name="download_wizard_diagnostics_last_http_status">Last HTTP status: %d</string>
     <string name="download_wizard_diagnostics_last_http_response">Last HTTP response:</string>
     <string name="download_wizard_diagnostics_last_http_response">Last HTTP response:</string>
+    <string name="download_wizard_diagnostics_last_http_exception">Last HTTP exception:</string>
 
 
     <string name="profile_rename_new_name">New nickname</string>
     <string name="profile_rename_new_name">New nickname</string>
 
 

+ 5 - 0
libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/HttpInterface.kt

@@ -35,6 +35,11 @@ interface HttpInterface {
      */
      */
     val lastHttpResponse: HttpResponse?
     val lastHttpResponse: HttpResponse?
 
 
+    /**
+     * The last exception that has been thrown during a HTTP connection
+     */
+    val lastHttpException: Exception?
+
     fun transmit(url: String, tx: ByteArray, headers: Array<String>): HttpResponse
     fun transmit(url: String, tx: ByteArray, headers: Array<String>): HttpResponse
     // The LPA is supposed to pass in a list of pkIds supported by the eUICC.
     // The LPA is supposed to pass in a list of pkIds supported by the eUICC.
     // HttpInterface is responsible for providing TrustManager implementations that
     // HttpInterface is responsible for providing TrustManager implementations that

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

@@ -4,7 +4,8 @@ import net.typeblog.lpac_jni.HttpInterface.HttpResponse
 
 
 interface LocalProfileAssistant {
 interface LocalProfileAssistant {
     data class ProfileDownloadException(
     data class ProfileDownloadException(
-        val lastHttpResponse: HttpResponse?
+        val lastHttpResponse: HttpResponse?,
+        val lastHttpException: Exception?,
     ) : Exception("Failed to download profile")
     ) : Exception("Failed to download profile")
 
 
     val valid: Boolean
     val valid: Boolean

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

@@ -24,6 +24,7 @@ class HttpInterfaceImpl(
     private lateinit var trustManagers: Array<TrustManager>
     private lateinit var trustManagers: Array<TrustManager>
 
 
     override var lastHttpResponse: HttpInterface.HttpResponse? = null
     override var lastHttpResponse: HttpInterface.HttpResponse? = null
+    override var lastHttpException: Exception? = null
 
 
     override fun transmit(
     override fun transmit(
         url: String,
         url: String,
@@ -80,6 +81,11 @@ class HttpInterfaceImpl(
             }
             }
         } catch (e: Exception) {
         } catch (e: Exception) {
             e.printStackTrace()
             e.printStackTrace()
+
+            // Reset response to null because there's no response here
+            lastHttpResponse = null
+            lastHttpException = e
+
             throw e
             throw e
         }
         }
     }
     }

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

@@ -155,7 +155,10 @@ class LocalProfileAssistantImpl(
         )
         )
 
 
         if (res != 0) {
         if (res != 0) {
-            throw LocalProfileAssistant.ProfileDownloadException(httpInterface.lastHttpResponse)
+            throw LocalProfileAssistant.ProfileDownloadException(
+                httpInterface.lastHttpResponse,
+                httpInterface.lastHttpException
+            )
         }
         }
     }
     }