From 15763edaeb15b61599fd827571006b9f70b0f8d1 Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Wed, 23 Aug 2023 10:01:12 -0500 Subject: [PATCH 01/21] Found two places where the reference to the WebView was being held onto after destroy() was called. --- .../org/prebid/mobile/rendering/mraid/methods/MraidExpand.java | 1 + .../prebid/mobile/rendering/views/webview/PrebidWebViewBase.java | 1 + 2 files changed, 2 insertions(+) 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/views/webview/PrebidWebViewBase.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/webview/PrebidWebViewBase.java index 2e7f8edc8..d648ec87d 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 @@ -97,6 +97,7 @@ 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; } public void initMraidExpanded() { From 304888898d4b1e4324b277eea650bebda209eb95 Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Wed, 23 Aug 2023 10:01:12 -0500 Subject: [PATCH 02/21] Found two places where the reference to the WebView was being held onto after destroy() was called. --- .../org/prebid/mobile/rendering/mraid/methods/MraidExpand.java | 1 + .../prebid/mobile/rendering/views/webview/PrebidWebViewBase.java | 1 + 2 files changed, 2 insertions(+) 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/views/webview/PrebidWebViewBase.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/webview/PrebidWebViewBase.java index 2e7f8edc8..d648ec87d 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 @@ -97,6 +97,7 @@ 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; } public void initMraidExpanded() { From 94adfbae732d6bfeaf39392e1ee998a8cf6d7698 Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Thu, 11 Jan 2024 13:21:56 -0600 Subject: [PATCH 03/21] Added the networking task cancellation/destruction to a background thread. --- .../modelcontrollers/Requester.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) 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..557edbffb 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; @@ -82,10 +83,32 @@ public abstract class Requester { public abstract void startAdRequest(); + /** + * This Async task is needed because the networkTask needs to be cancelled / destroyed + * on a background thread or it throws a NetworkOnMainThreadException + **/ + private static class DestroyNetworkTaskAsyncTask extends AsyncTask { + + @Override + protected Void doInBackground(BaseNetworkTask... baseNetworkTasks) { + if (baseNetworkTasks.length > 0) { + if (baseNetworkTasks[0] != null) { + baseNetworkTasks[0].cancel(true); + baseNetworkTasks[0].destroy(); + } + } + return null; + } + } + public void destroy() { if (networkTask != null) { - networkTask.cancel(true); - networkTask.destroy(); + if(Looper.getMainLooper().getThread() == Thread.currentThread()) { + new DestroyNetworkTaskAsyncTask().execute(networkTask); + } else { + networkTask.cancel(true); + networkTask.destroy(); + } } networkTask = null; if (fetchAdIdInfoTask != null) { From c739139e30caa5537c662720d569567a0fdf1187 Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Wed, 17 Jan 2024 15:31:46 -0600 Subject: [PATCH 04/21] Run getGlobalVisibleRect on the main thread instead of a background thread. --- .../rendering/views/webview/mraid/BaseJSInterface.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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..778aad415 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 @@ -171,9 +171,8 @@ public String getDefaultPosition() { public String getCurrentPosition() { JSONObject position = new JSONObject(); Rect rect = new Rect(); - - adBaseView.getGlobalVisibleRect(rect); - + Handler mainHandler = new Handler(Looper.getMainLooper()); + mainHandler.post(() -> adBaseView.getGlobalVisibleRect(rect)); try { position.put(JSON_X, (int) (rect.left / Utils.DENSITY)); position.put(JSON_Y, (int) (rect.top / Utils.DENSITY)); From 875aa22521c6a596b8b64b238017fb0de1b0a40b Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Thu, 18 Jan 2024 11:27:31 -0600 Subject: [PATCH 05/21] Cleaning up mraidWebView as well just to make sure. --- .../prebid/mobile/rendering/views/webview/PrebidWebViewBase.java | 1 + 1 file changed, 1 insertion(+) 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 d648ec87d..f9c2c33e7 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 @@ -98,6 +98,7 @@ public void destroy() { handler.removeCallbacksAndMessages(null); handler.postDelayed(new WebViewCleanupRunnable(currentWebView), WEBVIEW_DESTROY_DELAY_MS); webView = null; + mraidWebView = null; } public void initMraidExpanded() { From ea55c5634115e0ec3bdf52b27278337e668767af Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Thu, 18 Jan 2024 11:37:09 -0600 Subject: [PATCH 06/21] Crash that does keep occurring in my testing. --- .../rendering/views/webview/mraid/BaseJSInterface.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 778aad415..730086fa3 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 @@ -119,9 +119,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)); From 50d4c662485fb56745cf23dec30a8e7ca19d5b98 Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Thu, 18 Jan 2024 12:39:18 -0600 Subject: [PATCH 07/21] Fixed to run synchronously. --- .../rendering/views/webview/mraid/BaseJSInterface.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 730086fa3..0d52976fc 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 { @@ -174,8 +176,10 @@ public String getCurrentPosition() { JSONObject position = new JSONObject(); Rect rect = new Rect(); Handler mainHandler = new Handler(Looper.getMainLooper()); - mainHandler.post(() -> adBaseView.getGlobalVisibleRect(rect)); + Runnable mainThreadRunnable = () -> adBaseView.getGlobalVisibleRect(rect); + RunnableFuture task = new FutureTask<>(mainThreadRunnable, null); try { + mainHandler.post(task); 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)); From cb275873bb552a769587488d7e95244631e06449 Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Thu, 18 Jan 2024 12:41:21 -0600 Subject: [PATCH 08/21] Forgot important step. --- .../mobile/rendering/views/webview/mraid/BaseJSInterface.java | 1 + 1 file changed, 1 insertion(+) 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 0d52976fc..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 @@ -180,6 +180,7 @@ public String getCurrentPosition() { 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)); From a36852862d25e3fce7993c55125f20128a8dae98 Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Fri, 19 Jan 2024 13:43:46 -0600 Subject: [PATCH 09/21] 2.2.0 changes --- build.gradle | 2 +- scripts/Maven/PrebidMobile-admobAdapters-pom.xml | 4 ++-- scripts/Maven/PrebidMobile-core-pom.xml | 2 +- scripts/Maven/PrebidMobile-gamEventHandlers-pom.xml | 4 ++-- scripts/Maven/PrebidMobile-maxAdapters-pom.xml | 4 ++-- scripts/Maven/PrebidMobile-pom.xml | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) 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/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 From b4ea7c43fad61606bd61a62ba0d34aa54a413a05 Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Fri, 19 Jan 2024 13:44:51 -0600 Subject: [PATCH 10/21] change readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 60d7438a1f419e426991e9c2b084719203a6c224 Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Tue, 30 Jan 2024 12:14:54 -0600 Subject: [PATCH 11/21] removing the redundant .destroy() call first. --- .../mobile/rendering/networking/modelcontrollers/Requester.java | 1 - 1 file changed, 1 deletion(-) 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 557edbffb..2ccee14ef 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 @@ -107,7 +107,6 @@ public void destroy() { new DestroyNetworkTaskAsyncTask().execute(networkTask); } else { networkTask.cancel(true); - networkTask.destroy(); } } networkTask = null; From 214bf166fc9899bbfe9dd103f3defd7c12b06bcb Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Tue, 20 Feb 2024 14:07:37 -0600 Subject: [PATCH 12/21] Added implementation and started writing tests. --- .../main/java/org/prebid/mobile/AdUnit.java | 5 ++ .../java/org/prebid/mobile/BannerAdUnit.java | 10 +++ .../org/prebid/mobile/BannerBaseAdUnit.java | 9 ++ .../prebid/mobile/InStreamVideoAdUnit.java | 1 + .../org/prebid/mobile/InterstitialAdUnit.java | 10 +++ .../java/org/prebid/mobile/NativeAdUnit.java | 7 ++ .../org/prebid/mobile/VideoBaseAdUnit.java | 5 ++ .../api/mediation/MediationBaseAdUnit.java | 9 ++ .../mobile/api/rendering/BannerView.java | 9 ++ .../api/rendering/BaseInterstitialAdUnit.java | 9 ++ .../mobile/api/rendering/DisplayView.java | 10 +++ .../api/rendering/PrebidDisplayView.java | 9 ++ .../configuration/AdUnitConfiguration.java | 11 +++ .../rendering/models/openrtb/BidRequest.java | 84 ++++++++++++++++++- .../parameters/BasicParameterBuilder.java | 1 + .../rendering/views/base/BaseAdView.java | 14 ++++ .../views/webview/PrebidWebViewBase.java | 3 + .../parameters/BasicParameterBuilderTest.java | 23 +++++ 18 files changed, 226 insertions(+), 3 deletions(-) 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..cedeb064c 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,62 @@ 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 { + assert ortbConfig != null; + 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 { + target.put(key, value); + } + } + } + return target; + } + // Accessors to prevent NPE while maintaining null if object is not set // App @@ -156,4 +216,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/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 f9c2c33e7..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; 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..ebf14f4ac 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; @@ -322,6 +323,28 @@ public void setGpid_gpidPresentInRequest() { assertEquals(expectedGpid, gpid); } + @Test + public void setOrtbConfig_configPresentInRequest() { + 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 { + assertEquals("arbitraryparamvalue1", actualBidRequest.getJsonObject().getString("arbitraryparamkey1")); + } catch (Exception e) { + fail(); + } + } + @Test public void whenAppendParametersAndBInterstitialType_ImpWithValidBannerObject() throws JSONException { From ae74ef2b92f888b41296a10d3098fae4a3cabec9 Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Wed, 21 Feb 2024 11:12:16 -0600 Subject: [PATCH 13/21] Finished up the tests. --- .../rendering/models/openrtb/BidRequest.java | 4 +- .../parameters/BasicParameterBuilderTest.java | 51 ++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) 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 cedeb064c..3c5bbe069 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 @@ -76,7 +76,9 @@ public JSONObject getJsonObject() throws JSONException { private JSONObject mergeOrtbConfig(JSONObject bidRequestJson) { try { - assert ortbConfig != null; + if (ortbConfig == null) { + return bidRequestJson; + } JSONObject ortbConfigObject = new JSONObject(ortbConfig); //remove protected fields if (ortbConfigObject.has("regs")) { 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 ebf14f4ac..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 @@ -31,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; @@ -326,7 +327,7 @@ public void setGpid_gpidPresentInRequest() { @Test public void setOrtbConfig_configPresentInRequest() { AdUnitConfiguration adConfiguration = new AdUnitConfiguration(); - String ortbConfig = "{\"arbitraryparamkey1\":\"arbitraryparamvalue1\"}"; + String ortbConfig = "{\"arbitraryparamkey1\":\"arbitraryparamvalue1\",\"ext\":{\"otherExtParam\":\"otherParam\"}}"; adConfiguration.setOrtbConfig(ortbConfig); BasicParameterBuilder builder = new BasicParameterBuilder( @@ -340,6 +341,54 @@ public void setOrtbConfig_configPresentInRequest() { 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(); } From 40d9edbad07aa0198d14863d1340642ee00dbaa4 Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Wed, 21 Feb 2024 15:01:27 -0600 Subject: [PATCH 14/21] Forgot to add section about arrays. --- .../mobile/rendering/models/openrtb/BidRequest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 3c5bbe069..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 @@ -118,8 +118,15 @@ private static JSONObject deepMerge(JSONObject source, JSONObject target) throws } else { // existing value for "key" - recursively deep merge: if (value instanceof JSONObject) { - JSONObject valueJson = (JSONObject)value; + 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); } From 7e395164a8ca9ccbc0234235e48f8171c1c226b2 Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Tue, 27 Feb 2024 10:49:01 -0600 Subject: [PATCH 15/21] removing the .destroy() call --- .../mobile/rendering/networking/modelcontrollers/Requester.java | 1 - 1 file changed, 1 deletion(-) 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 2ccee14ef..0e991fe50 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 @@ -94,7 +94,6 @@ protected Void doInBackground(BaseNetworkTask... baseNetworkTasks) { if (baseNetworkTasks.length > 0) { if (baseNetworkTasks[0] != null) { baseNetworkTasks[0].cancel(true); - baseNetworkTasks[0].destroy(); } } return null; From a6a1320476a626c55ef8bb7dab03273451554182 Mon Sep 17 00:00:00 2001 From: shinwan2 Date: Mon, 11 Mar 2024 20:00:57 +0900 Subject: [PATCH 16/21] fix: Pin Google Play Services Ads to 22.6.0 Using 23.0.0 will fail the build because it requires minimum SDK 21 while Prebid still supports minimum SDK 19. --- Example/PrebidDemoJava/build.gradle | 2 +- Example/PrebidDemoKotlin/build.gradle | 2 +- Example/PrebidInternalTestApp/build.gradle | 2 +- PrebidMobile/PrebidMobile-admobAdapters/build.gradle | 2 +- PrebidMobile/PrebidMobile-gamEventHandlers/build.gradle | 2 +- .../mobile/eventhandlers/global/GoogleAdVersionTest.java | 3 ++- gradle/libs.versions.toml | 5 +++++ 7 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 gradle/libs.versions.toml 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-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/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" } From 27fa1c9e867b498b276e0b6b9c5c125d823cf230 Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Tue, 9 Apr 2024 11:01:04 -0500 Subject: [PATCH 17/21] Made requested changes. --- .../modelcontrollers/Requester.java | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) 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 0e991fe50..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 @@ -83,30 +83,9 @@ public abstract class Requester { public abstract void startAdRequest(); - /** - * This Async task is needed because the networkTask needs to be cancelled / destroyed - * on a background thread or it throws a NetworkOnMainThreadException - **/ - private static class DestroyNetworkTaskAsyncTask extends AsyncTask { - - @Override - protected Void doInBackground(BaseNetworkTask... baseNetworkTasks) { - if (baseNetworkTasks.length > 0) { - if (baseNetworkTasks[0] != null) { - baseNetworkTasks[0].cancel(true); - } - } - return null; - } - } - public void destroy() { if (networkTask != null) { - if(Looper.getMainLooper().getThread() == Thread.currentThread()) { - new DestroyNetworkTaskAsyncTask().execute(networkTask); - } else { - networkTask.cancel(true); - } + networkTask.cancel(true); } networkTask = null; if (fetchAdIdInfoTask != null) { From e7ef5b536ca3af0517b1d630841ab17097ca8645 Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Thu, 11 Jan 2024 13:21:56 -0600 Subject: [PATCH 18/21] Added the networking task cancellation/destruction to a background thread. --- .../modelcontrollers/Requester.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) 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..557edbffb 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; @@ -82,10 +83,32 @@ public abstract class Requester { public abstract void startAdRequest(); + /** + * This Async task is needed because the networkTask needs to be cancelled / destroyed + * on a background thread or it throws a NetworkOnMainThreadException + **/ + private static class DestroyNetworkTaskAsyncTask extends AsyncTask { + + @Override + protected Void doInBackground(BaseNetworkTask... baseNetworkTasks) { + if (baseNetworkTasks.length > 0) { + if (baseNetworkTasks[0] != null) { + baseNetworkTasks[0].cancel(true); + baseNetworkTasks[0].destroy(); + } + } + return null; + } + } + public void destroy() { if (networkTask != null) { - networkTask.cancel(true); - networkTask.destroy(); + if(Looper.getMainLooper().getThread() == Thread.currentThread()) { + new DestroyNetworkTaskAsyncTask().execute(networkTask); + } else { + networkTask.cancel(true); + networkTask.destroy(); + } } networkTask = null; if (fetchAdIdInfoTask != null) { From 6f8055804a129fde36c9af51e6d3344937e91574 Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Tue, 30 Jan 2024 12:14:54 -0600 Subject: [PATCH 19/21] removing the redundant .destroy() call first. --- .../mobile/rendering/networking/modelcontrollers/Requester.java | 1 - 1 file changed, 1 deletion(-) 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 557edbffb..2ccee14ef 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 @@ -107,7 +107,6 @@ public void destroy() { new DestroyNetworkTaskAsyncTask().execute(networkTask); } else { networkTask.cancel(true); - networkTask.destroy(); } } networkTask = null; From 26947c7ba4f4fa54dea6a570bba7574400e78f2d Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Tue, 27 Feb 2024 10:49:01 -0600 Subject: [PATCH 20/21] removing the .destroy() call --- .../mobile/rendering/networking/modelcontrollers/Requester.java | 1 - 1 file changed, 1 deletion(-) 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 2ccee14ef..0e991fe50 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 @@ -94,7 +94,6 @@ protected Void doInBackground(BaseNetworkTask... baseNetworkTasks) { if (baseNetworkTasks.length > 0) { if (baseNetworkTasks[0] != null) { baseNetworkTasks[0].cancel(true); - baseNetworkTasks[0].destroy(); } } return null; From be701b231f317d42de3ded633b2cac98e15e3b2a Mon Sep 17 00:00:00 2001 From: Jono Sligh Date: Tue, 9 Apr 2024 11:01:04 -0500 Subject: [PATCH 21/21] Made requested changes. --- .../modelcontrollers/Requester.java | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) 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 0e991fe50..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 @@ -83,30 +83,9 @@ public abstract class Requester { public abstract void startAdRequest(); - /** - * This Async task is needed because the networkTask needs to be cancelled / destroyed - * on a background thread or it throws a NetworkOnMainThreadException - **/ - private static class DestroyNetworkTaskAsyncTask extends AsyncTask { - - @Override - protected Void doInBackground(BaseNetworkTask... baseNetworkTasks) { - if (baseNetworkTasks.length > 0) { - if (baseNetworkTasks[0] != null) { - baseNetworkTasks[0].cancel(true); - } - } - return null; - } - } - public void destroy() { if (networkTask != null) { - if(Looper.getMainLooper().getThread() == Thread.currentThread()) { - new DestroyNetworkTaskAsyncTask().execute(networkTask); - } else { - networkTask.cancel(true); - } + networkTask.cancel(true); } networkTask = null; if (fetchAdIdInfoTask != null) {