Modern Apps git

← Modern-Apps.git

fix naming and crash

Commit
ea3e2c9e534b9972ed9d251f20cf2a3396260545
Author
vayun-mathur <[email protected]>
When
2026-09-27 02:41 UTC (2 months ago)
Parents
c8edfd7

Diff

euicc/src/main/java/com/vayunmathur/euicc/EuiccNative.kt
diff --git a/euicc/src/main/java/com/vayunmathur/euicc/EuiccNative.kt b/euicc/src/main/java/com/vayunmathur/euicc/EuiccNative.ktindex ba4f93a5be..fce144e6c8 100644--- a/euicc/src/main/java/com/vayunmathur/euicc/EuiccNative.kt+++ b/euicc/src/main/java/com/vayunmathur/euicc/EuiccNative.kt@@ -100,12 +100,14 @@ object EuiccNative {      /**      * Finishes an authenticated session (PrepareDownload with hashCc, BPP fetch,-     * segment install with [callback] progress) and returns-     * `{"success":Boolean,"message":String}`. Consumes the session.+     * segment install with [callback] progress, then SetNickname from the carrier+     * preview) and returns `{"success":Boolean,"message":String,"iccid":String}`.+     * Consumes the session.      */     external fun nativeFinishDownload(         transactionId: String,         confirmationCode: String,+        nickname: String,         callback: DownloadProgressCallback,     ): String 
euicc/src/main/java/com/vayunmathur/euicc/data/Profile.kt
diff --git a/euicc/src/main/java/com/vayunmathur/euicc/data/Profile.kt b/euicc/src/main/java/com/vayunmathur/euicc/data/Profile.ktindex d7ade1cad3..a66a92a9f7 100644--- a/euicc/src/main/java/com/vayunmathur/euicc/data/Profile.kt+++ b/euicc/src/main/java/com/vayunmathur/euicc/data/Profile.kt@@ -21,7 +21,17 @@ data class Profile( ) {     val isEnabled: Boolean get() = state == "enabled" -    /** Best label to show for this profile. */+    /**+     * Best label to show for this profile: nickname (seeded from the carrier+     * preview at install, user-renamable after), then profile name, then+     * carrier, then the ICCID tail as a last resort so the row is never blank.+     */     val displayName: String-        get() = nickname.ifBlank { name.ifBlank { serviceProvider.ifBlank { iccidDisplay } } }+        get() = nickname.ifBlank {+            name.ifBlank {+                serviceProvider.ifBlank {+                    iccidDisplay.takeLast(4).let { if (it.isNotBlank()) "•••• $it" else "" }+                }+            }+        } }
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 f631b4e883..28aeb38d78 100644--- a/euicc/src/main/java/com/vayunmathur/euicc/platform/EuiccViewModel.kt+++ b/euicc/src/main/java/com/vayunmathur/euicc/platform/EuiccViewModel.kt@@ -32,9 +32,13 @@ data class EuiccScreenState(     val notifications: List<Notification> = emptyList(), ) -/** Native download outcome (`{success, message}`). */+/** Native download outcome (`{success, message, iccid}`). */ @kotlinx.serialization.Serializable-private data class DownloadResult(val success: Boolean = false, val message: String = "")+private data class DownloadResult(+    val success: Boolean = false,+    val message: String = "",+    val iccid: String = "",+)  /** Native authenticate-session outcome (see `EuiccNative.nativeAuthenticate`). */ @kotlinx.serialization.Serializable@@ -177,13 +181,22 @@ class EuiccViewModel(app: Application) : AndroidViewModel(app) {             }             // Foreground guard for the eUICC write: keeps process importance up             // (and the CPU awake) until the install settles either way.+            // The nickname seeds from the carrier preview (profile name first,+            // carrier second); native applies it via SetNickname while the+            // channel is still open.             val app = getApplication<Application>()+            val nickname = when (val current = download) {+                is DownloadState.Confirm ->+                    current.profileName?.ifBlank { null } ?: current.carrier+                is DownloadState.AwaitingConfirmationCode -> current.carrier+                else -> pendingCarrier+            }.orEmpty()             DownloadService.start(app)             val outcome = try {                 withContext(Dispatchers.IO) {                     runCatching {                         channelManager.withIsdrChannel {-                            EuiccNative.nativeFinishDownload(transactionId, code.orEmpty(), callback)+                            EuiccNative.nativeFinishDownload(transactionId, code.orEmpty(), nickname, callback)                         }                     }                 }
euicc/src/main/java/com/vayunmathur/euicc/service/EuiccManagerService.kt
diff --git a/euicc/src/main/java/com/vayunmathur/euicc/service/EuiccManagerService.kt b/euicc/src/main/java/com/vayunmathur/euicc/service/EuiccManagerService.ktindex b09cf194e4..d66b14111d 100644--- a/euicc/src/main/java/com/vayunmathur/euicc/service/EuiccManagerService.kt+++ b/euicc/src/main/java/com/vayunmathur/euicc/service/EuiccManagerService.kt@@ -83,9 +83,16 @@ class EuiccManagerService : EuiccService() {         return runProfileOp(iccid) { raw -> EuiccNative.nativeEnableProfile(raw) }     } -    // Single-port eUICC: there is no onSwitchToSubscriptionWithPort in the-    // framework base this module builds against, and the soldered eUICC has-    // exactly one implicit port — the unported switch above is the whole API.+    // Single-port eUICC with exactly one implicit port: the ported switch is the+    // unported switch. This override must exist (not just a comment) because the+    // framework calls it directly from Settings and the base throws+    // UnsupportedOperationException — a missing override crashes the LPA process.+    override fun onSwitchToSubscriptionWithPort(+        slotId: Int,+        portIndex: Int,+        iccid: String?,+        forceDeactivateSim: Boolean,+    ): Int = onSwitchToSubscription(slotId, iccid, forceDeactivateSim)      override fun onUpdateSubscriptionNickname(slotId: Int, iccid: String, nickname: String?): Int =         runProfileOp(iccid) { raw -> EuiccNative.nativeSetNickname(raw, nickname.orEmpty()) }@@ -168,7 +175,7 @@ class EuiccManagerService : EuiccService() {      private fun Profile.toFrameworkProfileInfo(): EuiccProfileInfo =         EuiccProfileInfo.Builder(iccidDisplay)-            .setNickname(nickname)+            .setNickname(displayName)             .setServiceProviderName(serviceProvider)             .setProfileName(name)             .setState(
euicc/src/main/rust/src/download.rs
diff --git a/euicc/src/main/rust/src/download.rs b/euicc/src/main/rust/src/download.rsindex 447541ec04..8a71733836 100644--- a/euicc/src/main/rust/src/download.rs+++ b/euicc/src/main/rust/src/download.rs@@ -205,8 +205,12 @@ pub fn authenticate(     let ac = parse_activation_code(activation_code)?;      // 1. eUICC challenge + info for the server's authentication.-    let challenge = es10b::parse_euicc_challenge(&store_data(env, &es10b::build_get_euicc_challenge())?)?;-    let euicc_info1 = store_data(env, &es10::build_get_euicc_info1())?;+    let challenge = es10b::parse_euicc_challenge(+        &store_data(env, &es10b::build_get_euicc_challenge())+            .map_err(|e| format!("GetEUICCChallenge: {e}"))?,+    )?;+    let euicc_info1 = store_data(env, &es10::build_get_euicc_info1())+        .map_err(|e| format!("GetEUICCInfo1: {e}"))?;      // 2. Server authentication material.     let r1 = es9p::initiate_authentication(&ac.smdp, &challenge, &euicc_info1)?;@@ -240,7 +244,7 @@ pub fn authenticate(         &r1.server_certificate,         &ctx,     );-    let auth_resp = store_data(env, &auth_req)?;+    let auth_resp = store_data(env, &auth_req).map_err(|e| format!("AuthenticateServer: {e}"))?;      // Binary transaction id for hashCc / CancelSession (the JSON string form     // stays the ES9+ correlator).@@ -296,7 +300,7 @@ pub fn finish_download(         hash_ref,         &session.server_certificate2,     );-    let prep_resp = store_data(env, &prep_req)?;+    let prep_resp = store_data(env, &prep_req).map_err(|e| format!("PrepareDownload: {e}"))?;      // 6. Fetch the (encrypted) Bound Profile Package.     let bpp = es9p::get_bound_profile_package(@@ -313,7 +317,8 @@ pub fn finish_download(     let total = segments.len();     let mut last = Vec::new();     for (i, segment) in segments.iter().enumerate() {-        last = store_data(env, segment)?;+        last = store_data(env, segment)+            .map_err(|e| format!("LoadBoundProfilePackage segment {}/{total}: {e}", i + 1))?;         if !progress.on_progress(env, i + 1, total) {             return Err("Download cancelled".to_string());         }
euicc/src/main/rust/src/es10.rs
diff --git a/euicc/src/main/rust/src/es10.rs b/euicc/src/main/rust/src/es10.rsindex 93bebc1376..7365c36fdd 100644--- a/euicc/src/main/rust/src/es10.rs+++ b/euicc/src/main/rust/src/es10.rs@@ -39,6 +39,9 @@ const TAG_DELETE: u32 = 0xBF33; // ES10c DeleteProfile const TAG_SET_NICKNAME: u32 = 0xBF29; // ES10c SetNickname const TAG_REFRESH_FLAG: u32 = 0x81; // [1] refreshFlag BOOLEAN const TAG_RESULT: u32 = 0x80; // [0] result INTEGER (enable/disable/delete/setNickname)+/// [0]-constructed profile-identifier choice wrapping ICCID (+refresh) in+/// enable/disable/delete requests.+const TAG_PROFILE_CHOICE: u32 = 0xA0;  // Notification list/remove tags, shared with the es10b retrieve path. const TAG_LIST_NOTIFICATION: u32 = 0xBF28; // ES10b ListNotification@@ -261,23 +264,28 @@ pub fn parse_profiles(response: &[u8]) -> Result<Vec<ProfileInfo>, String> { // ---------------------------------------------------------------------------  /// Builds an EnableProfile request keyed by ICCID.+///+/// Per SGP.22 (and lpac's `es10c_enable_disable_delete_profile`), the+/// ICCID + refresh flag ride inside the `[0]`-constructed `A0` choice:+/// `BF31 { A0 { 5A iccid, 81 FF } }`. A bare `BF31 { 5A, 81 }` is rejected+/// by the eUICC (surfaced as result code 127). pub fn build_enable(iccid: &[u8], refresh: bool) -> Vec<u8> {     let mut v = asn1::tlv(TAG_ICCID, iccid);     v.extend(asn1::tlv(TAG_REFRESH_FLAG, &[if refresh { 0xFF } else { 0x00 }]));-    asn1::tlv(TAG_ENABLE, &v)+    asn1::tlv(TAG_ENABLE, &asn1::tlv(TAG_PROFILE_CHOICE, &v)) } -/// Builds a DisableProfile request keyed by ICCID.+/// Builds a DisableProfile request keyed by ICCID (same `A0` choice shape). pub fn build_disable(iccid: &[u8], refresh: bool) -> Vec<u8> {     let mut v = asn1::tlv(TAG_ICCID, iccid);     v.extend(asn1::tlv(TAG_REFRESH_FLAG, &[if refresh { 0xFF } else { 0x00 }]));-    asn1::tlv(TAG_DISABLE, &v)+    asn1::tlv(TAG_DISABLE, &asn1::tlv(TAG_PROFILE_CHOICE, &v)) } -/// Builds a DeleteProfile request keyed by ICCID.+/// Builds a DeleteProfile request keyed by ICCID (same `A0` choice shape). pub fn build_delete(iccid: &[u8]) -> Vec<u8> {     let inner = asn1::tlv(TAG_ICCID, iccid);-    asn1::tlv(TAG_DELETE, &inner)+    asn1::tlv(TAG_DELETE, &asn1::tlv(TAG_PROFILE_CHOICE, &inner)) }  /// Builds a SetNickname request for a profile keyed by ICCID.
euicc/src/main/rust/src/es10_part1.rs
diff --git a/euicc/src/main/rust/src/es10_part1.rs b/euicc/src/main/rust/src/es10_part1.rsindex ff82fc6d2d..4d0f3b135f 100644--- a/euicc/src/main/rust/src/es10_part1.rs+++ b/euicc/src/main/rust/src/es10_part1.rs@@ -122,18 +122,25 @@ mod tests {      #[test]     fn enable_disable_delete_requests() {+        // SGP.22 choice shape: BFxx { A0 { 5A iccid, 81 flag } }.         let iccid = [0x11, 0x22, 0x33];         assert_eq!(             build_enable(&iccid, true),-            vec![0xBF, 0x31, 0x08, 0x5A, 0x03, 0x11, 0x22, 0x33, 0x81, 0x01, 0xFF],+            vec![+                0xBF, 0x31, 0x0A, 0xA0, 0x08, 0x5A, 0x03, 0x11, 0x22, 0x33, 0x81, 0x01,+                0xFF,+            ],         );         assert_eq!(             build_disable(&iccid, false),-            vec![0xBF, 0x32, 0x08, 0x5A, 0x03, 0x11, 0x22, 0x33, 0x81, 0x01, 0x00],+            vec![+                0xBF, 0x32, 0x0A, 0xA0, 0x08, 0x5A, 0x03, 0x11, 0x22, 0x33, 0x81, 0x01,+                0x00,+            ],         );         assert_eq!(             build_delete(&iccid),-            vec![0xBF, 0x33, 0x05, 0x5A, 0x03, 0x11, 0x22, 0x33],+            vec![0xBF, 0x33, 0x07, 0xA0, 0x05, 0x5A, 0x03, 0x11, 0x22, 0x33],         );     } 
euicc/src/main/rust/src/es10b.rs
diff --git a/euicc/src/main/rust/src/es10b.rs b/euicc/src/main/rust/src/es10b.rsindex 5b701822e3..b050eb76ca 100644--- a/euicc/src/main/rust/src/es10b.rs+++ b/euicc/src/main/rust/src/es10b.rs@@ -11,7 +11,7 @@ use crate::asn1; use crate::es10::{     TAG_ICCID, TAG_NOTIFICATION_ADDRESS, TAG_NOTIFICATION_LIST, TAG_NOTIFICATION_METADATA,-    TAG_SEQ_NUMBER, decode_iccid, encode_int_minimal, first_byte, parse_int, utf8,+    TAG_SEQ_NUMBER, decode_iccid, encode_int_minimal, first_byte, hex, parse_int, utf8, };  // --- Tags (SGP.22) ---@@ -71,6 +71,8 @@ pub struct InstallResult {     pub message: String,     /// Sequence number from the result's NotificationMetadata (for retrieve/remove).     pub seq_number: i64,+    /// Installed profile ICCID as raw hex (for the follow-up SetNickname).+    pub installed_iccid: String,     /// Failing BPP command id (0-5) on error, `None` on success.     pub bpp_command_id: Option<i64>,     /// SGP.22 install error reason on error, `None` on success.@@ -207,21 +209,33 @@ pub fn build_prepare_download( /// Segments a Bound Profile Package (BF36) into the ordered list of TLVs the LPA /// must transmit to the eUICC via STORE DATA, mirroring lpac /// (`euicc/es10b.c:es10b_load_bound_profile_package_r`):-/// `[BF23][A0 whole][A1 header + 88 elements...][A2 whole if present][A3-/// header + 86 elements...]`.+/// `[BF36hdr+BF23 verbatim][A0 whole][A1 header + 88 elements...][A2 whole if+/// present][A3 header + 86 elements...]`. ///-/// The wrapper TLVs are sent whole (tag + length + value); the `88…`/`86…`-/// element sequences are sent header-first (tag + length, without the value)-/// then element by element, because the eUICC uses the header as a length-/// prefix for the stream that follows.+/// The first segment is the BPP bytes from the outer BF36 tag through the end+/// of BF23, verbatim: the outer header keeps its FULL body length and the+/// eUICC reads the total BPP length from it — rewriting the length breaks the+/// install with SW 6985. The remaining wrappers are sent whole (tag + length ++/// value); the `88…`/`86…` element sequences are sent header-first (tag ++/// length, without the value) then element by element, because the eUICC uses+/// the header as a length prefix for the stream that follows. pub fn segment_bpp(bpp: &[u8]) -> Result<Vec<Vec<u8>>, String> {     let body = asn1::find(bpp, TAG_BPP).ok_or("BoundProfilePackage: missing BF36")?;     let mut segments = Vec::new(); -    // initialiseSecureChannelRequest (BF23): sent whole.-    let isc = asn1::find(body, TAG_INITIALISE_SECURE_CHANNEL)+    // First segment: the BPP bytes from the outer BF36 tag through the end of+    // BF23, verbatim — including the outer header with its FULL body length+    // (lpac sends `reqbuf_len = tmpnode.self.ptr -+    // n_BoundProfilePackage.self.ptr + tmpnode.self.length`, i.e. the+    // original header untouched). The eUICC reads the total BPP length from+    // it; rewriting the length breaks the install with SW 6985.+    let isc_value = asn1::find(body, TAG_INITIALISE_SECURE_CHANNEL)         .ok_or("BoundProfilePackage: missing BF23")?;-    segments.push(asn1::tlv(TAG_INITIALISE_SECURE_CHANNEL, isc));+    let isc_start = find_child_offset(body, TAG_INITIALISE_SECURE_CHANNEL)+        .ok_or("BoundProfilePackage: missing BF23")?;+    let isc_tlv = asn1::tlv(TAG_INITIALISE_SECURE_CHANNEL, isc_value);+    let prefix_len = bpp.len() - body.len();+    segments.push(bpp[..prefix_len + isc_start + isc_tlv.len()].to_vec());      // firstSequenceOf87 (A0): sent whole.     let seq87 = asn1::find(body, TAG_BPP_SEQ_87).ok_or("BoundProfilePackage: missing A0")?;@@ -249,6 +263,22 @@ pub fn segment_bpp(bpp: &[u8]) -> Result<Vec<Vec<u8>>, String> {     Ok(segments) } +/// Byte offset of the first child with `tag` inside a constructed value body.+fn find_child_offset(body: &[u8], tag: u32) -> Option<usize> {+    let mut offset = 0;+    let mut rest = body;+    while !rest.is_empty() {+        let (tlv, next) = asn1::parse(rest)?;+        if tlv.tag == tag {+            return Some(offset);+        }+        let consumed = rest.len() - next.len();+        offset += consumed;+        rest = next;+    }+    None+}+ /// Parses a ProfileInstallationResult (BF37) into an [`InstallResult`]. /// /// Matches fields by tag — `bppCommandId 0x80`, `errorReason 0x81` — like lpac's@@ -267,10 +297,18 @@ pub fn parse_install_result(response: &[u8]) -> Result<InstallResult, String> {         .map(parse_int)         .unwrap_or(-1); +    // Installed profile ICCID (BCD in NotificationMetadata): needed to address+    // the follow-up SetNickname, since the BPP result carries no ISD-P AID.+    let installed_iccid = asn1::find(data, TAG_NOTIFICATION_METADATA)+        .and_then(|m| asn1::find(m, TAG_ICCID))+        .map(hex)+        .unwrap_or_default();+     let base = InstallResult {         success: false,         message: String::new(),         seq_number,+        installed_iccid,         bpp_command_id: None,         error_reason: None,         notification: response.to_vec(),
euicc/src/main/rust/src/es10b_part1.rs
diff --git a/euicc/src/main/rust/src/es10b_part1.rs b/euicc/src/main/rust/src/es10b_part1.rsindex c921803b7a..0008881d05 100644--- a/euicc/src/main/rust/src/es10b_part1.rs+++ b/euicc/src/main/rust/src/es10b_part1.rs@@ -54,7 +54,10 @@ mod tests {      #[test]     fn segment_bpp_wraps_and_splits_like_lpac() {-        // lpac framing: [BF23][A0 whole][A1 header + 88s][A2 whole][A3 header + 86s].+        // lpac framing: [BF36hdr+BF23 verbatim][A0 whole][A1 header + 88s]+        // [A2 whole][A3 header + 86s]. The first segment keeps the outer+        // header with its FULL body length — the eUICC reads the total BPP+        // length from it.         let isc = asn1::tlv(TAG_INITIALISE_SECURE_CHANNEL, &[0x01]);         let seq87 = asn1::tlv(TAG_BPP_SEQ_87, &asn1::tlv(0x87, &[0x11]));         let mut seq88_inner = asn1::tlv(0x88, &[0x33]);@@ -63,7 +66,7 @@ mod tests {         let seq87b = asn1::tlv(TAG_BPP_SEQ_87B, &asn1::tlv(0x87, &[0x66]));         let seq86 = asn1::tlv(TAG_BPP_SEQ_86, &asn1::tlv(0x86, &[0x55]));         let mut body = Vec::new();-        body.extend(isc);+        body.extend(isc.clone());         body.extend(seq87);         body.extend(seq88);         body.extend(seq87b);@@ -71,9 +74,12 @@ mod tests {         let bpp = asn1::tlv(TAG_BPP, &body);          let segments = segment_bpp(&bpp).unwrap();-        // BF23, A0 whole, A1 header, 88, 88, A2 whole, A3 header, 86.+        // BF36hdr+BF23 verbatim, A0 whole, A1 header, 88, 88, A2 whole,+        // A3 header, 86.         assert_eq!(segments.len(), 8);-        assert_eq!(segments[0], vec![0xBF, 0x23, 0x01, 0x01]);+        let mut expected_first = asn1::header(TAG_BPP, body.len());+        expected_first.extend(isc);+        assert_eq!(segments[0], expected_first);         // A1 header: tag + length only, no value bytes.         assert_eq!(segments[2], asn1::header(TAG_BPP_SEQ_88, seq88_inner.len()));         assert_eq!(segments[3], vec![0x88, 0x01, 0x33]);
euicc/src/main/rust/src/jni.rs
diff --git a/euicc/src/main/rust/src/jni.rs b/euicc/src/main/rust/src/jni.rsindex 994cff8e38..e5652385ae 100644--- a/euicc/src/main/rust/src/jni.rs+++ b/euicc/src/main/rust/src/jni.rs@@ -80,10 +80,24 @@ pub(crate) fn store_data_chunked(         let p1 = if i == last { 0x91 } else { 0x11 };         let mut apdu = vec![0x80u8, 0xE2, p1, i as u8, block.len() as u8];         apdu.extend_from_slice(block);-        // Only the last block's response carries the ES10 reply: intermediate-        // STORE DATA responses are per-block statuses (61xx chaining is-        // already resolved per APDU by the Kotlin transport). Keep the last.-        response = transmit_apdu(env, &apdu)?;+        // Accumulate every block's response data like lpac's+        // `iter_es10x_command` (the Kotlin transport already resolves 61xx+        // per APDU, so intermediate bodies are normally empty — but when a+        // card streams chained reply bytes, only concatenation reassembles+        // them). Fail fast on a non-success status.+        let mut block_resp = transmit_apdu(env, &apdu)?;+        if block_resp.len() < 2 {+            return Err("APDU response too short".into());+        }+        let sw = [block_resp[block_resp.len() - 2], block_resp[block_resp.len() - 1]];+        block_resp.truncate(block_resp.len() - 2);+        response.append(&mut block_resp);+        if sw != [0x90, 0x00] {+            return Err(format!("eUICC returned SW={:02X}{:02X}", sw[0], sw[1]));+        }+        if i == last {+            response.extend_from_slice(&sw);+        }     }      if response.len() < 2 {
euicc/src/main/rust/src/jni_download.rs
diff --git a/euicc/src/main/rust/src/jni_download.rs b/euicc/src/main/rust/src/jni_download.rsindex c2b1b83093..55abaa606f 100644--- a/euicc/src/main/rust/src/jni_download.rs+++ b/euicc/src/main/rust/src/jni_download.rs@@ -32,8 +32,12 @@ thread_local! { }  /// `nativeDownloadProfile(activationCode)` — runs the full SGP.22 download for-/// an activation code and returns a JSON `{success, message}` string. Must be-/// called while the ISD-R channel is open (inside `withIsdrChannel`).+/// an activation code and returns a JSON `{success, message, iccid}` string.+/// Must be called while the ISD-R channel is open (inside `withIsdrChannel`).+///+/// Kept for the `EuiccManagerService` platform path; the UI flow uses the+/// split-phase entries. No nickname is applied here — Settings shows the+/// carrier metadata, and the user can rename from the LUI. #[no_mangle] pub extern "system" fn Java_com_vayunmathur_euicc_EuiccNative_nativeDownloadProfile<'l>(     mut env: JNIEnv<'l>,@@ -49,7 +53,11 @@ pub extern "system" fn Java_com_vayunmathur_euicc_EuiccNative_nativeDownloadProf     };      let json = match crate::download::download_profile(&mut env, &code) {-        Ok(result) => serde_json::json!({ "success": result.success, "message": result.message }),+        Ok(result) => serde_json::json!({+            "success": result.success,+            "message": result.message,+            "iccid": result.installed_iccid,+        }),         Err(message) => serde_json::json!({ "success": false, "message": message }),     };     new_jstring(&env, &json.to_string())@@ -118,13 +126,17 @@ pub extern "system" fn Java_com_vayunmathur_euicc_EuiccNative_nativeAuthenticate  /// `nativeFinishDownload(transactionId, confirmationCode)` — runs /// PrepareDownload (with `hashCc`) → GetBoundProfilePackage → BPP install with-/// progress callbacks, returning `{success, message}`. Consumes the session.+/// progress callbacks, returning `{success, message, iccid}`. Consumes the session.+/// `nickname` (from the carrier preview) is applied via SetNickname while the+/// channel is still open, so the profile shows a name immediately.+/// `nativeFinishDownload(transactionId, confirmationCode, nickname, callback)` #[no_mangle] pub extern "system" fn Java_com_vayunmathur_euicc_EuiccNative_nativeFinishDownload<'l>(     mut env: JNIEnv<'l>,     _class: JClass<'l>,     transaction_id: JString<'l>,     confirmation_code: JString<'l>,+    nickname: JString<'l>,     callback: jni::objects::JObject<'l>, ) -> jstring {     jni_http::init(&mut env);@@ -133,6 +145,7 @@ pub extern "system" fn Java_com_vayunmathur_euicc_EuiccNative_nativeFinishDownlo         return finish_json(&env, false, "Invalid download session");     };     let code = read_string(&mut env, &confirmation_code).filter(|c| !c.is_empty());+    let nickname = read_string(&mut env, &nickname).filter(|c| !c.trim().is_empty());     let session = SESSION.with(|s| s.borrow_mut().remove(&handle));     let Some(session) = session else {         return finish_json(&env, false, "Download session expired — start again");@@ -143,7 +156,26 @@ pub extern "system" fn Java_com_vayunmathur_euicc_EuiccNative_nativeFinishDownlo     };     let json = match crate::download::finish_download(&mut env, &session, code.as_deref(), &mut progress)     {-        Ok(result) => serde_json::json!({ "success": result.success, "message": result.message }),+        Ok(result) => {+            // Seed the profile nickname from the carrier preview while the+            // channel is open; best-effort (a rename can always be retried).+            if result.success {+                if let Some(name) = nickname.as_deref() {+                    let iccid = crate::es10::hex_decode(&result.installed_iccid);+                    if !iccid.is_empty() {+                        let _ = crate::jni::store_data(+                            &mut env,+                            &crate::es10::build_set_nickname(&iccid, name.trim()),+                        );+                    }+                }+            }+            serde_json::json!({+                "success": result.success,+                "message": result.message,+                "iccid": result.installed_iccid,+            })+        }         Err(message) => serde_json::json!({ "success": false, "message": message }),     };     new_jstring(&env, &json.to_string())
library/euicc-stubs/src/main/java/android/service/euicc/EuiccService.java
diff --git a/library/euicc-stubs/src/main/java/android/service/euicc/EuiccService.java b/library/euicc-stubs/src/main/java/android/service/euicc/EuiccService.javaindex a14c88538c..2be6d35080 100644--- a/library/euicc-stubs/src/main/java/android/service/euicc/EuiccService.java+++ b/library/euicc-stubs/src/main/java/android/service/euicc/EuiccService.java@@ -49,6 +49,16 @@ public abstract class EuiccService extends Service {      public abstract int onSwitchToSubscription(int slotId, String iccid, boolean forceDeactivateSim); +    /**+     * Port-aware switch (MEP devices). The framework's default throws+     * {@code UnsupportedOperationException}, which crashes the LPA process when+     * Settings calls it — every override must exist even on single-port eUICCs.+     */+    public int onSwitchToSubscriptionWithPort(+            int slotId, int portIndex, String iccid, boolean forceDeactivateSim) {+        throw new UnsupportedOperationException("LPA must override onSwitchToSubscriptionWithPort");+    }+     public abstract int onUpdateSubscriptionNickname(int slotId, String iccid, String nickname);      public abstract int onEraseSubscriptions(int slotId);