Skip to content

Integrate AdMob reward verification flow in adapter#3468

Open
polmiro wants to merge 19 commits into
admob-reward-verification-locator-splitfrom
admob-reward-verification-adapter-core-integration
Open

Integrate AdMob reward verification flow in adapter#3468
polmiro wants to merge 19 commits into
admob-reward-verification-locator-splitfrom
admob-reward-verification-adapter-core-integration

Conversation

@polmiro
Copy link
Copy Markdown
Member

@polmiro polmiro commented May 12, 2026

Checklist

  • If applicable, unit tests
  • If applicable, create follow-up issues for purchases-ios and hybrids

Motivation

The AdMob adapter reward verification APIs are scaffolded, and core reward verification result plumbing is available in :purchases. This PR wires the adapter callback flow end-to-end so AdMob reward callbacks can return deterministic verification outcomes now, while keeping full polling/retry orchestration out of scope for a follow-up PR.

Description

  • Connects the AdMob reward verification service locator to Purchases lifecycle registration.
  • Adds the AdMob reward verification poller and maps core reward verification results into adapter RewardVerificationResult values.
  • Stores per-ad client transaction IDs on enableRewardVerification() and consumes that state when AdMob reports a reward.
  • Uses a lifecycle-owned RewardVerificationManager to own state, verification scope, cleanup, and main-thread callback delivery.
  • Fails safely with RewardVerificationResult.failed when reward verification show overloads are used without prior enableRewardVerification() or when runtime state is unavailable.
  • Treats PENDING, UNKNOWN, and backend errors as failed results for now; retry/backoff orchestration remains out of scope.
  • Keeps AdMob adapter callback delivery on the main thread and trusts AdMob to invoke the reward callback once per show.
  • Adds focused unit coverage for locator registration and poller result mapping; show behavior coverage remains Robolectric-based.

Out of scope in this PR:

  • polling loops
  • retries/backoff
  • timeout orchestration

Note

Medium Risk
Adds new asynchronous reward-verification flow (lifecycle hooks, background polling, main-thread callback delivery) that affects rewarded ad showing behavior and introduces new failure modes if misconfigured.

Overview
Implements the previously-scaffolded AdMob reward verification APIs: enableRewardVerification() now installs per-ad client transaction IDs and show() overloads now invoke a verification pipeline instead of throwing NotImplementedError, with callbacks delivered on the main thread.

Adds a lifecycle-owned RewardVerificationManager/runtime that hooks into a new public PurchasesLifecycle registration API to create/cancel a verification coroutine scope, track ad→transaction IDs (via WeakHashMap), and fail-safe to RewardVerificationResult.failed when setup/state is missing.

Introduces a Poller that calls core awaitGetRewardVerificationResult and maps core statuses into adapter results (treating PENDING/UNKNOWN/errors as failed for now), plus unit/Robolectric coverage for lifecycle registration, polling mapping, placement override behavior, and cancellation handling.

Reviewed by Cursor Bugbot for commit 8591366. Bugbot is set up for automated code reviews on this repo. Configure here.

@polmiro polmiro changed the title Integrate one-shot AdMob reward verification status in adapter Integrate one-shot reward verification status in adapter May 13, 2026
@polmiro polmiro changed the base branch from admob-reward-verification to admob-reward-verification-polling-endpoint May 13, 2026 07:19
@polmiro polmiro changed the base branch from admob-reward-verification-polling-endpoint to admob-reward-verification-api May 13, 2026 07:36
@polmiro polmiro force-pushed the admob-reward-verification-adapter-core-integration branch from 63bbdb1 to 8088338 Compare May 13, 2026 07:36
Base automatically changed from admob-reward-verification-api to admob-reward-verification May 13, 2026 07:55
@polmiro polmiro force-pushed the admob-reward-verification-adapter-core-integration branch 2 times, most recently from 5e78e69 to 63d3926 Compare May 13, 2026 09:25
@polmiro polmiro changed the title Integrate one-shot reward verification status in adapter Integrate AdMob reward verification flow in adapter May 13, 2026
@polmiro polmiro requested a review from tonidero May 13, 2026 10:14
@polmiro polmiro marked this pull request as ready for review May 13, 2026 10:14
@polmiro polmiro requested a review from a team as a code owner May 13, 2026 10:14
Copy link
Copy Markdown
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, just concerned a bit with the static nature of the state we are holding... Trying to think of ways we can bound it to the purchases instance at least...

@polmiro polmiro force-pushed the admob-reward-verification-adapter-core-integration branch from bb245d4 to 2619158 Compare May 13, 2026 13:41
@polmiro polmiro changed the base branch from admob-reward-verification to admob-reward-verification-response-surface May 13, 2026 13:42
@polmiro polmiro force-pushed the admob-reward-verification-adapter-core-integration branch from 2619158 to f87cb50 Compare May 14, 2026 10:28
@polmiro polmiro changed the base branch from admob-reward-verification-response-surface to admob-reward-verification-locator-split May 14, 2026 10:28
polmiro added 3 commits May 14, 2026 16:36
Expose a small Purchases lifecycle registration bridge and use it as the default registrar for AdMob reward verification hooks.
Map core reward verification responses into AdMob adapter results and preserve cancellation while treating non-terminal states as failed until retry orchestration lands.
Store per-ad verification state on enable, consume it when AdMob reports a reward, and deliver verification outcomes on the main thread through a lifecycle-owned manager.
@polmiro polmiro force-pushed the admob-reward-verification-adapter-core-integration branch from b367836 to 5b7c933 Compare May 14, 2026 14:37
} else {
block()
}
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty the same as PurchasesOrchestrator.dispatch but I was not sure if the wiring was worth while. Perhaps this helper can be promoted to core.

Remove the single-field State wrapper and store the client transaction id directly by ad until reward verification consumes it.
polmiro added 2 commits May 14, 2026 20:49
Let the lifecycle runtime own the weak ad-to-transaction map directly now that no storage abstraction is needed.
Make the missing transaction id path return before checking verification runtime state so manager control flow follows the reward callback lifecycle directly.
polmiro added 5 commits May 14, 2026 20:57
Keep missing-state, missing-runtime, and polling delivery branches together in the manager callback flow.
Remove a small failed-result wrapper so the manager shows fallback result delivery directly in each branch.
Rename completion callback parameters and notification helpers so callback flow reads as started/completed events rather than result values.
Schedule verification under the runtime lock and fail the completion callback if the launched verification job is cancelled before producing a result.
Extract the runtime test seam and assert cancelled verification work completes with a failed reward verification result.
polmiro added 4 commits May 15, 2026 12:49
Treat any failed verification coroutine completion as a terminal failed reward verification result.
Apply detekt formatting corrections for reward verification manager and poller imports.
Refresh API dumps after reward verification callback naming and lifecycle registration changes.
Call the placement-aware AdMob show overload with an explicit reward listener from reward verification wrappers.
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f077332. Configure here.

polmiro added 4 commits May 15, 2026 15:46
Split reward verification show overloads so calls without placement preserve load-time analytics placement while explicit placement overloads continue to override.
Refresh AdMob API signatures after splitting reward verification show overloads by placement handling.
…r-split' into admob-reward-verification-adapter-core-integration
@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (admob-reward-verification-locator-split@2b0b876). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...evenuecat/purchases/PurchasesLifecycleListeners.kt 0.00% 2 Missing ⚠️
Additional details and impacted files
@@                            Coverage Diff                             @@
##             admob-reward-verification-locator-split    #3468   +/-   ##
==========================================================================
  Coverage                                           ?   79.94%           
==========================================================================
  Files                                              ?      374           
  Lines                                              ?    14995           
  Branches                                           ?     2066           
==========================================================================
  Hits                                               ?    11988           
  Misses                                             ?     2167           
  Partials                                           ?      840           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants