Skip to content

Commit

Permalink
Rendering controls settings from bid responses (#424)
Browse files Browse the repository at this point in the history
* feat: add rendering control settings from bid response #422

* feat: add ad configuration examples #422

Add temporary examples debug support.

* test: add tests for MobileSdkPassThrough and BidResponse #422

Change debug tests to release ones.
  • Loading branch information
ValentinPostindustria authored Apr 26, 2022
1 parent e0208c6 commit fbb4368
Show file tree
Hide file tree
Showing 11 changed files with 515 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,32 @@ class DemoItemProvider private constructor() {
)
)
)
demoList.add(
DemoItem(
getString(R.string.demo_bidding_in_app_interstitial_video_320_480_with_ad_configuration),
ppmInterstitialAction,
ppmVideoTagList,
createBannerBundle(
R.string.imp_prebid_id_video_interstitial_320_480,
null,
320, 480,
R.string.response_prebid_video_interstitial_ad_configuration
)
)
)
demoList.add(
DemoItem(
getString(R.string.demo_bidding_in_app_interstitial_video_320_480_end_card_with_ad_configuration),
ppmInterstitialAction,
ppmVideoTagList,
createBannerBundle(
R.string.imp_prebid_id_video_interstitial_320_480_with_end_card,
null,
320, 480,
R.string.response_prebid_video_interstitial_end_card_ad_configuration
)
)
)

demoList.add(
DemoItem(
Expand Down Expand Up @@ -516,16 +542,37 @@ class DemoItemProvider private constructor() {
R.string.imp_prebid_id_video_rewarded_end_card_320_480,
null,
MIN_WIDTH_PERC,
MIN_HEIGHT_PERC,R.string.response_prebid_video_rewarded_320_480
MIN_HEIGHT_PERC, R.string.response_prebid_video_rewarded_320_480
)
)
)
demoList.add(
DemoItem(
getString(R.string.demo_bidding_in_app_video_rewarded_320_480_with_ad_configuration),
ppmRewardedAction,
ppmVideoTagList,
createBannerBundle(
R.string.imp_prebid_id_video_rewarded_end_card_320_480,
null,
MIN_WIDTH_PERC,
MIN_HEIGHT_PERC, R.string.response_prebid_video_rewarded_320_480_with_ad_configuration
)
)
)


demoList.add(
DemoItem(
getString(R.string.demo_bidding_in_app_banner_video_outstream),
R.id.action_header_bidding_to_in_app_banner_video,
ppmVideoTagList,
createBannerBundle(R.string.imp_prebid_id_video_outstream, null, 300, 250,R.string.response_prebid_video_outstream)
createBannerBundle(
R.string.imp_prebid_id_video_outstream,
null,
300,
250,
R.string.response_prebid_video_outstream
)
)
)
demoList.add(
Expand Down
6 changes: 6 additions & 0 deletions Example/PrebidInternalTestApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@
<string name="demo_bidding_in_app_interstitial_video_320_480_end_card_skip_button">Video Interstitial 320x480 With End Card and Skip Button (In-App)</string>
<string name="demo_bidding_in_app_interstitial_video_320_480_mraid_end_card">Video Interstitial 320x480 with MRAID End Card (In-App)</string>
<string name="demo_bidding_in_app_interstitial_video_320_480_no_bids">Video Interstitial 320x480 (In-App) [noBids]</string>
<string name="demo_bidding_in_app_interstitial_video_320_480_with_ad_configuration">Video Interstitial 320x480 With Ad Configuration (In-App)</string>
<string name="demo_bidding_in_app_interstitial_video_320_480_end_card_with_ad_configuration">Video Interstitial 320x480 With End Card With Ad Configuration (In-App)</string>
<string name="demo_bidding_in_app_video_rewarded_end_card_320_480">Video Rewarded 320x480 (In-App)</string>
<string name="demo_bidding_in_app_video_rewarded_end_card_320_480_no_bids">Video Rewarded 320x480 with End Card (In-App) [noBids]</string>
<string name="demo_bidding_in_app_video_rewarded_320_480">Video Rewarded 320x480 without End Card (In-App)</string>
<string name="demo_bidding_in_app_video_rewarded_320_480_with_ad_configuration">Video Rewarded 320x480 With Ad Configuration (In-App)</string>
<string name="demo_bidding_in_app_mraid_expand">MRAID 2.0: Expand - 1 Part (In-App)</string>
<string name="demo_bidding_in_app_mraid_expand_2">MRAID 2.0: Expand - 2 Part (In-App)</string>
<string name="demo_bidding_in_app_mraid_resize">MRAID 2.0: Resize (In-App)</string>
Expand Down Expand Up @@ -362,12 +365,15 @@
<string name="response_prebid_video_interstitial_320_480_with_end_card">response-prebid-video-interstitial-320-480-with-end-card</string>
<string name="response_prebid_video_interstitial_deeplink">response-prebid-video-interstitial-320-480-deeplink</string>
<string name="response_prebid_video_interstitial_skipoffset">response-prebid-video-interstitial-320-480-skip-offset</string>
<string name="response_prebid_video_interstitial_ad_configuration">response-prebid-video-interstitial-320-480-with-ad-configuration</string>
<string name="response_prebid_video_interstitial_end_card_ad_configuration">response-prebid-video-interstitial-320-480-with-end-card-with-ad-configuration</string>
<!-- Video Outstream -->
<string name="response_prebid_video_outstream">response-prebid-video-outstream</string>
<string name="response_prebid_video_outstream_end_card">response-prebid-video-outstream-with-end-card</string>
<!-- Video Rewarded -->
<string name="response_prebid_video_rewarded_end_card_320_480">response-prebid-video-rewarded-320-480-without-end-card</string>
<string name="response_prebid_video_rewarded_320_480">response-prebid-video-rewarded-320-480</string>
<string name="response_prebid_video_rewarded_320_480_with_ad_configuration">response-prebid-video-rewarded-320-480-with-ad-configuration</string>

<!-- MRAID -->
<string name="response_prebid_mraid_resize">response-prebid-mraid-resize</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.json.JSONArray;
import org.json.JSONObject;
import org.prebid.mobile.rendering.models.internal.MacrosModel;
import org.prebid.mobile.rendering.models.openrtb.bidRequests.MobileSdkPassThrough;
import org.prebid.mobile.rendering.utils.helpers.MacrosResolutionHelper;

import java.util.HashMap;
Expand Down Expand Up @@ -125,6 +126,8 @@ public class Bid {
// wait between the auction and the actual impression
private int mExp;

private MobileSdkPassThrough mobileSdkPassThrough;

protected Bid() {
}

Expand Down Expand Up @@ -243,6 +246,10 @@ public String getJsonString() {
return jsonString;
}

public MobileSdkPassThrough getMobileSdkPassThrough() {
return mobileSdkPassThrough;
}

public static Bid fromJSONObject(JSONObject jsonObject) {
Bid bid = new Bid();
if (jsonObject == null) {
Expand Down Expand Up @@ -280,6 +287,7 @@ public static Bid fromJSONObject(JSONObject jsonObject) {
JSONObject ext = jsonObject.optJSONObject("ext");
if (ext != null) {
bid.mPrebid = Prebid.fromJSONObject(ext.optJSONObject("prebid"));
bid.mobileSdkPassThrough = MobileSdkPassThrough.create(ext);
}

substituteMacros(bid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.json.JSONObject;
import org.prebid.mobile.LogUtil;
import org.prebid.mobile.rendering.models.openrtb.bidRequests.Ext;
import org.prebid.mobile.rendering.models.openrtb.bidRequests.MobileSdkPassThrough;
import org.prebid.mobile.rendering.utils.helpers.Dips;
import org.prebid.mobile.rendering.utils.helpers.Utils;

Expand Down Expand Up @@ -61,6 +62,8 @@ public class BidResponse {

private long mCreationTime;

private MobileSdkPassThrough mobileSdkPassThrough;

public BidResponse(String json) {
mSeatbids = new ArrayList<>();
parseJson(json);
Expand Down Expand Up @@ -120,9 +123,14 @@ private void parseJson(String json) {
mCustomData = responseJson.optString("customdata");
mNbr = responseJson.optInt("nbr", -1);

MobileSdkPassThrough rootMobilePassThrough = null;
if (responseJson.has("ext")) {
mExt = new Ext();
mExt.put(responseJson.optJSONObject("ext"));
JSONObject extJsonObject = responseJson.optJSONObject("ext");
mExt.put(extJsonObject);
if (extJsonObject != null) {
rootMobilePassThrough = MobileSdkPassThrough.create(extJsonObject);
}
}

JSONArray jsonSeatbids = responseJson.optJSONArray("seatbid");
Expand All @@ -132,12 +140,18 @@ private void parseJson(String json) {
mSeatbids.add(seatbid);
}
}
if (getWinningBid() == null) {

MobileSdkPassThrough bidMobilePassThrough = null;
Bid winningBid = getWinningBid();
if (winningBid == null) {
mHasParseError = true;
mParseError = "Failed to parse bids. No winning bids were found.";
LogUtil.info(TAG, mParseError);
} else {
bidMobilePassThrough = winningBid.getMobileSdkPassThrough();
}

mobileSdkPassThrough = MobileSdkPassThrough.combine(bidMobilePassThrough, rootMobilePassThrough);
mCreationTime = System.currentTimeMillis();
}
catch (JSONException e) {
Expand Down Expand Up @@ -220,4 +234,10 @@ public Pair<Integer, Integer> getWinningBidWidthHeightPairDips(Context context)
final int height = Dips.dipsToIntPixels(winningBid.getHeight(), context);
return new Pair<>(width, height);
}

@Nullable
public MobileSdkPassThrough getMobileSdkPassThrough() {
return mobileSdkPassThrough;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package org.prebid.mobile.rendering.bidding.loader;

import android.content.Context;
import androidx.annotation.Nullable;
import org.prebid.mobile.LogUtil;
import org.prebid.mobile.PrebidMobile;
import org.prebid.mobile.rendering.bidding.data.bid.BidResponse;
import org.prebid.mobile.rendering.bidding.listeners.BidRequesterListener;
import org.prebid.mobile.rendering.errors.AdException;
import org.prebid.mobile.rendering.models.openrtb.bidRequests.MobileSdkPassThrough;
import org.prebid.mobile.rendering.networking.BaseNetworkTask;
import org.prebid.mobile.rendering.networking.ResponseHandler;
import org.prebid.mobile.rendering.networking.modelcontrollers.BidRequester;
Expand Down Expand Up @@ -60,6 +62,7 @@ public void onResponse(BaseNetworkTask.GetUrlResult response) {
return;
}
checkTmax(response, bidResponse);
updateAdUnitConfiguration(bidResponse.getMobileSdkPassThrough());
if (mRequestListener != null) {
setupRefreshTimer();
mRequestListener.onFetchCompleted(bidResponse);
Expand Down Expand Up @@ -200,7 +203,10 @@ private void failedToLoadBid(String msg) {
mRequestListener.onError(new AdException(AdException.INTERNAL_ERROR, "Invalid bid response: " + msg));
}

private void checkTmax(BaseNetworkTask.GetUrlResult response, BidResponse parsedResponse) {
private void checkTmax(
BaseNetworkTask.GetUrlResult response,
BidResponse parsedResponse
) {
Map<String, Object> extMap = parsedResponse.getExt().getMap();
if (!sTimeoutHasChanged && extMap.containsKey(TMAX_REQUEST_KEY)) {
int tmaxRequest = (int) extMap.get(TMAX_REQUEST_KEY);
Expand All @@ -211,7 +217,16 @@ private void checkTmax(BaseNetworkTask.GetUrlResult response, BidResponse parsed
}
}

private void updateAdUnitConfiguration(@Nullable MobileSdkPassThrough mobileSdkPassThrough) {
if (mobileSdkPassThrough != null) {
mobileSdkPassThrough.modifyAdUnitConfiguration(mAdConfiguration);
}
}

public interface BidRefreshListener {

boolean canPerformRefresh();

}

}
Loading

0 comments on commit fbb4368

Please sign in to comment.