globalesim: Install is offered only when a complete activation code exists
- Commit
4801c742633dbd65cbf00513449a1727a0fb3afc- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 09:26 UTC (5 days ago)
- Parents
9bcaa5c
A profile exists before its activation fields do (both DTO fields default to blank, pinned by a realistic status payload test), and Install eSIM was enabled for every non-null profile. buildActivationCode never refused: it wrapped blanks into plausible strings — an empty matching ID produced 'LPA:1$smdp.example$', both blank produced 'LPA:1$$' — and HomeScreen launched that at the system installer, which rejects empty-segment codes to a dead-end manual-entry page: an install that looks offered but can only get stuck. buildActivationCode now returns null when the matching ID is blank, when the SM-DP+ is blank for a bare ID, when a multi-segment code has a blank segment, and when a two-segment tail cannot be split at the known SM-DP+; all previously valid shapes build byte-identical output. The code is built once beside the button and Install is enabled only for a non-null code. Two regression tests failed pre-fix (seven synthetic null cases; the Install node lacking a disabled state). Card validation, data accounting and the provisioning watch were audited and cleared. Verified: :globalesim:testDevUnitTest 65 tests pass; :globalesim:lint 0 errors.
Diff
globalesim/src/main/java/com/vayunmathur/globalesim/domain/EsimActivationCode.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/domain/EsimActivationCode.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/domain/EsimActivationCode.ktindex 3c76cc9302..81a98ea324 100644--- a/globalesim/src/main/java/com/vayunmathur/globalesim/domain/EsimActivationCode.kt+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/domain/EsimActivationCode.kt@@ -9,14 +9,29 @@ package com.vayunmathur.globalesim.domain * (`LPA:1$<smdp><matchingId>`), which the LPA rejects straight to manual * entry. When the tail starts with our known SM-DP+ address, split there * and re-insert the separator instead of passing the fused string through.+ *+ * Returns null when no complete code can be built: a profile exists before+ * its activation fields do (both decode to "" when the server omits them),+ * and fabricating `LPA:1$$…` around the blanks hands the installer a string+ * it rejects the same way. Callers gate the install action on a non-null+ * result instead of stranding the user on that manual-entry page. */-fun buildActivationCode(rawCode: String, smdpAddress: String): String {+fun buildActivationCode(rawCode: String, smdpAddress: String): String? { val body = rawCode.trim().let { if (it.startsWith("LPA:", ignoreCase = true)) it.substring(4) else it }- if ('$' !in body) return "LPA:1\$$smdpAddress\$$body"+ if (body.isBlank()) return null+ if ('$' !in body) {+ if (smdpAddress.isBlank()) return null+ return "LPA:1\$$smdpAddress\$$body"+ } val parts = body.split('$')- if (parts.size >= 3) return "LPA:$body"+ if (parts.size >= 3) {+ // Segments are version, SM-DP+ host, matching ID: both payload+ // segments must be present for the LPA to accept the code.+ if (parts[1].isBlank() || parts[2].isBlank()) return null+ return "LPA:$body"+ } // Fused `<smdp><matchingId>` tail: split at the known SM-DP+ address. val tail = parts.last() if (smdpAddress.isNotEmpty() &&@@ -25,5 +40,5 @@ fun buildActivationCode(rawCode: String, smdpAddress: String): String { ) { return "LPA:1\$$smdpAddress\$${tail.substring(smdpAddress.length)}" }- return "LPA:$body"+ return null }
globalesim/src/main/java/com/vayunmathur/globalesim/ui/HomeScreen.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/ui/HomeScreen.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/ui/HomeScreen.ktindex c3a46fcd19..7a91847cfb 100644--- a/globalesim/src/main/java/com/vayunmathur/globalesim/ui/HomeScreen.kt+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/ui/HomeScreen.kt@@ -127,26 +127,32 @@ fun HomeScreen( ) } if (profile != null) {+ // The vendor stores SM-DP+ and matching ID separately; the+ // LPA needs the full LPA:1$<smdp>$<code> string, and a bare+ // or blank-segment one fails validation into a blank+ // manual-entry page. The server sometimes fuses smdp+code+ // with the `$` missing, so normalize first; a profile whose+ // activation fields have not arrived yet builds no code,+ // and Install stays disabled rather than handing the+ // installer a fabricated string.+ val activationCode = buildActivationCode(profile.activationCode, profile.smdpAddress) Row( modifier = Modifier.fillMaxWidth().padding(top = 12.dp), horizontalArrangement = Arrangement.spacedBy(8.dp), ) { OutlinedButton( onClick = {- // The vendor stores SM-DP+ and matching ID separately;- // the LPA needs the full LPA:1$<smdp>$<code> string.- // A bare matching ID fails validation and lands on a- // blank manual-entry page. The server sometimes fuses- // smdp+code with the `$` missing, so normalize first.- val full = buildActivationCode(profile.activationCode, profile.smdpAddress)- val url = "https://esimsetup.android.com/esim_qrcode_provisioning?carddata=$full"- val intent = Intent(Intent.ACTION_VIEW, url.toUri())- try {- context.startActivity(intent)- } catch (_: ActivityNotFoundException) {- messenger.show(context.getString(R.string.no_esim_installer))+ activationCode?.let { full ->+ val url = "https://esimsetup.android.com/esim_qrcode_provisioning?carddata=$full"+ val intent = Intent(Intent.ACTION_VIEW, url.toUri())+ try {+ context.startActivity(intent)+ } catch (_: ActivityNotFoundException) {+ messenger.show(context.getString(R.string.no_esim_installer))+ } } },+ enabled = activationCode != null, modifier = Modifier.weight(1f), ) { Text(stringResource(R.string.install_esim))
globalesim/src/test/java/com/vayunmathur/globalesim/domain/EsimActivationCodeTest.kt
diff --git a/globalesim/src/test/java/com/vayunmathur/globalesim/domain/EsimActivationCodeTest.kt b/globalesim/src/test/java/com/vayunmathur/globalesim/domain/EsimActivationCodeTest.ktindex 3bac3f5e8d..eb6a83ea4b 100644--- a/globalesim/src/test/java/com/vayunmathur/globalesim/domain/EsimActivationCodeTest.kt+++ b/globalesim/src/test/java/com/vayunmathur/globalesim/domain/EsimActivationCodeTest.kt@@ -2,6 +2,7 @@ package com.vayunmathur.globalesim.domain import kotlin.test.Test import kotlin.test.assertEquals+import kotlin.test.assertNull class EsimActivationCodeTest { @Test@@ -20,6 +21,27 @@ class EsimActivationCodeTest { ) } + @Test+ fun blankOrIncompletePartsYieldNoCode() {+ // Regression: ProfileDto defaults activation_code/smdp_address to ""+ // when the server omits them (a just-created profile has neither+ // yet), and the builder used to fabricate a string anyway — e.g.+ // "LPA:1$smdp.example$" with an empty matching ID, or "LPA:1$$TN123"+ // with an empty SM-DP+ — which the Install button then handed to the+ // system installer, landing the user on a dead-end manual-entry page.+ // No complete code can be built from blank parts, so there is none.+ assertNull(buildActivationCode("", "smdp.example"))+ assertNull(buildActivationCode(" ", "smdp.example"))+ assertNull(buildActivationCode("", ""))+ assertNull(buildActivationCode("TN123", ""))+ // Well-formed shape, but a payload segment is empty.+ assertNull(buildActivationCode("LPA:1\$smdp.example\$", "smdp.example"))+ assertNull(buildActivationCode("LPA:1\$\$TN123", "smdp.example"))+ // Two segments whose host is not our SM-DP+: nothing to split, and a+ // bare "LPA:1$<tail>" passthrough would be missing a segment.+ assertNull(buildActivationCode("LPA:1\$other.exampleTN123", "smdp.example"))+ }+ @Test fun fusedSmdpAndMatchingIdAreSplit() { // The exact shape seen in the broken handoff: one `$` missing.
globalesim/src/test/java/com/vayunmathur/globalesim/ui/HomeTopUpComposeTest.kt
diff --git a/globalesim/src/test/java/com/vayunmathur/globalesim/ui/HomeTopUpComposeTest.kt b/globalesim/src/test/java/com/vayunmathur/globalesim/ui/HomeTopUpComposeTest.ktindex ed1a7bd1aa..2cd0d880f2 100644--- a/globalesim/src/test/java/com/vayunmathur/globalesim/ui/HomeTopUpComposeTest.kt+++ b/globalesim/src/test/java/com/vayunmathur/globalesim/ui/HomeTopUpComposeTest.kt@@ -1,6 +1,7 @@ package com.vayunmathur.globalesim.ui import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.assertIsNotEnabled import androidx.compose.ui.test.hasClickAction import androidx.compose.ui.test.hasSetTextAction import androidx.compose.ui.test.performSemanticsAction@@ -111,6 +112,21 @@ class HomeTopUpComposeTest { @Test fun statusUnknownIsChecking() = assertStatusLabel("unknown", "Balance · Checking…") @Test fun statusCustomIsCapitalized() = assertStatusLabel("weird", "Balance · Weird") + @Test fun profileWithoutActivationCodeHasInstallDisabled() {+ // The server profile exists before its activation fields do+ // (ProfileDto defaults both to ""), so Install must stay disabled+ // until a complete LPA code can be built — tapping it used to hand+ // the installer a fabricated "LPA:1$$…" string and strand the user+ // on a manual-entry page.+ home(+ EsimUiState(+ statusLoaded = true,+ simId = "sim-xyz",+ profile = ProfileDto(iccid = "8901", status = "pending", walletUsdCents = 200L)))+ composeRule.onNodeWithText("Balance · Activating").assertIsDisplayed()+ composeRule.onNodeWithText("Install eSIM").assertIsNotEnabled()+ }+ @Test fun profileInstallAndCopyActions() { val ctx = ApplicationProvider.getApplicationContext<android.content.Context>() home(