Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.prebid.mobile.api.original.OnFetchDemandResult;
import org.prebid.mobile.configuration.AdUnitConfiguration;
import org.prebid.mobile.rendering.bidding.data.bid.BidResponse;
import org.prebid.mobile.rendering.bidding.data.bid.TargetingKey;
import org.prebid.mobile.rendering.bidding.listeners.BidRequesterListener;
import org.prebid.mobile.rendering.bidding.loader.BidLoader;
import org.prebid.mobile.rendering.sdk.PrebidContextHolder;
Expand Down Expand Up @@ -350,7 +351,7 @@ private void registerVisibilityTrackerIfNeeded(BidResponse response) {

String burl = response.getWinningBid().getBurl();

String cacheId = response.getTargeting().get("hb_cache_id");
String cacheId = response.getTargeting().get(TargetingKey.CACHE_ID);
if (cacheId == null) {
LogUtil.warning(TAG, "Can't register visibility tracker. There is no hb_cache_id keyword.");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,12 @@ public enum ResultCode {
/**
* Prebid Server returned bids, but none had successful cache entries.
*/
NO_CACHED_BIDS
NO_CACHED_BIDS,
/**
* The bid that the registered
* {@link org.prebid.mobile.rendering.bidding.data.bid.PrebidBidSelecting} plugin chose lacks
* the targeting keywords the ad server needs ({@code hb_pb} and {@code hb_bidder}, plus
* {@code hb_cache_id} when the cache is used), so no keywords were attached.
*/
INVALID_TARGETING
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,19 @@ public enum FetchDemandResult {
/**
* Prebid Server returned bids, but none had successful cache entries.
*/
NO_CACHED_BIDS;
NO_CACHED_BIDS,
/**
* The bid that the registered
* {@link org.prebid.mobile.rendering.bidding.data.bid.PrebidBidSelecting} plugin chose lacks
* the targeting keywords the ad server needs, so no keywords were attached.
*/
INVALID_TARGETING;

private static final String TAG = "FetchDemandResult";

public static final String NO_BIDS_MESSAGE = "Failed to parse bids. No winning bids were found.";
public static final String NO_CACHED_BIDS_MESSAGE = "No bids with successful Prebid Cache entries were found.";
public static final String INVALID_TARGETING_MESSAGE = "The selected bid has no valid targeting keywords";

/**
* Returns the {@link ResultCode} the original API reports for the same outcome.
Expand Down Expand Up @@ -109,6 +116,8 @@ public ResultCode toResultCode() {
return ResultCode.NO_BIDS;
case NO_CACHED_BIDS:
return ResultCode.NO_CACHED_BIDS;
case INVALID_TARGETING:
return ResultCode.INVALID_TARGETING;
case SERVER_ERROR:
default:
return ResultCode.PREBID_SERVER_ERROR;
Expand Down Expand Up @@ -139,6 +148,8 @@ public static FetchDemandResult fromResultCode(ResultCode resultCode) {
return NO_BIDS;
case NO_CACHED_BIDS:
return NO_CACHED_BIDS;
case INVALID_TARGETING:
return INVALID_TARGETING;
case PREBID_SERVER_ERROR:
return SERVER_ERROR;
case TIMEOUT:
Expand Down Expand Up @@ -167,6 +178,10 @@ public static FetchDemandResult parseErrorMessage(String msg) {
if (msg.contains(NO_CACHED_BIDS_MESSAGE)) {
return NO_CACHED_BIDS;
}
// Checked before "No bids": the bid selector reports it as an AdException.NO_BIDS error
if (msg.contains(INVALID_TARGETING_MESSAGE)) {
return INVALID_TARGETING;
}
if (msg.contains("No bids") || msg.equals(NO_BIDS_MESSAGE)) {
return NO_BIDS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.prebid.mobile.PrebidMobile;
import org.prebid.mobile.api.rendering.pluginrenderer.PrebidMobilePluginRenderer;
import org.prebid.mobile.rendering.bidding.data.bid.PrebidBidSelecting;

/**
* A kind of plugin the SDK accepts. Pass one to
Expand Down Expand Up @@ -50,6 +51,23 @@ public final class PluginCapability<P> {
)
);

/**
* Bid selectors: objects that implement {@link PrebidBidSelecting}.
* <p>
* Selectors are identified by {@link PrebidBidSelecting#getPluginInfo()}, i.e. name and version.
* At most one selector is registered at a time: while one is registered, registering another is
* ignored. Unregister the current one first.
*/
public static final PluginCapability<PrebidBidSelecting> BID_SELECTOR = new PluginCapability<>(
new PluginRegistry<>(
"bidSelector",
PrebidBidSelecting::getPluginInfo,
1,
PrebidBidSelecting::onRegister,
PrebidBidSelecting::onUnregister
)
);

@NonNull
private final PluginRegistry<P> registry;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ private void reflectAttrs(AttributeSet attrs) {
}

private void init() {
adUnitConfig.setRendersWithoutAdServer(eventHandler instanceof StandaloneBannerEventHandler);
initPrebidRenderingSdk();
initAdConfiguration();
initBidLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public InterstitialAdUnit(
config.setConfigId(configId);
config.setAdUnitFormats(adUnitFormats);
config.addAdFormat(AdFormat.INTERSTITIAL);
config.setRendersWithoutAdServer(this.eventHandler instanceof StandaloneInterstitialEventHandler);
init(config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public RewardedAdUnit(
adUnitConfiguration.setConfigId(configId);
adUnitConfiguration.setAdFormats(EnumSet.of(AdFormat.INTERSTITIAL, AdFormat.VAST));
adUnitConfiguration.setRewarded(true);
adUnitConfiguration.setRendersWithoutAdServer(eventHandler instanceof StandaloneRewardedVideoEventHandler);

init(adUnitConfiguration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import androidx.annotation.FloatRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;

import org.prebid.mobile.AdSize;
import org.prebid.mobile.BannerParameters;
Expand Down Expand Up @@ -41,6 +42,7 @@ public class AdUnitConfiguration {
@Nullable
private Boolean isSoundButtonVisible;
private boolean isOriginalAdUnit = false;
private boolean rendersWithoutAdServer = false;
private boolean hasEndCard = false;

private int videoSkipOffset = SKIP_OFFSET_NOT_ASSIGNED;
Expand Down Expand Up @@ -115,6 +117,7 @@ public AdUnitConfiguration(@NonNull AdUnitConfiguration source) {
isMuted = source.isMuted;
isSoundButtonVisible = source.isSoundButtonVisible;
isOriginalAdUnit = source.isOriginalAdUnit;
rendersWithoutAdServer = source.rendersWithoutAdServer;
hasEndCard = source.hasEndCard;

videoSkipOffset = source.videoSkipOffset;
Expand Down Expand Up @@ -533,6 +536,20 @@ public void setIsOriginalAdUnit(boolean originalAdUnit) {
isOriginalAdUnit = originalAdUnit;
}

/**
* Whether the ad unit renders the winning bid itself, with no ad server involved. Such an ad
* unit doesn't need the targeting keywords that ad servers match.
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public boolean rendersWithoutAdServer() {
return rendersWithoutAdServer;
}

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public void setRendersWithoutAdServer(boolean rendersWithoutAdServer) {
this.rendersWithoutAdServer = rendersWithoutAdServer;
}

public String getImpressionUrl() {
return impressionUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public class BidResponse {
private boolean topBidFiltered;
@Nullable
private Bid promotedWinningBid;
@Nullable
private Bid selectedWinningBid;
@Nullable
private MobileSdkPassThrough rootMobilePassThrough;

private long creationTime;

Expand Down Expand Up @@ -152,7 +156,6 @@ private void parseJson(String json) {
customData = responseJson.optString("customdata");
nbr = responseJson.optInt("nbr", -1);

MobileSdkPassThrough rootMobilePassThrough = null;
if (responseJson.has("ext")) {
ext = new Ext();
JSONObject extJsonObject = responseJson.optJSONObject("ext");
Expand Down Expand Up @@ -199,6 +202,11 @@ public long getCreationTime() {

@Nullable
public Bid getWinningBid() {
if (selectedWinningBid != null) {
winningBidJson = selectedWinningBid.getJsonString();
return selectedWinningBid;
}

if (promotedWinningBid != null) {
winningBidJson = promotedWinningBid.getJsonString();
return promotedWinningBid;
Expand All @@ -222,6 +230,11 @@ public Bid getWinningBid() {

@NonNull
public HashMap<String, String> getTargeting() {
if (selectedWinningBid != null) {
// The bids that lost contribute no keys
return new HashMap<>(selectedWinningBid.getPrebid().getTargeting());
}

HashMap<String, String> keywords = new HashMap<>();
for (Seatbid seatbid : seatbids) {
for (Bid bid : seatbid.getBids()) {
Expand Down Expand Up @@ -298,11 +311,51 @@ public AdUnitConfiguration getAdUnitConfiguration() {
return adUnitConfiguration;
}

private boolean hasWinningKeywords(Prebid prebid) {
/**
* The bids of this response the ad unit can use, in response order. Uncached bids are already
* gone when {@link #isFilteringUncachedBids()}.
*/
@NonNull
List<Bid> getAllBids() {
List<Bid> bids = new ArrayList<>();
if (seatbids == null) {
return bids;
}
for (Seatbid seatbid : seatbids) {
bids.addAll(seatbid.getBids());
}
return bids;
}

/**
* Makes {@code bid}, which a bid selector chose from {@link #getAllBids()}, the winner of this
* response. The targeting is the selected bid's alone, and the cached-bid promotion no longer
* applies.
*/
void commitSelectedBid(@NonNull Bid bid) {
selectedWinningBid = bid;
winningBidJson = bid.getJsonString();
promotedWinningBid = null;
topBidFiltered = false;
mobileSdkPassThrough = MobileSdkPassThrough.combine(bid.getMobileSdkPassThrough(), rootMobilePassThrough);
}

/**
* Whether a winner must have {@code hb_cache_id}: the Original API, or cache reporting with the
* Rendering API.
*/
boolean usesCache() {
return usesCache;
}

/**
* Whether {@code prebid} has the keys that make a bid the winner of its impression.
*/
boolean hasWinningKeywords(Prebid prebid) {
if (!hasDesignatedWinningKeywords(prebid)) {
return false;
}
return !usesCache || prebid.getTargeting().containsKey("hb_cache_id");
return !usesCache || prebid.getTargeting().containsKey(TargetingKey.CACHE_ID);
}

/**
Expand All @@ -315,7 +368,7 @@ private static boolean hasDesignatedWinningKeywords(@Nullable Prebid prebid) {
return false;
}
HashMap<String, String> targeting = prebid.getTargeting();
return targeting.containsKey("hb_pb") && targeting.containsKey("hb_bidder");
return targeting.containsKey(TargetingKey.PRICE) && targeting.containsKey(TargetingKey.BIDDER);
}

private boolean keepBidWithSuccessfulCache(@NonNull Bid bid) {
Expand Down
Loading