EuiccManager#startResolutionActivity 行为在 Android 12 (API 31) 中发生了变化

EuiccManager#startResolutionActivity behavior changed in Android 12 (API 31)

将我们的应用程序升级为使用 targetSdkVersion 和 compileSdkVersion 到 31 后,我们在 esim 激活过程中面临不同的行为,调用 startResolutionActivity 应用程序现在崩溃并显示:

08-27 10:49:06.288  6641  6641 D DownloadEsimSubscription: 2 - Event received!, com.myapp.download_subscription - 1
08-27 10:49:06.288  6641  6641 D DownloadEsimSubscription: 2 - Subscription downloaded, com.myapp.download_subscription - 1
08-27 10:49:06.296  6641  6641 E AndroidRuntime: FATAL EXCEPTION: main
08-27 10:49:06.296  6641  6641 E AndroidRuntime: Process: com.myapp, PID: 6641
08-27 10:49:06.296  6641  6641 E AndroidRuntime: io.reactivex.exceptions.OnErrorNotImplementedException: Invalid result intent
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at io.reactivex.internal.observers.LambdaObserver.onError(LambdaObserver.java:74)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at io.reactivex.internal.observers.LambdaObserver.onNext(LambdaObserver.java:64)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:200)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:252)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker$BooleanRunnable.run(ExecutorScheduler.java:260)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker.run(ExecutorScheduler.java:225)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at android.os.Handler.handleCallback(Handler.java:938)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:99)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at android.os.Looper.loopOnce(Looper.java:201)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:288)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:7822)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
08-27 10:49:06.296  6641  6641 E AndroidRuntime: Caused by: java.lang.IllegalArgumentException: Invalid result intent
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at android.telephony.euicc.EuiccManager.startResolutionActivity(EuiccManager.java:954)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at com.myapp.esim.system.StartResolvableErrorActivity.invoke(StartResolvableErrorActivity.kt:33)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at com.myapp.esim.ui.EsimFlowView$onCreate$$inlined$observe.onChanged(ArchitectureComponentsExtensions.kt:29)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at androidx.lifecycle.LiveData.considerNotify(LiveData.java:133)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:151)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at androidx.lifecycle.LiveData.setValue(LiveData.java:309)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at com.myapp.ui.-$$Lambda$Hv4SBqiTm1O-ghpLWVMxBLQvcAA.accept(Unknown Source:4)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    at io.reactivex.internal.observers.LambdaObserver.onNext(LambdaObserver.java:60)
08-27 10:49:06.296  6641  6641 E AndroidRuntime:    ... 12 more

查看源代码,似乎现在在意图中有一个必需的额外内容:

    public void startResolutionActivity(Activity activity, int requestCode, Intent resultIntent,
            PendingIntent callbackIntent) throws IntentSender.SendIntentException {
        PendingIntent resolutionIntent =
                resultIntent.getParcelableExtra(EXTRA_EMBEDDED_SUBSCRIPTION_RESOLUTION_INTENT);
        if (resolutionIntent == null) {
            throw new IllegalArgumentException("Invalid result intent");
        }
        Intent fillInIntent = new Intent();
        fillInIntent.putExtra(EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_RESOLUTION_CALLBACK_INTENT,
                callbackIntent);
        activity.startIntentSenderForResult(resolutionIntent.getIntentSender(), requestCode,
                fillInIntent, 0 /* flagsMask */, 0 /* flagsValues */, 0 /* extraFlags */);
    }

即:

    /**
     * Key for an extra set on {@link PendingIntent} result callbacks providing the resolution
     * pending intent for {@link #EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR}s.
     * @hide
     */
    public static final String EXTRA_EMBEDDED_SUBSCRIPTION_RESOLUTION_INTENT =
            "android.telephony.euicc.extra.EMBEDDED_SUBSCRIPTION_RESOLUTION_INTENT";

但我不清楚这个 extra 应该是什么。 documentation.

中也没有提到(我想)

针对 api 30 个作品测试针对目标和构建应用程序的相同代码。

相关代码:


 open operator fun invoke(intent: Intent) {
        val callbackIntent = PendingIntent.getBroadcast(activity,
            RequestCodes.REQUEST_DOWNLOAD,
            Intent(DownloadEsimSubscription.getActionDownloadSubscriptionName(activity)),
            PendingIntent.FLAG_UPDATE_CURRENT
        )

        val euiccManager = activity.getSystemService(Context.EUICC_SERVICE) as EuiccManager

        try {
            euiccManager.startResolutionActivity(
                activity,
                RequestCodes.REQUEST_SOLVE_ISSUE,
                intent,
                callbackIntent
            )
        } catch (e: IntentSender.SendIntentException) {
            Logger.e(LOGTAG, "SendIntentException when calling again startResolutionActivity - ", e)
        }

        esimActivationFlowBL.switch()
    }

传递给此方法的意图是在监听订阅过程的 broadcastReceiver 中返回的

还有其他人遇到过这个问题吗?

中使用的回调意图
euiccManager.downloadSubscription(subscription, true, callbackIntent)

应具有可变标志,以便系统可以添加解决方案所需的额外内容 activity。

就我而言:

val callbackIntent = PendingIntent.getBroadcast(context, RequestCodes.REQUEST_DOWNLOAD, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)

val euiccManager = context.getSystemService(Context.EUICC_SERVICE) as EuiccManager
       euiccManager.downloadSubscription(subscription, true, callbackIntent)