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

Google Play Integrity API首次请求频繁失败问题求助

问题:Google Play Integrity API 长时间未使用后首次请求失败

我的应用集成了Google Play Integrity API,逻辑为接收Firebase消息时执行完整性校验,校验通过后方可继续核心功能。

  • 应用超过2小时未使用时,首次完整性校验失败概率超50%,无法生成新的Integrity Token,该问题已通过日志上报及向后端发送错误状态记录。
  • 若立即或数分钟内再次发送Firebase消息,Token请求即可成功,应用恢复正常运行;但再次长时间未使用(如次日早晨),问题会复现。
  • 异常由integrityManager.requestIntegrityToken抛出

应用调用IntegrityManager的代码实现

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // 从负载中提取nonce
    CompletableFuture<String> completableFuture = PlayIntegrityCheck.getInstance()
           .getTokenWithExponentialBackoff(nonce);
}

public CompletableFuture<String> getTokenWithExponentialBackoff(String nonce) {
    CompletableFuture<String> future = new CompletableFuture<>();
    IntegrityManager integrityManager = IntegrityManagerFactory.create(getAppContext());
    retryRequest(nonce, maxRetryAttempts, future, integrityManager);
    return future;
}

private void retryRequest(String nonce, int remainingAttempts, CompletableFuture<String> future, IntegrityManager integrityManager) {
    if (remainingAttempts <= 0) {
        future.completeExceptionally(new RuntimeException("Max retry attempts reached"));
        return;
    }

    if (maxRetryAttempts - remainingAttempts > 0) {
        long backoffMillis = initialBackoffMillis * (1L << (remainingAttempts - 1));
        sleepFor(backoffMillis);
    }

    integrityManager
            .requestIntegrityToken(IntegrityTokenRequest.builder().setNonce(nonce).build())
            .addOnSuccessListener(tokenResponse -> {
                future.complete(tokenResponse.token());
            })
            .addOnFailureListener(e -> retryRequest(nonce, remainingAttempts - 1, future, integrityManager));
}

已排除的可能性

  • 非网络问题:不同设备和网络环境下故障模式一致
  • 与应用前后台状态无关:前台、后台场景均会触发
  • 已按API文档实现指数退避重试机制
  • 属于常规API请求,无需预热

捕获到的异常日志

12:46:15.582 Finsky                             E  [294] rdg.a(11): requestIntegrityToken() 
                                                   com.google.android.finsky.integrityservice.IntegrityException
                                                    at rdg.c(PG:499)
                                                    at rdg.b(PG:1)
                                                    at alvd.dispatchTransaction(PG:86)
                                                    at ior.onTransact(PG:13)
                                                    at android.os.Binder.execTransactInternal(Binder.java:1321)
                                                    at android.os.Binder.execTransact(Binder.java:1280)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 15:05:21