Modern Apps git

← Modern-Apps.git

euicc: detekt clean (105 tests)

Commit
1b208a5f0731abf79fb9cda6d885cc2862a954f9
Author
Vayun Mathur <[email protected]>
When
2026-11-14 23:15 UTC (21 days ago)
Parents
f6c89b5
Fix all 7 detekt findings: real KDoc for Route, EuiccViewModel, DownloadService companion and EuiccChannelManager companion; split FakeEuicc.respond (CyclomaticComplexMethod 19) into bppSegmentResponse/profileBodyFor/simpleBodyFor; FunctionOnlyReturningConstant successHeader()/failedStatus() in FakeSmdp converted to val properties.

Verified: ./gradlew :euicc:detekt :euicc:testDevUnitTest :euicc:lint --max-workers=32 — BUILD SUCCESSFUL, 105 unit tests pass. No @Suppress added.

Diff

euicc/src/main/java/com/vayunmathur/euicc/Route.kt
diff --git a/euicc/src/main/java/com/vayunmathur/euicc/Route.kt b/euicc/src/main/java/com/vayunmathur/euicc/Route.ktindex 59bf4c16f1..30f5a0309c 100644--- a/euicc/src/main/java/com/vayunmathur/euicc/Route.kt+++ b/euicc/src/main/java/com/vayunmathur/euicc/Route.kt@@ -3,6 +3,7 @@ package com.vayunmathur.euicc import com.vayunmathur.library.util.NavKey import kotlinx.serialization.Serializable +/** Navigation destinations for the eSIM manager (LPA) flow, from the profile list into a download. */ @Serializable sealed interface Route : NavKey {     /** The profile list - the LUI's landing screen. */
euicc/src/main/java/com/vayunmathur/euicc/platform/EuiccViewModel.kt
diff --git a/euicc/src/main/java/com/vayunmathur/euicc/platform/EuiccViewModel.kt b/euicc/src/main/java/com/vayunmathur/euicc/platform/EuiccViewModel.ktindex ae7c92c3c6..be4ba4901a 100644--- a/euicc/src/main/java/com/vayunmathur/euicc/platform/EuiccViewModel.kt+++ b/euicc/src/main/java/com/vayunmathur/euicc/platform/EuiccViewModel.kt@@ -75,6 +75,10 @@ private fun isConfirmationCodeRefusal(message: String?): Boolean =             "Confirmation Code is missing" in message         ) +/**+ * Drives the LPA screens: mirrors eUICC profiles and notifications into [state] and runs the+ * split-phase SM-DP+ download (authenticate, confirm, install) tracked separately in [download].+ */ class EuiccViewModel(app: Application) : AndroidViewModel(app) {     private val channelManager = EuiccChannelManager(app)     private val json = Json { ignoreUnknownKeys = true }
euicc/src/main/java/com/vayunmathur/euicc/service/DownloadService.kt
diff --git a/euicc/src/main/java/com/vayunmathur/euicc/service/DownloadService.kt b/euicc/src/main/java/com/vayunmathur/euicc/service/DownloadService.ktindex e5d6c6aa96..04757119f6 100644--- a/euicc/src/main/java/com/vayunmathur/euicc/service/DownloadService.kt+++ b/euicc/src/main/java/com/vayunmathur/euicc/service/DownloadService.kt@@ -86,6 +86,7 @@ class DownloadService : Service() {         }     } +    /** Notification and wake-lock constants plus the start/stop entry points for the install guard. */     companion object {         private const val CHANNEL_ID = "esim_install"         private const val FOREGROUND_ID = 1001
euicc/src/main/java/com/vayunmathur/euicc/telephony/EuiccChannelManager.kt
diff --git a/euicc/src/main/java/com/vayunmathur/euicc/telephony/EuiccChannelManager.kt b/euicc/src/main/java/com/vayunmathur/euicc/telephony/EuiccChannelManager.ktindex 36f83e302f..8758b160ab 100644--- a/euicc/src/main/java/com/vayunmathur/euicc/telephony/EuiccChannelManager.kt+++ b/euicc/src/main/java/com/vayunmathur/euicc/telephony/EuiccChannelManager.kt@@ -196,6 +196,7 @@ class EuiccChannelManager(context: Context) {         throw EuiccException("${method.name} is not accessible: $e")     } +    /** APDU framing constants, the process-wide ISD-R lock, and the reflective `@SystemApi` telephony methods. */     companion object {         /** Process-wide ISD-R session lock; see [withIsdrChannel]. */         private val CHANNEL_LOCK = Any()
euicc/src/test/java/com/vayunmathur/euicc/FakeSmdp.kt
diff --git a/euicc/src/test/java/com/vayunmathur/euicc/FakeSmdp.kt b/euicc/src/test/java/com/vayunmathur/euicc/FakeSmdp.ktindex 1f61997b8f..4162378e3e 100644--- a/euicc/src/test/java/com/vayunmathur/euicc/FakeSmdp.kt+++ b/euicc/src/test/java/com/vayunmathur/euicc/FakeSmdp.kt@@ -68,6 +68,12 @@ class FakeEuicc {     }      private fun respond(dataHex: String): String {+        bppSegmentResponse(dataHex)?.let { return it }+        return bodyFor(dataHex).toHex() + "9000"+    }++    /** Response for a Bound Profile Package segment, or null when [dataHex] is not one. */+    private fun bppSegmentResponse(dataHex: String): String? {         when {             dataHex.startsWith("BF36") -> {                 // Our BPP segments into 6 STORE DATA calls; this is the first.@@ -82,28 +88,38 @@ class FakeEuicc {                 }                 return "9000"             }+            else -> return null         }-        val body: ByteArray = when {-            dataHex.startsWith("BF2E") ->-                tlv2(0xBF, 0x2E, tlv1(0x80, ByteArray(16) { (it + 1).toByte() }))-            dataHex.startsWith("BF20") -> info1()-            dataHex.startsWith("BF3E") ->-                tlv2(0xBF, 0x3E, tlv1(0x5A, hexBytes("89044022444301000000000000012345".take(32))))-            dataHex.startsWith("BF2D") ->-                tlv2(0xBF, 0x2D, tlv1(0xA0, cat(*profileSet.toTypedArray())))-            dataHex.startsWith("BF28") -> notifications()-            dataHex.startsWith("BF30") -> tlv2(0xBF, 0x30, tlv1(0x80, byteArrayOf(0)))-            dataHex.startsWith("BF31") -> tlv2(0xBF, 0x31, tlv1(0x80, byteArrayOf(0)))-            dataHex.startsWith("BF32") -> tlv2(0xBF, 0x32, tlv1(0x80, byteArrayOf(0)))-            dataHex.startsWith("BF33") -> tlv2(0xBF, 0x33, tlv1(0x80, byteArrayOf(0)))-            dataHex.startsWith("BF29") -> tlv2(0xBF, 0x29, tlv1(0x80, byteArrayOf(0)))-            dataHex.startsWith("BF38") -> tlv2(0xBF, 0x38, ByteArray(0))-            dataHex.startsWith("BF21") -> tlv2(0xBF, 0x21, ByteArray(0))-            dataHex.startsWith("BF41") -> tlv2(0xBF, 0x41, ByteArray(0))-            dataHex.startsWith("BF2B") -> tlv2(0xBF, 0x2B, ByteArray(0))-            else -> ByteArray(0)-        }-        return body.toHex() + "9000"+    }++    private fun bodyFor(dataHex: String): ByteArray =+        profileBodyFor(dataHex) ?: simpleBodyFor(dataHex) ?: ByteArray(0)++    /** Bodies for the ES10 reads that carry profile, info, or notification data. */+    private fun profileBodyFor(dataHex: String): ByteArray? = when {+        dataHex.startsWith("BF2E") ->+            tlv2(0xBF, 0x2E, tlv1(0x80, ByteArray(16) { (it + 1).toByte() }))+        dataHex.startsWith("BF20") -> info1()+        dataHex.startsWith("BF3E") ->+            tlv2(0xBF, 0x3E, tlv1(0x5A, hexBytes("89044022444301000000000000012345".take(32))))+        dataHex.startsWith("BF2D") ->+            tlv2(0xBF, 0x2D, tlv1(0xA0, cat(*profileSet.toTypedArray())))+        dataHex.startsWith("BF28") -> notifications()+        else -> null+    }++    /** Bodies for the remaining ES10 operations: a success word or an empty payload. */+    private fun simpleBodyFor(dataHex: String): ByteArray? = when {+        dataHex.startsWith("BF30") -> tlv2(0xBF, 0x30, tlv1(0x80, byteArrayOf(0)))+        dataHex.startsWith("BF31") -> tlv2(0xBF, 0x31, tlv1(0x80, byteArrayOf(0)))+        dataHex.startsWith("BF32") -> tlv2(0xBF, 0x32, tlv1(0x80, byteArrayOf(0)))+        dataHex.startsWith("BF33") -> tlv2(0xBF, 0x33, tlv1(0x80, byteArrayOf(0)))+        dataHex.startsWith("BF29") -> tlv2(0xBF, 0x29, tlv1(0x80, byteArrayOf(0)))+        dataHex.startsWith("BF38") -> tlv2(0xBF, 0x38, ByteArray(0))+        dataHex.startsWith("BF21") -> tlv2(0xBF, 0x21, ByteArray(0))+        dataHex.startsWith("BF41") -> tlv2(0xBF, 0x41, ByteArray(0))+        dataHex.startsWith("BF2B") -> tlv2(0xBF, 0x2B, ByteArray(0))+        else -> null     }      private fun info1(): ByteArray = tlv2(@@ -187,7 +203,7 @@ class FakeSmdp {                 "initiateAuthentication" -> 200 to initiate()                 "authenticateClient" -> 200 to authenticateClient()                 "getBoundProfilePackage" ->-                    if (refuseBoundProfilePackage) 200 to failedStatus()+                    if (refuseBoundProfilePackage) 200 to failedStatus                     else 200 to boundProfilePackage()                 "cancelSession" -> 204 to ""                 "handleNotification" -> 204 to ""@@ -208,13 +224,13 @@ class FakeSmdp {      fun stop() = server.stop(0) -    private fun successHeader(): String =+    private val successHeader: String =         """"header":{"functionExecutionStatus":{"status":"Executed-Success"}}"""      private fun initiate(): String {         val txBin = "txbin123".toByteArray()         val serverSigned1 = der(byteArrayOf(0x30), tlv1(0x80, txBin))-        return """{${successHeader()},"transactionId":"tx-123","serverSigned1":"${b64(serverSigned1)}","serverSignature1":"${b64(byteArrayOf(1, 2, 3))}","euiccCiPKIdToBeUsed":"${b64(hexBytes("1122"))}","serverCertificate":"${b64(byteArrayOf(0x30, 0))}"}"""+        return """{${successHeader},"transactionId":"tx-123","serverSigned1":"${b64(serverSigned1)}","serverSignature1":"${b64(byteArrayOf(1, 2, 3))}","euiccCiPKIdToBeUsed":"${b64(hexBytes("1122"))}","serverCertificate":"${b64(byteArrayOf(0x30, 0))}"}"""     }      private fun authenticateClient(): String {@@ -234,10 +250,10 @@ class FakeSmdp {                 tlv1(0x01, byteArrayOf(if (ccRequired) 1 else 0)),             ),         )-        return """{${successHeader()},"profileMetadata":"${b64(metadata)}","smdpSigned2":"${b64(signed2)}","smdpSignature2":"${b64(byteArrayOf(4, 5))}","smdpCertificate":"${b64(byteArrayOf(0x30, 0))}"}"""+        return """{${successHeader},"profileMetadata":"${b64(metadata)}","smdpSigned2":"${b64(signed2)}","smdpSignature2":"${b64(byteArrayOf(4, 5))}","smdpCertificate":"${b64(byteArrayOf(0x30, 0))}"}"""     } -    private fun failedStatus(): String =+    private val failedStatus: String =         """{"header":{"functionExecutionStatus":{"status":"Failed","statusCodeData":{"subjectCode":"8.2.7","reasonCode":"3.8"}}}}"""      private fun boundProfilePackage(): String {@@ -248,6 +264,6 @@ class FakeSmdp {             tlv1(0xA3, tlv1(0x86, byteArrayOf(0x55))),         )         val bpp = tlv2(0xBF, 0x36, body)-        return """{${successHeader()},"boundProfilePackage":"${b64(bpp)}"}"""+        return """{${successHeader},"boundProfilePackage":"${b64(bpp)}"}"""     } }