You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android API 33下eSIM Profile切换权限异常问题求助

Android 13 (API 33) EuiccManager.switchToSubscription 触发 SecurityException 权限矛盾问题

问题背景

我们开发了一款eSIM Profile下载管理应用,在Android 13(编译目标API 33)下遇到权限异常,已在Pixel 7、Samsung S20机型复现:

  • Android 13起,EuiccManager.switchToSubscription新增portIndex参数
  • 可正常获取portIndex,且目标eSIM Profile由本应用下载;系统自带eSIM功能可正常操作,编译目标API 32时使用无portIndex的旧接口也能正常运行
  • 调用新版方法:
    public void switchToSubscription (int subscriptionId, int portIndex, PendingIntent callbackIntent)
    
    触发以下错误:
    FATAL EXCEPTION: main
    [...], PID: 22231
    java.lang.SecurityException: Must have carrier privileges to use switchToSubscription with portIndex
    at android.telephony.evicc.EviccManager.switchToSubscription(EuiccManager.java:1297)
    
  • 权限校验存在矛盾:
    • SubscriptionManager.canManageSubscription(subscriptionInfo)返回true
    • TelephonyManager.hasCarrierPrivileges()返回false,但官方文档明确hasCarrierPrivileges是SubscriptionManager#canManageSubscription校验的超集

可行解决方案

1. 版本兼容降级调用

针对API 33及以上设备,优先尝试带portIndex的调用,捕获SecurityException后降级到旧版接口:

EuiccManager euiccManager = context.getSystemService(EuiccManager.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
    try {
        euiccManager.switchToSubscription(subId, portIndex, callbackIntent);
    } catch (SecurityException e) {
        // 降级调用无portIndex的旧接口
        euiccManager.switchToSubscription(subId, callbackIntent);
    }
} else {
    euiccManager.switchToSubscription(subId, callbackIntent);
}

2. 验证运营商权限配置

虽然应用下载了目标eSIM Profile,部分厂商在Android 13对eSIM权限做了强化校验:

  • 确认应用是否签署了运营商颁发的专用证书(若涉及运营商合作场景)
  • 检查设备厂商是否限制了第三方应用使用带portIndex的eSIM切换接口,部分机型仅允许系统应用调用该重载方法

3. 从SubscriptionInfo获取端口信息

避免手动指定portIndex,改用SubscriptionInfo中关联的端口值,减少权限校验触发概率:

SubscriptionManager subscriptionManager = context.getSystemService(SubscriptionManager.class);
SubscriptionInfo subInfo = subscriptionManager.getActiveSubscriptionInfo(subId);
if (subInfo != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
    int validPortIndex = subInfo.getPortIndex();
    euiccManager.switchToSubscription(subId, validPortIndex, callbackIntent);
}

4. 提交厂商兼容性反馈

若上述方案无效,可向Google(Pixel设备)、三星(S20设备)提交兼容性问题,说明权限校验逻辑矛盾——canManageSubscription返回true却仍要求运营商权限,这可能属于系统层面的权限逻辑bug。

内容的提问来源于stack exchange,提问作者Johann

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 02:16:14