Repository navigation
Conversation
Add getCreativeWidth()/getCreativeHeight() so consumers can learn which requested size won inside BannerViewListener.onAdLoaded(BannerView). For a multi-size rendering placement (e.g. 300x250 + 320x50) the host otherwise must reserve the bounding box and cannot shrink to the rendered creative. Non-breaking getters sourced from the already-populated bidResponse winning bid (dp; 0 on no-fill). iOS already surfaces this via bannerView(_:didReceiveAdWithAdSize:). Fixes prebid#1006.
Previous run failed at 'Set up Android SDK' (sdkmanager tools) because it pinned a stale pre-fix workflow snapshot; prebid/prebid-mobile-android's main already fixed this on fix/ci-android-sdk-platform-tools (merged 2026-09-14), switching to 'platform-tools'. Empty commit only, to force a fresh workflow resolution — no source change.
mdanylov-sigma
left a comment
There was a problem hiding this comment.
Thanks for picking this up — #1006 is a real gap, and getters rather than a new listener method is the right call for keeping this non-breaking.
One blocking problem: on the ad-server (GAM) win path these getters report the size of the Prebid bid that lost, or 0 when Prebid had no bid at all, even though onAdLoaded fires for the GAM creative. A host using this to size the slot will size it wrong exactly where a wrong size is visible. Details inline, along with a staleness issue around refresh/expiry and a suggested shape for the fix (capture the size when a view is displayed, as iOS does by passing adSize with the ad-server view).
Also worth adding: unit tests for the new public API. BannerViewTest already has the setBidResponse() helper, so null response / no winning bid / winning bid / GAM-win are all cheap to cover.
Reviewed with Claude Code.
| public int getCreativeWidth() { | ||
| Bid bid = bidResponse != null ? bidResponse.getWinningBid() : null; | ||
| return bid != null ? bid.getWidth() : 0; | ||
| } |
There was a problem hiding this comment.
When GAM wins, this returns the size of the bid that lost.
onAdServerWin calls notifyAdLoadedListener() (line 207) while bidResponse still holds the Prebid bid from onFetchCompleted. So inside onAdLoaded for a GAM creative these getters describe a creative that was never rendered:
- Sizes 300x250 + 320x50, Prebid bids 320x50, GAM serves its own 300x250 line item → the host reads 320x50 and shrinks the slot, clipping the GAM creative.
- Prebid has no bid →
onErrornullsbidResponse→ the getters return 0, which the Javadoc defines as no-fill, even though GAM filled the slot. A host that collapses on 0 hides a served ad.
The PR mentions iOS parity, but iOS doesn't have this gap: the size travels with the view (adServerDidWin(_ view:, adSize:) → bannerView(_:didReceiveAdWithAdSize:)), so the GAM path reports GAM's served size.
Suggested fix (also resolves the staleness comment below): record the size where a view is actually displayed rather than deriving it here — in displayPrebidView() (the bid size is already computed there for addView) and in displayAdServerView() (size from the event handler, e.g. AdManagerAdView.getAdSize(), via an overload or a default method on BannerEventListener), and clear it on failure, expiry and destroy.
There was a problem hiding this comment.
Fixed in 46de0e5. The size is now captured where a view is displayed. BannerEventListener gets a default onAdServerWin(View, AdSize) overload, and GamBannerEventHandler passes AdManagerAdView.getAdSize(), so a GAM win reports GAM's served size. A handler that reports no size (or a fluid one) gives 0 instead of the losing bid's size. NextGen still uses the one-arg call, so it reports 0 for now.
| */ | ||
| public int getCreativeHeight() { | ||
| Bid bid = bidResponse != null ? bidResponse.getWinningBid() : null; | ||
| return bid != null ? bid.getHeight() : 0; |
There was a problem hiding this comment.
These values can describe an ad that is not on screen.
They track the mutable bidResponse field, which changes independently of the displayed creative:
- Refresh:
onFetchCompleted(line 173) replacesbidResponsebefore the new creative renders, so while the ad-server request is in flight the getters return the new bid's size while the previous creative is still displayed. - Failed refresh:
onError(line 182) setsbidResponse = null→ 0 ("no-fill"), butdisplayPrebidView()is never reached, so the old creative stays visible. - Render failure /
destroy(): neither clearsbidResponse, so the last bid's size is still returned. - After merging master: Expire ads respectively to the seatbid.bid.exp #945 expires a refreshable banner by destroying the
displayViewand callingremoveAllViews(), but keepsbidResponse— so these report the expired bid's size for an empty slot until the next fetch.
Capturing the size at display time (see the comment above) removes all four cases.
There was a problem hiding this comment.
Fixed in 46de0e5. The getters now return fields set in displayPrebidView() / onAdServerWin, not from bidResponse. A refresh that is still in flight or finds no bid keeps reporting the creative on screen. The size is cleared on render failure, when #945 expiry removes the ad from a refreshable banner, and on destroy(). Each case has a test in BannerViewTest.
| * so the host can size the slot to the creative. {@code onAdLoaded} fires | ||
| * after the bid response is set, so this is populated at callback time. On | ||
| * the ad-server (GAM) win path the served view owns its size, so this | ||
| * reflects the Prebid winning bid only. |
There was a problem hiding this comment.
The doc promises more than the value delivers — worth softening even if the behaviour stays.
- "which size actually rendered" is the requested bid size, not a measured one. When the winning bid names a third-party plugin renderer,
displayPrebidView()takes theelsebranch (line 493) and lays the view outMATCH_PARENTinstead of at the bid size, so the bid's w/h is not the rendered size there. - MRAID
resize()/expand()changes the creative's size after load; these getters keep returning the original bid size.
Calling it the winning bid's declared size would describe it accurately.
There was a problem hiding this comment.
Done in 46de0e5. The Javadoc now calls it the winning bid's declared size, not a measured one. It calls out the plugin-renderer MATCH_PARENT layout, MRAID resize()/expand(), the ad-server-win source, and when the value is 0.
| * path, or 0 when there is no winning bid. See {@link #getCreativeWidth()}. | ||
| */ | ||
| public int getCreativeHeight() { | ||
| Bid bid = bidResponse != null ? bidResponse.getWinningBid() : null; |
There was a problem hiding this comment.
Small cleanup: this null-guarded lookup already exists as getWinnerBid() (line 597) and is now written three times. Production code already calls it from onFetchCompleted, so reusing it here (and dropping the test-only framing) keeps winning-bid selection in one place.
Also note BidResponse.getWinningBid() loops over every seatbid and rewrites winningBidJson on each call, so reading width and height runs that scan twice — worth caching the bid, or the displayed size.
There was a problem hiding this comment.
Done in 46de0e5. displayPrebidView() reads the bid once via getWinnerBid(), and the getters only return cached fields, so the seatbid scan no longer runs per call. getWinnerBid() also moved out of the test-only helpers region.
Picks up the pinned google-play-services-ads 25.4.0 (the branch had a floating version that resolved to 25.5.0, which requires minSdk 24 and broke CI), plus prebid#945 ad expiry, which the review asked to account for.
…isplayed Address review on prebid#1007. getCreativeWidth()/getCreativeHeight() no longer read the mutable bidResponse. The size is captured where a creative is displayed and returned from dedicated fields: - Prebid win: the winning bid's declared w/h, captured in displayPrebidView() via getWinnerBid() before the creative is created. - Ad server win: the ad server creative's size. BannerEventListener gets a default onAdServerWin(View, AdSize) overload; GamBannerEventHandler passes AdManagerAdView.getAdSize(). Handlers that report no size, or a fluid size, give 0 instead of the losing Prebid bid's size. - A refresh that is still loading or finds no bid keeps the size of the creative on screen. - Cleared on render failure, when an expired ad is removed, and on destroy. Javadoc now describes the value as the declared size, and notes plugin renderers and MRAID resize. getWinnerBid() is no longer framed as test-only. Adds BannerViewTest and GamBannerEventHandlerTest coverage.
mdanylov-sigma
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround. Capturing the size at display time fixes the GAM-win and staleness problems from the last round, and the new tests cover each case. A few follow-ups inline, plus these:
Next-Gen. You mentioned NextGenBannerEventHandler still makes the one-arg call and reports 0. It's a small change: the Next-Gen BannerAd has getAdSize() (width/height in dp), and AdViewWrapper already keeps the loaded ad in ad. An adSize property on the wrapper plus the two-arg call at lines 151 and 195 would do it, and NextGenBannerEventHandlerTest (lines 125/135) would switch to the two-arg verify. I'd do it here so both GAM handlers behave the same. Otherwise, a follow-up issue so it doesn't get lost.
Tests. A few paths aren't covered yet:
onAdServerWin(null, size): should clear the size and reportonAdFailed.- The GAM
onAdFailed→onPrebidSdkWin()fallback: should report the bid size. - A Prebid → GAM → Prebid refresh sequence.
Minor: mockBidResponse(w, h, exp) overlaps the existing receiveBid(exp) helper. Merging them would leave one way to fake an auction in this class.
Reviewed with Claude Code.
| @Override | ||
| public void onAdFailed(AdException exception) { | ||
| // The Prebid creative failed to render, so there is no creative size to report. | ||
| clearCreativeSize(); |
There was a problem hiding this comment.
A detached Prebid creative can clear the size of the ad on screen. displayViewListener is shared by every DisplayView this banner creates. displayAdServerView() calls removeAllViews() without destroying displayView, and displayPrebidView() only destroys it while it's still a child. So after a Prebid → GAM refresh, the old creative is still alive and wired to this listener. If it reports a failure later (a video error, for example), this line sets the size to 0x0 while GAM's creative is on screen.
It's an edge case, but the fix belongs one level down: destroy and null displayView in displayAdServerView(), the same way displayPrebidView() does. That also stops the detached creative from leaking and from sending callbacks to bannerViewListener.
There was a problem hiding this comment.
Fixed in 835a955. displayAdServerView() now destroys and nulls displayView before removing views, and onAdServerWin_DestroysPreviousPrebidCreative covers it.
|
|
||
| removeAllViews(); | ||
|
|
||
| // Captured before the creative is created, so it is set by the time onAdLoaded fires. |
There was a problem hiding this comment.
Small doc mismatch. The Javadoc says the value doesn't change until the next creative is displayed, and that a refresh still loading keeps reporting the creative on screen. But on a Prebid win this runs right after removeAllViews() and before the new creative has loaded. So from here until onAdLoaded (or until the creative fails), the getters report the new bid's size for an empty slot.
Reading it in onAdLoaded is fine. I'd either say in the Javadoc that the value is set when a creative starts displaying and is meant to be read from onAdLoaded, or keep the bid size in a pending field and apply it in displayViewListener.onAdLoaded().
There was a problem hiding this comment.
Fixed in 835a955. displayPrebidView() sets a pending size (and nulls the current one, since the old creative is removed), onAdLoaded() publishes it before notifying the host, and a render failure discards it. The Javadoc says the value describes the creative on screen and is meant to be read from onAdLoaded.
| } | ||
|
|
||
| displayView = new DisplayView(getContext(), displayViewListener, displayVideoListener, adUnitConfig, bidResponse); | ||
| if (bidResponse.getPreferredPluginRendererName() == PrebidMobilePluginRegister.PREBID_MOBILE_RENDERER_NAME) { |
There was a problem hiding this comment.
Correction to my earlier comment on the plugin-renderer MATCH_PARENT branch: it isn't only plugin renderers. This line compares strings with ==. getPreferredPluginRendererName() returns either null (no rendererName in the bid's meta, the usual case) or a string parsed from JSON, which isn't interned. So in practice every Prebid creative takes the MATCH_PARENT branch, and the bid-sized addView only runs in the new tests, because mockBidResponse returns the interned constant.
This predates the PR, and switching to .equals wouldn't change much in production, since null still falls through. But the new Javadoc ("a third party plugin renderer lays its view out to match this view") implies the default renderer is laid out at the bid size, and the tests exercise a branch production doesn't take. I'd make it PrebidMobilePluginRegister.PREBID_MOBILE_RENDERER_NAME.equals(...), have mockBidResponse return null for the renderer name so the tests follow the real path, and adjust that Javadoc bullet.
There was a problem hiding this comment.
Done in 835a955. It now uses PREBID_MOBILE_RENDERER_NAME.equals(...), the test helper returns a null renderer name so tests take the MATCH_PARENT path (asserted in creativeSize_OnPrebidWin_CreativeFillsBannerView), and the Javadoc says the creative fills the view rather than being laid out at the bid size.
| * render, after an expired ad is removed, and after {@link #destroy()}.</li> | ||
| * </ul> | ||
| */ | ||
| public int getCreativeWidth() { |
There was a problem hiding this comment.
0 means two different things here. It's returned when nothing is displayed, and also when a creative is displayed but its size is unknown. That includes a GAM fluid ad, a handler that doesn't report a size (Next-Gen today, or any custom BannerEventHandler), and a Prebid bid without w/h. Those are optional in OpenRTB and often missing on outstream video in a multiformat banner. A host that follows this Javadoc and sets the slot height to getCreativeHeight() collapses a live ad to 0 dp in all of those cases.
One fix that also simplifies the code: keep a single @Nullable AdSize creativeSize field and expose getCreativeSize(), returning null only when nothing is displayed. Hosts can then tell "no ad" from "ad of unknown size". It replaces the two ints, setCreativeSize/clearCreativeSize and the two set-or-clear blocks, and uses the same AdSize type as addAdditionalSizes() and the new onAdServerWin(View, AdSize). If you'd rather keep the int getters, please at least say in the Javadoc that 0 doesn't mean the slot is empty.
There was a problem hiding this comment.
Done in 835a955. There is now a single @Nullable AdSize getCreativeSize(): null only when nothing is displayed, and 0x0 when a creative is displayed but its size is unknown (bid without w/h, fluid or other non-positive size, or no size from the handler). The Javadoc says not to size the slot from 0x0.
| * Event handlers that know the served size should call this instead of | ||
| * {@link #onAdServerWin(View)}, so the banner can report it. Pass null when the size is unknown. | ||
| */ | ||
| default void onAdServerWin(View view, @Nullable AdSize adSize) { |
There was a problem hiding this comment.
Optional, but worth considering while this API is new: the two overloads delegate to each other. This default forwards two-arg → one-arg, and BannerView's one-arg override forwards back to two-arg. That works today because BannerView overrides both. But BannerView is the only implementer and event handlers are the callers, so the delegation runs the wrong way. If someone later drops the two-arg override, or writes a wrapper that follows this Javadoc and forwards one-arg → two-arg, it recurses until StackOverflowError. A wrapper that only overrides the one-arg method silently drops the size.
Flipping it keeps every existing caller compiling, and matches iOS, where adServerDidWin(_:adSize:) is the only variant:
/** @deprecated Use {@link #onAdServerWin(View, AdSize)}. */
@Deprecated
default void onAdServerWin(View view) {
onAdServerWin(view, null);
}
void onAdServerWin(View view, @Nullable AdSize adSize);BannerView then only implements the two-arg method. It would only break code that implements BannerEventListener itself, which should be rare outside the SDK.
There was a problem hiding this comment.
Done in 835a955. The two-arg onAdServerWin(View, AdSize) is now abstract, the one-arg overload is a @Deprecated default forwarding null, and BannerView implements only the two-arg method.
| recycleCurrentBanner(); | ||
| embeddedBanner = gamBannerView; | ||
| bannerEventListener.onAdServerWin(getView(gamBannerView)); | ||
| bannerEventListener.onAdServerWin(getView(gamBannerView), getAdSize(gamBannerView)); |
There was a problem hiding this comment.
Probably rare, since Prebid normally drives refresh, but worth a line in the Javadoc. If refresh is configured on the GAM ad unit itself, GAM reloads the embedded AdManagerAdView in place. onAdLoaded fires again, but requestBanner is null by then, so nothing reaches BannerView and the getters keep the previous creative's size.
There was a problem hiding this comment.
Added in 835a955 to the GamBannerEventHandler class Javadoc: refresh configured on the GAM ad unit reloads in place without reaching BannerView, so it keeps the first creative's size.
| WhiteBox.method(GamBannerEventHandler.class, "handleAppEventTimeout").invoke(bannerEventHandler); | ||
|
|
||
| verify(mockBannerEventListener, times(1)).onAdServerWin(any()); | ||
| verify(mockBannerEventListener, times(1)).onAdServerWin(any(), any()); |
There was a problem hiding this comment.
The app-event-timeout path is the usual ad-server win when Prebid sent a bid, but here it's only verified with any(), any(). A test like the one above, with requestBanner set to a mock that returns a size, would confirm that handleAppEventTimeout forwards it.
PublisherAdViewWrapper.getAdSize() isn't covered in PublisherAdViewWrapperTest either: the FLUID mapping, a null getAdSize(), and the catch path.
There was a problem hiding this comment.
Added in 835a955. onAppEventTimeout_PassGamCreativeSizeToOnAdServerWin sets requestBanner to a mock returning a size and verifies it is forwarded, and PublisherAdViewWrapperTest now covers a normal size, FLUID, a null getAdSize() and the catch path.
| public AdSize getAdSize() { | ||
| try { | ||
| com.google.android.gms.ads.AdSize gamAdSize = adView.getAdSize(); | ||
| return gamAdSize != null ? new AdSize(gamAdSize.getWidth(), gamAdSize.getHeight()) : null; |
There was a problem hiding this comment.
Nit: GamBannerEventHandler.convertGamAdSize(...) already does this mapping, so calling it (after the null check) would keep a single conversion.
Also, the Javadoc says this returns null when GAM reports no size, but for FLUID it returns AdSize(-3, -4). Worth saying that negative dimensions can come back and are filtered in BannerView.
There was a problem hiding this comment.
Done in 835a955. getAdSize() calls convertGamAdSize(...) after the null check, and the Javadoc notes that FLUID comes back as -3 x -4 and that BannerView reports it as unknown size.
…Size Address round 2 review: - Replace getCreativeWidth/getCreativeHeight with getCreativeSize(). It is null when nothing is displayed and 0x0 when a creative is displayed but its size is unknown. - Publish a Prebid creative's size when it loads, right before onAdLoaded. - Destroy the previous Prebid creative when the ad server wins, so a detached creative cannot clear the size or send callbacks. - Compare the preferred renderer name with equals. - Make onAdServerWin(View, AdSize) the primary BannerEventListener method and deprecate the one argument overload. - Report the served size from the Next-Gen banner event handler. - Reuse convertGamAdSize in PublisherAdViewWrapper.getAdSize and document fluid sizes and GAM side refresh. - Add tests for the null view, GAM failure fallback, refresh sequence, app event timeout size and PublisherAdViewWrapper/AdViewWrapper sizes.
|
Thanks for the second pass. All addressed in 835a955 (after merging current Next-Gen. Done here. Tests. Added in Helper. The PR description's "Changes after review" section now covers round 2. |
Resolve conflicts with the GAM manual impression change: handleAdServerWin() now passes the GAM creative size to onAdServerWin(View, AdSize).
The Next-Gen SDK's Kotlin metadata declares getAdSize() as a function, not an adSize property, so the property access did not compile.
|
@mdanylov-sigma all comments from your second pass were addressed in 835a955 (replies are on each thread). Since then:
Core, GAM and Next-Gen unit tests pass, except Could you take another look? |
mdanylov-sigma
left a comment
There was a problem hiding this comment.
Thanks, everything from the second pass is in. I checked each item against caacfa1:
displayAdServerView()destroys and nulls the previousDisplayView, so a detached creative can no longer clear the size.- The Prebid size stays pending until
onAdLoaded, a render failure drops it, and the Javadoc matches. - The renderer name is compared with
equals, and the tests now take the productionMATCH_PARENTpath. - A single
@Nullable AdSize getCreativeSize(): null when nothing is displayed, 0x0 when the size is unknown. onAdServerWin(View, AdSize)is the abstract method, and the one-arg overload is a deprecated default.- Next-Gen reports
BannerAd.getAdSize()throughAdViewWrapper.adSize. - The GAM in-place refresh note, the app-event-timeout and
PublisherAdViewWrappertests, and the three missingBannerViewpaths are all covered.
BannerViewTest, GamBannerEventHandlerTest, PublisherAdViewWrapperTest, AdViewWrapperTest and NextGenBannerEventHandlerTest pass locally at caacfa1.
Reviewed with Claude Code.
Fixes #1006.
Problem
The rendering
BannerViewgives consumers no way to learn which requested size actually won.BannerViewListener.onAdLoaded(BannerView)carries no size and there's no getter for the rendered creative's dimensions. For a multi-size rendering placement (multiple sizes on oneBannerViewviaaddAdditionalSizes(...), e.g. 300x250 + 320x50) the host must reserve the bounding box of all requested sizes and, when a smaller creative wins, has no signal to shrink the slot — leaving whitespace. iOS already exposes this viabannerView(_:didReceiveAdWithAdSize:).Change
A non-breaking public getter on
BannerView:@Nullable AdSize getCreativeSize()→ declared size in dp of the displayed creative.nullwhen nothing is displayed,0x0when a creative is displayed but its size is unknown.The size is published right before
onAdLoaded, soonAdLoadedcan read it and it stays accurate across refreshes (see "Changes after review"). A getter rather than a new listener method, so no existing implementer breaks.Notes
BannerEventListener.onAdServerWin(View, AdSize)overload (see below).didReceiveAdWithAdSize.Changes after review
Round 1
bidResponse.w/h.BannerEventListener.onAdServerWin(View, AdSize).GamBannerEventHandlerpassesAdManagerAdView.getAdSize(). It is never the losing Prebid bid's size.destroy().masterto pick up the pinnedplay-services-adsversion for CI.Round 2
@Nullable AdSize getCreativeSize()instead ofgetCreativeWidth()/getCreativeHeight().nullmeans nothing is displayed.0x0means a creative is displayed but its size is unknown: a bid withoutw/h, a fluid or other non-positive ad server size, or a handler that reports no size.onAdLoaded, right before the host listener is called. While a new Prebid creative loads, the previous one is gone and the value isnull. A render failure discards the pending size.displayAdServerView()destroys and nulls the previous PrebidDisplayView, so a detached creative can't clear the size, leak, or callbannerViewListener.equals. The Javadoc says the creative is laid out to fill the view, not at the bid size.onAdServerWin(View, AdSize)is now the abstract method. The one-arg overload is a@Deprecateddefault that forwards withnull.BannerViewimplements only the two-arg method, matching iOSadServerDidWin(_:adSize:).NextGenBannerEventHandlerreports the served size through a newAdViewWrapper.adSize(fromBannerAd.getAdSize()), so both GAM handlers behave the same.PublisherAdViewWrapper.getAdSize()reusesGamBannerEventHandler.convertGamAdSize(...). The Javadoc covers negative fluid dimensions and GAM-side refresh, which isn't reflected inBannerView.PublisherAdViewWrapper/AdViewWrappersize mapping including FLUID, null and exceptions. TheBannerViewTestauction helpers are merged into onereceiveBid(w, h, exp), and bids name no preferred renderer so tests take the production display path.Developed with AI assistance.