UnityAds adapter: context handling (GH-3077) + null/empty token to failure#30
Conversation
Pass a nullable Activity to the Unity SDK instead of hard-rejecting a non-Activity context on show. Removes the unused ERROR_MSG_CONTEXT_NULL. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
collectSignals treated a null/empty token as an empty success, so the bidder billed Unity as a no-fill. Route null/empty tokens to SignalCallbacks.onFailure via RoutingTokenListener (new error code 112). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR extracts and ships two Unity Ads adapter fixes independently: (1) relaxes show-time context handling by passing a nullable Activity into the Unity SDK instead of hard-failing non-Activity contexts, and (2) treats null/empty RTB bidding tokens as an error by routing them to SignalCallbacks.onFailure (new adapter error code 112) rather than reporting an “empty success”.
Changes:
- Update interstitial + rewarded
showAdto passActivity?(nullwhen context is not anActivity) toUnityAds.show(...). - Add
RoutingTokenListenerto route null/empty tokens toSignalCallbacks.onFailurewithERROR_TOKEN_GENERATION_FAILED = 112. - Update/add unit tests covering the new context behavior and null/empty token failure routing.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| ThirdPartyAdapters/unity/unity/src/main/java/com/google/ads/mediation/unity/UnityRewardedAd.java | Allow show with non-Activity context by passing nullable Activity to Unity show. |
| ThirdPartyAdapters/unity/unity/src/main/java/com/google/ads/mediation/unity/UnityInterstitialAd.java | Same nullable-Activity show behavior for interstitial. |
| ThirdPartyAdapters/unity/unity/src/main/java/com/google/ads/mediation/unity/UnityMediationAdapter.java | Route null/empty RTB token to onFailure via new RoutingTokenListener and error code 112. |
| ThirdPartyAdapters/unity/unity/src/test/kotlin/com/google/ads/mediation/unity/UnityRewardedAdTest.kt | Update show-context test to expect Unity show called with null activity. |
| ThirdPartyAdapters/unity/unity/src/test/kotlin/com/google/ads/mediation/unity/UnityInterstitialAdTest.kt | Add show-context test to expect Unity show called with null activity. |
| ThirdPartyAdapters/unity/unity/src/test/kotlin/com/google/ads/mediation/unity/UnityMediationAdapterTest.kt | Add tests asserting null/empty tokens route to SignalCallbacks.onFailure. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
is the following check still needed? In public api migration PR, we were able to remove it |
As discussed will remove thanks. |
BannerView accepts a plain Context since Unity Ads SDK 4.16.2, so drop the Activity checks in collectSignals and the banner load path and pass the context through directly. Also tighten the RoutingTokenListener Javadoc to the implemented behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Good catch on the banner Activity-context check, fixed it in a0ce9fa. BannerView accepts a plain Context since 4.16.2, so removed the Activity requirement from the banner load path too. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
No longer referenced after dropping the Activity-context requirements. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ivity test Copilot flagged that the test only checked onSuccess() and would still pass if onFailure or other callbacks were also invoked. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
|
||
| static final String ERROR_MSG_NON_ACTIVITY = | ||
| "Unity Ads requires an Activity context to load ads."; | ||
| /** UnityAds returned no usable bidding token; routed to onFailure so the bidder skips Unity. */ |
| signalCallbacks.onFailure( | ||
| new AdError( | ||
| ERROR_TOKEN_GENERATION_FAILED, | ||
| "Unity Ads returned a null or empty bidding token.", |
There was a problem hiding this comment.
the other errors have a named constant for an error message. should we do the same?
Separates two Unity Ads adapter fixes from the delayed v4.19.0 fork-sync/new-API migration PR, so they can ship independently off
main.ERROR_MSG_CONTEXT_NULL.collectSignalstreated a null/empty token as an empty success (billed as a no-fill). Route null/empty tokens toSignalCallbacks.onFailureviaRoutingTokenListener(new error code 112).Tests:
./gradlew :unity:testpasses.