diff --git a/Example/PrebidDemoJava/build.gradle b/Example/PrebidDemoJava/build.gradle index cf6ccf042..39f11d41b 100644 --- a/Example/PrebidDemoJava/build.gradle +++ b/Example/PrebidDemoJava/build.gradle @@ -38,7 +38,7 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.1.4' // Ads - implementation 'com.google.android.gms:play-services-ads:+' + implementation libs.google.play.services.ads // Video Player implementation 'com.google.android.exoplayer:exoplayer:2.15.1' diff --git a/Example/PrebidDemoKotlin/build.gradle b/Example/PrebidDemoKotlin/build.gradle index 2249c450d..cc6b31cc1 100644 --- a/Example/PrebidDemoKotlin/build.gradle +++ b/Example/PrebidDemoKotlin/build.gradle @@ -46,7 +46,7 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1' // Advertisement - implementation 'com.google.android.gms:play-services-ads:+' + implementation libs.google.play.services.ads implementation "com.applovin:applovin-sdk:11.5.3" implementation "com.google.android.gms:play-services-ads-identifier:18.0.1" // For Applovin Max diff --git a/Example/PrebidInternalTestApp/build.gradle b/Example/PrebidInternalTestApp/build.gradle index 1ef79b7a8..e59fcb314 100644 --- a/Example/PrebidInternalTestApp/build.gradle +++ b/Example/PrebidInternalTestApp/build.gradle @@ -84,7 +84,7 @@ dependencies { // Ad dependencies implementation 'com.google.android.gms:play-services-base:18.1.0' - implementation 'com.google.android.gms:play-services-ads:+' + implementation libs.google.play.services.ads implementation "com.applovin:applovin-sdk:11.3.2" implementation "com.google.android.gms:play-services-ads-identifier:18.0.1" // For Applovin Max diff --git a/PrebidMobile/PrebidMobile-admobAdapters/build.gradle b/PrebidMobile/PrebidMobile-admobAdapters/build.gradle index 84b67e1c5..0b9286692 100644 --- a/PrebidMobile/PrebidMobile-admobAdapters/build.gradle +++ b/PrebidMobile/PrebidMobile-admobAdapters/build.gradle @@ -10,5 +10,5 @@ android { dependencies { implementation project(":PrebidMobile") - implementation 'com.google.android.gms:play-services-ads:+' + implementation libs.google.play.services.ads } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java index d63696c5e..a522a19a0 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java @@ -403,6 +403,11 @@ public void setGpid(@Nullable String gpid) { configuration.setGpid(gpid); } + @Nullable + public String getOrtbConfig() { return configuration.getOrtbConfig();} + + public void setOrtbConfig(@Nullable String ortbConfig) {configuration.setOrtbConfig(ortbConfig);} + protected BidRequesterListener createBidListener(OnCompleteListener originalListener) { return new BidRequesterListener() { @Override diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerAdUnit.java index c628e5425..f8940733d 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerAdUnit.java @@ -17,6 +17,7 @@ package org.prebid.mobile; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import org.prebid.mobile.api.data.AdFormat; import org.prebid.mobile.api.data.AdUnitFormat; @@ -52,4 +53,13 @@ HashSet getSizes() { return configuration.getSizes(); } + @Nullable + public String getOrtbConfig() { + return configuration.getOrtbConfig(); + } + + public void setOrtbConfig(@Nullable String ortbConfig) { + configuration.setOrtbConfig(ortbConfig); + } + } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerBaseAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerBaseAdUnit.java index dc9d5505f..fb2892584 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerBaseAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerBaseAdUnit.java @@ -79,6 +79,15 @@ public Parameters getParameters() { return null; } + @Nullable + public String getOrtbConfig() { + return configuration.getOrtbConfig(); + } + + public void setOrtbConfig(@Nullable String ortbConfig) { + configuration.setOrtbConfig(ortbConfig); + } + /** * Describes an OpenRTB banner object */ diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InStreamVideoAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InStreamVideoAdUnit.java index d455106f0..3f365ce7c 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InStreamVideoAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InStreamVideoAdUnit.java @@ -17,6 +17,7 @@ package org.prebid.mobile; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import org.prebid.mobile.api.data.AdFormat; diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InterstitialAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InterstitialAdUnit.java index df3b119ef..7e8d2f145 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InterstitialAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InterstitialAdUnit.java @@ -18,6 +18,7 @@ import androidx.annotation.IntRange; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import org.prebid.mobile.api.data.AdFormat; import org.prebid.mobile.api.data.AdUnitFormat; @@ -59,4 +60,13 @@ public void setMinSizePercentage( configuration.setMinSizePercentage(new AdSize(width, height)); } + @Nullable + public String getOrtbConfig() { + return configuration.getOrtbConfig(); + } + + public void setOrtbConfig(@Nullable String ortbConfig) { + configuration.setOrtbConfig(ortbConfig); + } + } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/NativeAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/NativeAdUnit.java index 9e5414936..f3cfd7299 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/NativeAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/NativeAdUnit.java @@ -1,6 +1,7 @@ package org.prebid.mobile; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import org.json.JSONObject; @@ -212,4 +213,10 @@ public NativeAdUnitConfiguration getNativeConfiguration() { return nativeConfiguration; } + @Nullable + public String getOrtbConfig() {return configuration.getOrtbConfig();} + + public void setOrtbConfig(@Nullable String ortbConfig) {configuration.setOrtbConfig(ortbConfig);} + + } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/VideoBaseAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/VideoBaseAdUnit.java index 12012324f..d41d20162 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/VideoBaseAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/VideoBaseAdUnit.java @@ -39,6 +39,11 @@ public void setVideoParameters(@Nullable VideoParameters parameters) { configuration.setVideoParameters(parameters); } + @Nullable + public String getOrtbConfig() { return configuration.getOrtbConfig(); } + + public void setOrtbConfig(@Nullable String ortbConfig) { configuration.setOrtbConfig(ortbConfig);} + /** * @deprecated use `setVideoParameters()` */ diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/mediation/MediationBaseAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/mediation/MediationBaseAdUnit.java index 4e718b951..f2da65a60 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/mediation/MediationBaseAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/mediation/MediationBaseAdUnit.java @@ -318,4 +318,13 @@ private void cancelRefresh() { } } + @Nullable + public String getOrtbConfig() { + return adUnitConfig.getOrtbConfig(); + } + + public void setOrtbConfig(@Nullable String ortbConfig) { + adUnitConfig.setOrtbConfig(ortbConfig); + } + } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BannerView.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BannerView.java index 242c9d238..a295fba6a 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BannerView.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BannerView.java @@ -684,6 +684,15 @@ public BidResponse getBidResponse() { return bidResponse; } + @Nullable + public String getOrtbConfig() { + return adUnitConfig.getOrtbConfig(); + } + + public void setOrtbConfig(@Nullable String ortbConfig) { + adUnitConfig.setOrtbConfig(ortbConfig); + } + //region ==================== HelperMethods for Unit Tests. Should be used only in tests @VisibleForTesting final void setBidResponse(BidResponse response) { diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BaseInterstitialAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BaseInterstitialAdUnit.java index cd4d27bbb..e3b7ffb24 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BaseInterstitialAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BaseInterstitialAdUnit.java @@ -278,6 +278,15 @@ public void clearUserData() { adUnitConfig.clearUserData(); } + @Nullable + public String getOrtbConfig() { + return adUnitConfig.getOrtbConfig(); + } + + public void setOrtbConfig(@Nullable String ortbConfig) { + adUnitConfig.setOrtbConfig(ortbConfig); + } + @Nullable public String getPbAdSlot() { diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/DisplayView.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/DisplayView.java index 868f79d8d..c89fcca93 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/DisplayView.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/DisplayView.java @@ -21,6 +21,7 @@ import android.widget.FrameLayout; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import org.prebid.mobile.rendering.bidding.listeners.DisplayVideoListener; import org.prebid.mobile.api.rendering.pluginrenderer.PrebidMobilePluginRegister; @@ -86,4 +87,13 @@ public void destroy() { displayViewListener = null; displayVideoListener = null; } + + @Nullable + public String getOrtbConfig() { + return adUnitConfiguration.getOrtbConfig(); + } + + public void setOrtbConfig(@Nullable String ortbConfig) { + adUnitConfiguration.setOrtbConfig(ortbConfig); + } } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/PrebidDisplayView.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/PrebidDisplayView.java index 31ccb90be..939514811 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/PrebidDisplayView.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/PrebidDisplayView.java @@ -327,4 +327,13 @@ private static BidResponse getBidResponseFromCache(String id) throws AdException return cachedResponse; } + @Nullable + public String getOrtbConfig() { + return adUnitConfiguration.getOrtbConfig(); + } + + public void setOrtbConfig(@Nullable String ortbConfig) { + adUnitConfiguration.setOrtbConfig(ortbConfig); + } + } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/configuration/AdUnitConfiguration.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/configuration/AdUnitConfiguration.java index 882f6bba9..3ca8c41b7 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/configuration/AdUnitConfiguration.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/configuration/AdUnitConfiguration.java @@ -57,6 +57,8 @@ public class AdUnitConfiguration { private String fingerprint = Utils.generateUUIDTimeBased(); @Nullable private String gpid; + @Nullable + private String ortbConfig; private Position closeButtonPosition = Position.TOP_RIGHT; private Position skipButtonPosition = Position.TOP_RIGHT; @@ -540,6 +542,15 @@ public void setGpid(@Nullable String gpid) { this.gpid = gpid; } + @Nullable + public String getOrtbConfig() { + return ortbConfig; + } + + public void setOrtbConfig(@Nullable String ortbConfig) { + this.ortbConfig = ortbConfig; + } + @Override public boolean equals(Object o) { if (this == o) { diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/BidRequest.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/BidRequest.java index 6f3e1df3b..5ee282ba3 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/BidRequest.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/BidRequest.java @@ -18,15 +18,18 @@ import android.text.TextUtils; +import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.prebid.mobile.LogUtil; import org.prebid.mobile.PrebidMobile; import org.prebid.mobile.rendering.models.openrtb.bidRequests.*; import org.prebid.mobile.rendering.models.openrtb.bidRequests.source.Source; import java.util.ArrayList; +import java.util.Iterator; public class BidRequest extends BaseBid { @@ -37,12 +40,17 @@ public class BidRequest extends BaseBid { private Regs regs = null; private User user = null; private Source source = null; - + @Nullable + private JSONObject arbitraryJSONConfig; + @Nullable + private String ortbConfig; private Ext ext = null; public JSONObject getJsonObject() throws JSONException { JSONObject jsonObject = new JSONObject(); - + if (arbitraryJSONConfig != null) { + deepMerge(arbitraryJSONConfig, jsonObject); + } if (imps != null && imps.size() > 0) { JSONArray jsonArray = new JSONArray(); @@ -62,10 +70,71 @@ public JSONObject getJsonObject() throws JSONException { toJSON(jsonObject, "source", source != null ? source.getJsonObject() : null); toJSON(jsonObject, "ext", ext != null ? ext.getJsonObject() : null); toJSON(jsonObject, "test", PrebidMobile.getPbsDebug() ? 1 : null); - + jsonObject = mergeOrtbConfig(jsonObject); return jsonObject; } + private JSONObject mergeOrtbConfig(JSONObject bidRequestJson) { + try { + if (ortbConfig == null) { + return bidRequestJson; + } + JSONObject ortbConfigObject = new JSONObject(ortbConfig); + //remove protected fields + if (ortbConfigObject.has("regs")) { + ortbConfigObject.remove("regs"); + } + if (ortbConfigObject.has("device")) { + ortbConfigObject.remove("device"); + } + if (ortbConfigObject.has("geo")) { + ortbConfigObject.remove("geo"); + } + if (ortbConfigObject.has("ext")) { + if (ortbConfigObject.get("ext") instanceof JSONObject) { + ortbConfigObject.getJSONObject("ext").remove("gdpr"); + ortbConfigObject.getJSONObject("ext").remove("us_privacy"); + ortbConfigObject.getJSONObject("ext").remove("consent"); + } + } + return deepMerge(ortbConfigObject, bidRequestJson); + } catch(Exception e) { + LogUtil.error("ORTBConfig is not valid JSON"); + return bidRequestJson; + } + } + + /** + * Merge "source" into "target". If fields have equal name, merge them recursively. + * @return the merged object (target). + */ + private static JSONObject deepMerge(JSONObject source, JSONObject target) throws JSONException { + for (Iterator it = source.keys(); it.hasNext(); ) { + String key = it.next(); + Object value = source.get(key); + if (!target.has(key)) { + // new value for "key": + target.put(key, value); + } else { + // existing value for "key" - recursively deep merge: + if (value instanceof JSONObject) { + JSONObject valueJson = (JSONObject) value; + deepMerge(valueJson, target.getJSONObject(key)); + } else if (value instanceof JSONArray) { + if (target.get(key) instanceof JSONArray) { + JSONArray sourceArray = (JSONArray) value; + for (int i = 0; i < sourceArray.length(); i++) { + target.getJSONArray(key).put(sourceArray.getJSONObject(i)); + } + } + } else { + target.put(key, value); + } + } + } + return target; + } + // Accessors to prevent NPE while maintaining null if object is not set // App @@ -156,4 +225,22 @@ public Ext getExt() { } return ext; } + + @Nullable + public JSONObject getArbitraryConfig() { + return arbitraryJSONConfig; + } + + public void setArbitraryConfig(@Nullable JSONObject config) { + this.arbitraryJSONConfig = config; + } + + @Nullable + public String getOrtbConfig() { + return ortbConfig; + } + + public void setOrtbConfig(@Nullable String ortbConfig) { + this.ortbConfig = ortbConfig; + } } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/mraid/methods/MraidExpand.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/mraid/methods/MraidExpand.java index 3a601e458..c303e51b7 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/mraid/methods/MraidExpand.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/mraid/methods/MraidExpand.java @@ -108,6 +108,7 @@ public void destroy() { if (expandedDialog != null) { expandedDialog.dismiss(); } + webViewBanner = null; } /** diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/modelcontrollers/Requester.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/modelcontrollers/Requester.java index d42704f73..c34f14a88 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/modelcontrollers/Requester.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/modelcontrollers/Requester.java @@ -19,6 +19,7 @@ import android.content.Context; import android.content.res.Resources; import android.os.AsyncTask; +import android.os.Looper; import org.prebid.mobile.LogUtil; import org.prebid.mobile.api.exceptions.AdException; @@ -85,7 +86,6 @@ public abstract class Requester { public void destroy() { if (networkTask != null) { networkTask.cancel(true); - networkTask.destroy(); } networkTask = null; if (fetchAdIdInfoTask != null) { diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilder.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilder.java index 7e5e83f9a..6115be378 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilder.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilder.java @@ -137,6 +137,7 @@ private void configureImpObject(Imp imp, String uuid) { private void configureBidRequest(BidRequest bidRequest, String uuid) { bidRequest.setId(uuid); + bidRequest.setOrtbConfig(adConfiguration.getOrtbConfig()); boolean isVideo = adConfiguration.isAdType(AdFormat.VAST); bidRequest.getExt().put("prebid", Prebid.getJsonObjectForBidRequest(PrebidMobile.getPrebidServerAccountId(), isVideo, adConfiguration)); //if coppaEnabled - set 1, else No coppa is sent diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/base/BaseAdView.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/base/BaseAdView.java index a7018c185..be5c8e2ff 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/base/BaseAdView.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/base/BaseAdView.java @@ -20,6 +20,9 @@ import android.util.AttributeSet; import android.view.View; import android.widget.FrameLayout; + +import androidx.annotation.Nullable; + import org.prebid.mobile.ContentObject; import org.prebid.mobile.LogUtil; import org.prebid.mobile.PrebidMobile; @@ -132,4 +135,15 @@ public void destroy() { eventForwardingReceiver = null; } } + + + @Nullable + public String getOrtbConfig() { + return adViewManager.getAdConfiguration().getOrtbConfig(); + } + + public void setOrtbConfig(@Nullable String ortbConfig) { + adViewManager.getAdConfiguration().setOrtbConfig(ortbConfig); + } + } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/webview/PrebidWebViewBase.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/webview/PrebidWebViewBase.java index 2e7f8edc8..7a6d87b7b 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/webview/PrebidWebViewBase.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/webview/PrebidWebViewBase.java @@ -27,6 +27,9 @@ import android.view.animation.AnimationUtils; import android.webkit.WebView; import android.widget.FrameLayout; + +import androidx.annotation.Nullable; + import org.prebid.mobile.LogUtil; import org.prebid.mobile.rendering.listeners.WebViewDelegate; import org.prebid.mobile.rendering.models.HTMLCreative; @@ -97,6 +100,8 @@ public void destroy() { // We need to give OMID time to finish method execution inside the webview handler.removeCallbacksAndMessages(null); handler.postDelayed(new WebViewCleanupRunnable(currentWebView), WEBVIEW_DESTROY_DELAY_MS); + webView = null; + mraidWebView = null; } public void initMraidExpanded() { diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/webview/mraid/BaseJSInterface.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/webview/mraid/BaseJSInterface.java index 9c97aaad9..aacd87ec5 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/webview/mraid/BaseJSInterface.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/webview/mraid/BaseJSInterface.java @@ -56,6 +56,8 @@ import org.prebid.mobile.rendering.views.webview.WebViewBase; import java.lang.ref.WeakReference; +import java.util.concurrent.FutureTask; +import java.util.concurrent.RunnableFuture; @SuppressLint("NewApi") public class BaseJSInterface implements JSInterface { @@ -119,9 +121,11 @@ public String getMaxSize() { JSONObject maxSize = new JSONObject(); try { final Rect currentMaxSizeRect = screenMetrics.getCurrentMaxSizeRect(); - maxSize.put(JSON_WIDTH, currentMaxSizeRect.width()); - maxSize.put(JSON_HEIGHT, currentMaxSizeRect.height()); - return maxSize.toString(); + if (currentMaxSizeRect != null) { + maxSize.put(JSON_WIDTH, currentMaxSizeRect.width()); + maxSize.put(JSON_HEIGHT, currentMaxSizeRect.height()); + return maxSize.toString(); + } } catch (Exception e) { LogUtil.error(TAG, "Failed getMaxSize() for MRAID: " + Log.getStackTraceString(e)); @@ -171,10 +175,12 @@ public String getDefaultPosition() { public String getCurrentPosition() { JSONObject position = new JSONObject(); Rect rect = new Rect(); - - adBaseView.getGlobalVisibleRect(rect); - + Handler mainHandler = new Handler(Looper.getMainLooper()); + Runnable mainThreadRunnable = () -> adBaseView.getGlobalVisibleRect(rect); + RunnableFuture task = new FutureTask<>(mainThreadRunnable, null); try { + mainHandler.post(task); + task.get(); position.put(JSON_X, (int) (rect.left / Utils.DENSITY)); position.put(JSON_Y, (int) (rect.top / Utils.DENSITY)); position.put(JSON_WIDTH, (int) (rect.right / Utils.DENSITY - rect.left / Utils.DENSITY)); diff --git a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilderTest.java b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilderTest.java index e69666b02..e0712fae2 100644 --- a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilderTest.java +++ b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilderTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.prebid.mobile.rendering.networking.parameters.BasicParameterBuilder.KEY_OM_PARTNER_NAME; import static org.prebid.mobile.rendering.networking.parameters.BasicParameterBuilder.KEY_OM_PARTNER_VERSION; import static org.prebid.mobile.rendering.networking.parameters.BasicParameterBuilder.VIDEO_INTERSTITIAL_PLAYBACK_END; @@ -30,6 +31,7 @@ import android.app.Activity; import android.content.Context; import android.content.res.Configuration; +import android.util.Log; import com.google.common.collect.Sets; @@ -322,6 +324,76 @@ public void setGpid_gpidPresentInRequest() { assertEquals(expectedGpid, gpid); } + @Test + public void setOrtbConfig_configPresentInRequest() { + AdUnitConfiguration adConfiguration = new AdUnitConfiguration(); + String ortbConfig = "{\"arbitraryparamkey1\":\"arbitraryparamvalue1\",\"ext\":{\"otherExtParam\":\"otherParam\"}}"; + adConfiguration.setOrtbConfig(ortbConfig); + + BasicParameterBuilder builder = new BasicParameterBuilder( + adConfiguration, + context.getResources(), + browserActivityAvailable + ); + AdRequestInput adRequestInput = new AdRequestInput(); + builder.appendBuilderParameters(adRequestInput); + + BidRequest actualBidRequest = adRequestInput.getBidRequest(); + try { + assertEquals("arbitraryparamvalue1", actualBidRequest.getJsonObject().getString("arbitraryparamkey1")); + assertEquals("otherParam", actualBidRequest.getJsonObject().getJSONObject("ext").getString("otherExtParam")); + } catch (Exception e) { + fail(); + } + } + + @Test + public void setOrtbConfig_invalidJSONInRequest() { + AdUnitConfiguration adConfiguration = new AdUnitConfiguration(); + String ortbConfig = "\"arbitraryparamkey1\":\"arbitraryparamvalue1\"}"; + adConfiguration.setOrtbConfig(ortbConfig); + + BasicParameterBuilder builder = new BasicParameterBuilder( + adConfiguration, + context.getResources(), + browserActivityAvailable + ); + AdRequestInput adRequestInput = new AdRequestInput(); + builder.appendBuilderParameters(adRequestInput); + + BidRequest actualBidRequest = adRequestInput.getBidRequest(); + try { + assertFalse(actualBidRequest.getJsonObject().has("arbitraryparamkey1"));; + } catch (Exception e) { + fail(); + } + } + + @Test + public void setOrtbConfig_illegalParametersPresentInRequest() { + AdUnitConfiguration adConfiguration = new AdUnitConfiguration(); + String ortbConfig = "{\"arbitraryparamkey1\":\"arbitraryparamvalue1\", \"regs\": \"no regs here\", \"ext\":{\"gdpr\":\"no GDPR here\", \"otherExtParam\":\"otherParam\"}}"; + adConfiguration.setOrtbConfig(ortbConfig); + + BasicParameterBuilder builder = new BasicParameterBuilder( + adConfiguration, + context.getResources(), + browserActivityAvailable + ); + AdRequestInput adRequestInput = new AdRequestInput(); + builder.appendBuilderParameters(adRequestInput); + + BidRequest actualBidRequest = adRequestInput.getBidRequest(); + try { + assertEquals("arbitraryparamvalue1", actualBidRequest.getJsonObject().getString("arbitraryparamkey1")); + assertEquals("otherParam", actualBidRequest.getJsonObject().getJSONObject("ext").getString("otherExtParam")); + assertFalse(actualBidRequest.getJsonObject().getJSONObject("ext").has("gdpr")); + assertFalse(actualBidRequest.getJsonObject().has("regs")); + } catch (Exception e) { + fail(); + } + } + @Test public void whenAppendParametersAndBInterstitialType_ImpWithValidBannerObject() throws JSONException { diff --git a/PrebidMobile/PrebidMobile-gamEventHandlers/build.gradle b/PrebidMobile/PrebidMobile-gamEventHandlers/build.gradle index 84b67e1c5..0b9286692 100644 --- a/PrebidMobile/PrebidMobile-gamEventHandlers/build.gradle +++ b/PrebidMobile/PrebidMobile-gamEventHandlers/build.gradle @@ -10,5 +10,5 @@ android { dependencies { implementation project(":PrebidMobile") - implementation 'com.google.android.gms:play-services-ads:+' + implementation libs.google.play.services.ads } diff --git a/PrebidMobile/PrebidMobile-gamEventHandlers/src/test/java/org/prebid/mobile/eventhandlers/global/GoogleAdVersionTest.java b/PrebidMobile/PrebidMobile-gamEventHandlers/src/test/java/org/prebid/mobile/eventhandlers/global/GoogleAdVersionTest.java index f6fd647dc..dabcbd54e 100644 --- a/PrebidMobile/PrebidMobile-gamEventHandlers/src/test/java/org/prebid/mobile/eventhandlers/global/GoogleAdVersionTest.java +++ b/PrebidMobile/PrebidMobile-gamEventHandlers/src/test/java/org/prebid/mobile/eventhandlers/global/GoogleAdVersionTest.java @@ -20,7 +20,8 @@ public void checkIfLastVersionUsed() { assertEquals( "Google Ad SDK was updated to " + currentVersion + "! " + "Please test Prebid SDK with the new version, resolve compilation problems, rewrite deprecated code. " + - "After testing you must update PrebidMobile.TESTED_GOOGLE_SDK_VERSION" + + "After testing you must update PrebidMobile.TESTED_GOOGLE_SDK_VERSION," + + "update google-play-services-ads version on the libs.versions.toml " + "and also must update version in publishing XML files (scripts/Maven/*.xml.", currentVersion, PrebidMobile.TESTED_GOOGLE_SDK_VERSION diff --git a/README.md b/README.md index 6d2f173e5..bac179078 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ See [this page](https://docs.prebid.org/prebid-server/overview/prebid-server-ove Easily include the Prebid Mobile SDK using Maven. Simply add this line to your gradle dependencies: ``` -implementation 'org.prebid:prebid-mobile-sdk:2.1.9' +implementation 'org.prebid:prebid-mobile-sdk:2.2.0' ``` ## Build from source diff --git a/build.gradle b/build.gradle index bbb0dd2ec..7ac072ce8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ ext { - prebidSdkVersionName = "2.1.9" + prebidSdkVersionName = "2.2.0" prebidSdkMinVersion = 16 prebidSdkTargetVersion = 33 prebidSdkCompileVersion = 33 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 000000000..dac328158 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,5 @@ +[versions] +google-play-services-ads = "22.6.0" + +[libraries] +google-play-services-ads = { group = "com.google.android.gms", name = "play-services-ads", version.ref = "google-play-services-ads" } diff --git a/scripts/Maven/PrebidMobile-admobAdapters-pom.xml b/scripts/Maven/PrebidMobile-admobAdapters-pom.xml index b7ba31f4a..3cda0d297 100644 --- a/scripts/Maven/PrebidMobile-admobAdapters-pom.xml +++ b/scripts/Maven/PrebidMobile-admobAdapters-pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.prebid prebid-mobile-sdk-admob-adapters - 2.1.9 + 2.2.0 jar Prebid Mobile Android SDK @@ -52,7 +52,7 @@ org.prebid prebid-mobile-sdk - 2.1.9 + 2.2.0 compile diff --git a/scripts/Maven/PrebidMobile-core-pom.xml b/scripts/Maven/PrebidMobile-core-pom.xml index b6c66713f..b8115efec 100644 --- a/scripts/Maven/PrebidMobile-core-pom.xml +++ b/scripts/Maven/PrebidMobile-core-pom.xml @@ -6,7 +6,7 @@ org.prebid prebid-mobile-sdk-core - 2.1.9 + 2.2.0 aar Prebid Mobile Android SDK Prebid Mobile diff --git a/scripts/Maven/PrebidMobile-gamEventHandlers-pom.xml b/scripts/Maven/PrebidMobile-gamEventHandlers-pom.xml index 9b11773ce..de79a18a1 100644 --- a/scripts/Maven/PrebidMobile-gamEventHandlers-pom.xml +++ b/scripts/Maven/PrebidMobile-gamEventHandlers-pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.prebid prebid-mobile-sdk-gam-event-handlers - 2.1.9 + 2.2.0 jar Prebid Mobile Android SDK @@ -52,7 +52,7 @@ org.prebid prebid-mobile-sdk - 2.1.9 + 2.2.0 compile diff --git a/scripts/Maven/PrebidMobile-maxAdapters-pom.xml b/scripts/Maven/PrebidMobile-maxAdapters-pom.xml index 3a3c46357..274eb6fa8 100644 --- a/scripts/Maven/PrebidMobile-maxAdapters-pom.xml +++ b/scripts/Maven/PrebidMobile-maxAdapters-pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.prebid prebid-mobile-sdk-max-adapters - 2.1.9 + 2.2.0 jar Prebid Mobile Android SDK @@ -52,7 +52,7 @@ org.prebid prebid-mobile-sdk - 2.1.9 + 2.2.0 compile diff --git a/scripts/Maven/PrebidMobile-pom.xml b/scripts/Maven/PrebidMobile-pom.xml index b20869b2c..bbbc917ca 100644 --- a/scripts/Maven/PrebidMobile-pom.xml +++ b/scripts/Maven/PrebidMobile-pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.prebid prebid-mobile-sdk - 2.1.9 + 2.2.0 jar Prebid Mobile Android SDK @@ -52,7 +52,7 @@ org.prebid prebid-mobile-sdk-core - 2.1.9 + 2.2.0 compile