Samsung profile switching fails with invalid OMAPI channel #349

Open
opened 2026-08-18 05:16:45 +02:00 by gekjunxu · 6 comments
Contributor

Environment

Device: Samsung SM-S908E

Android: 16, API 36

OpenEUICC: v1.6.2 unprivileged

Adapter: removable third-party eSIM adapter

Description

When switching or enabling an eSIM profile, the app becomes stuck on the loading screen and fails to reconnect to the adapter. Force-quitting and reopening the app temporarily restores access. This issue seems to occur on multiple Samsung phones that I've tried.

Relevant log

Sensitive APDU payloads and identifiers have been omitted:

OMAPI.SEService: Error closing channel

java.lang.IllegalArgumentException:
iccCloseLogicalChannel: invalid argument

    at android.se.omapi.Channel.close(...)
    at im.angry.openeuicc.core.OmapiApduInterface.logicalChannelClose(OmapiApduInterface.kt:52)
    at net.typeblog.lpac_jni.LpacJni.euiccFini(Native Method)
    at im.angry.openeuicc.core.LocalProfileAssistantImpl.close(LocalProfileAssistantImpl.kt:282)
    at im.angry.openeuicc.core.EuiccChannelImpl.close(EuiccChannelImpl.kt:52)
    at im.angry.openeuicc.core.DefaultEuiccChannelManager.waitForReconnect(...)
    at im.angry.openeuicc.service.EuiccChannelManagerService$launchProfileSwitchTask(...)

The verbose log also shows an APDU response with status word 9000 immediately before the channel-close failure.

Suspected cause

Samsung appears to invalidate the OMAPI logical channel during profile switching. OpenEUICC then attempts to close the already-invalid channel, causing IllegalArgumentException and aborting the reconnect task.

I have prepared a pull request #350 that catches this exception and removes the stale channel handle in a finally block:

PR: Handle invalid OMAPI channel during profile switch

I cannot fully hardware-test my locally built APK because the removable adapter authorizes only the official signing certificate. Could a maintainer build and sign a test APK from the pull request?

Environment Device: Samsung SM-S908E Android: 16, API 36 OpenEUICC: v1.6.2 unprivileged Adapter: removable third-party eSIM adapter Description When switching or enabling an eSIM profile, the app becomes stuck on the loading screen and fails to reconnect to the adapter. Force-quitting and reopening the app temporarily restores access. This issue seems to occur on multiple Samsung phones that I've tried. Relevant log Sensitive APDU payloads and identifiers have been omitted: ``` OMAPI.SEService: Error closing channel java.lang.IllegalArgumentException: iccCloseLogicalChannel: invalid argument at android.se.omapi.Channel.close(...) at im.angry.openeuicc.core.OmapiApduInterface.logicalChannelClose(OmapiApduInterface.kt:52) at net.typeblog.lpac_jni.LpacJni.euiccFini(Native Method) at im.angry.openeuicc.core.LocalProfileAssistantImpl.close(LocalProfileAssistantImpl.kt:282) at im.angry.openeuicc.core.EuiccChannelImpl.close(EuiccChannelImpl.kt:52) at im.angry.openeuicc.core.DefaultEuiccChannelManager.waitForReconnect(...) at im.angry.openeuicc.service.EuiccChannelManagerService$launchProfileSwitchTask(...) ``` The verbose log also shows an APDU response with status word 9000 immediately before the channel-close failure. Suspected cause Samsung appears to invalidate the OMAPI logical channel during profile switching. OpenEUICC then attempts to close the already-invalid channel, causing IllegalArgumentException and aborting the reconnect task. I have prepared a pull request #350 that catches this exception and removes the stale channel handle in a finally block: PR: Handle invalid OMAPI channel during profile switch I cannot fully hardware-test my locally built APK because the removable adapter authorizes only the official signing certificate. Could a maintainer build and sign a test APK from the pull request?
Owner

Your PR has been merged, can you test if this is now resolved?

Your PR has been merged, can you test if this is now resolved?

@PeterCxy

The eUICC card I purchased has your official certificate hash pre-configured in its ARA-M access whitelist (SHA-1 fingerprint: 2A2FA878BC7C3354C2CF82935A5945A3EDAE4AFA).
Since we do not hold the official signing key, self-compiled APKs with debug signatures will be denied access by the eUICC chip, making it impossible to verify the fix on actual hardware.

@PeterCxy The eUICC card I purchased has your official certificate hash pre-configured in its ARA-M access whitelist (SHA-1 fingerprint: `2A2FA878BC7C3354C2CF82935A5945A3EDAE4AFA`). Since we do not hold the official signing key, self-compiled APKs with debug signatures will be denied access by the eUICC chip, making it impossible to verify the fix on actual hardware.
Collaborator
Please use https://files.easyeuicc.org/latest/debug.apk
Owner

@G-986 by merging we have also generated a debug build signed with the official fix. Of course now the latest release also contains the fix commit.

@G-986 by merging we have also generated a debug build signed with the official fix. Of course now the latest release also contains the fix commit.
Author
Contributor

I tested the officially signed build containing #350. The result is an improvement, but the issue is not fully resolved.

Sometimes profile switching and reconnect recover successfully, and the app feels more responsive than before. In other attempts, the profile-list refresh spinner remains active indefinitely.

During this testing, I also noticed com.android.se becoming pinned at approximately one full CPU core, causing sustained battery drain. This appears to correlate with the behaviour previously reported in #209 and #352.

I suspect the invalid-close exception and high CPU usage are symptoms of the same platform path: EasyEUICC attempts to close an OMAPI channel that the modem has already invalidated. The Java exception itself may not consume the CPU; rather, the invalid Binder close request or the resulting stale channel state may leave the secure-element service in a bad state.

This may not be entirely specific to EasyEUICC's logic. In #209, 5ber was reported to work successfully with the same removable eUICC on affected Samsung devices, which suggests there may be a different way of handling the modem/channel lifecycle that avoids triggering the problematic path. We may not be able to control how Samsung's modem implementation invalidates the channel, but we can still try to make EasyEUICC more defensive around that behaviour.

I opened draft PR #354 as a localised follow-up. It removes stale channels from the reconnect cache before best-effort cleanup and ensures refresh failures clear the UI spinner. This does not yet prevent the initial invalid close request, but it should help determine whether retaining stale application-side channel state contributes to the spinner or repeated interaction with the failing OMAPI path.

If #354 does not prevent the com.android.se CPU pin, I think the next experiment should be to avoid issuing Channel.close() for a channel that is known to have been invalidated during profile refresh. That would not fix Samsung's underlying OMAPI implementation, but it may allow EasyEUICC to avoid entering the problematic vendor path in the first place.

An officially signed build of #354 would therefore be needed for hardware validation with the ARA-M-allowlisted removable eUICC.

@PeterCxy Could I trouble you to help generate a signed debug build with the changes in #354 for testing?

I tested the officially signed build containing #350. The result is an improvement, but the issue is not fully resolved. Sometimes profile switching and reconnect recover successfully, and the app feels more responsive than before. In other attempts, the profile-list refresh spinner remains active indefinitely. During this testing, I also noticed `com.android.se` becoming pinned at approximately one full CPU core, causing sustained battery drain. This appears to correlate with the behaviour previously reported in #209 and #352. I suspect the invalid-close exception and high CPU usage are symptoms of the same platform path: EasyEUICC attempts to close an OMAPI channel that the modem has already invalidated. The Java exception itself may not consume the CPU; rather, the invalid Binder close request or the resulting stale channel state may leave the secure-element service in a bad state. This may not be entirely specific to EasyEUICC's logic. In #209, 5ber was reported to work successfully with the same removable eUICC on affected Samsung devices, which suggests there may be a different way of handling the modem/channel lifecycle that avoids triggering the problematic path. We may not be able to control how Samsung's modem implementation invalidates the channel, but we can still try to make EasyEUICC more defensive around that behaviour. I opened draft PR #354 as a localised follow-up. It removes stale channels from the reconnect cache before best-effort cleanup and ensures refresh failures clear the UI spinner. This does not yet prevent the initial invalid close request, but it should help determine whether retaining stale application-side channel state contributes to the spinner or repeated interaction with the failing OMAPI path. If #354 does not prevent the `com.android.se` CPU pin, I think the next experiment should be to avoid issuing `Channel.close()` for a channel that is known to have been invalidated during profile refresh. That would not fix Samsung's underlying OMAPI implementation, but it may allow EasyEUICC to avoid entering the problematic vendor path in the first place. An officially signed build of #354 would therefore be needed for hardware validation with the ARA-M-allowlisted removable eUICC. @PeterCxy Could I trouble you to help generate a signed debug build with the changes in #354 for testing?
Collaborator

#353 Might be helpful for this issue

#353 Might be helpful for this issue
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
PeterCxy/OpenEUICC#349
No description provided.