Skip to content

Commit

Permalink
Pull request #723: 5664325 Added WarmUpAdCall and Prefetch Webview op…
Browse files Browse the repository at this point in the history
…tions in XandrAd.init

Merge in MOBILE-SDK/app_mobile-sdk-android from 5664325_warmupadcall_prefetch_webview to develop

Squashed commit of the following:

commit 4fdb3597f8c52e95e48e9551c74a9e4fee224a2e
Author: Ritesh Zaveri <[email protected]>
Date:   Tue Oct 17 22:10:14 2023 +0530

    updated final sdksettings.init

commit fb8380f40d5e17ae48b004100584b44db990a3e4
Author: Ritesh Zaveri <[email protected]>
Date:   Tue Oct 17 15:00:11 2023 +0530

    updated sdk settings init and test cases

commit f909feb4d40e8af589c52509a72b5d86b55d82d5
Author: Ritesh Zaveri <[email protected]>
Date:   Fri Oct 13 17:19:03 2023 +0530

    fix unit test failure

commit df277d47bc9c90059a7f6ca933df4d08c3c1aad5
Author: Ritesh Zaveri <[email protected]>
Date:   Thu Oct 12 20:50:16 2023 +0530

    overload init method

commit 2496b1c0b0d2465e0c2841f894135a7bff1e8363
Author: Ritesh Zaveri <[email protected]>
Date:   Tue Oct 10 14:08:43 2023 +0530

    sdk setting overload init changes

commit 575c8cfa23833cbc38160d867a4f2f169c0b9f3b
Author: Ritesh Zaveri <[email protected]>
Date:   Tue Oct 10 14:05:52 2023 +0530

    sdk settings init changes

commit 1b6b868efad17d0c0b4464152b4737bd32143a9e
Author: Ritesh Zaveri <[email protected]>
Date:   Thu Oct 5 21:39:32 2023 +0530

    simple video example

commit 0c8da672bd3dfb0f9d68802b35083c8148b7d176
Author: Ritesh Zaveri <[email protected]>
Date:   Thu Oct 5 21:09:51 2023 +0530

    instream video changes

commit fc32226fd47f0117223e0ad36fe353ec3aa725a2
Author: Ritesh Zaveri <[email protected]>
Date:   Thu Oct 5 19:15:45 2023 +0530

    warmupadcall_prefetch_webview
  • Loading branch information
Ritesh Zaveri committed Oct 18, 2023
1 parent 4ef5164 commit 2881eb9
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,4 @@ public void goBacktoNormal() {
baseContainer.setLayoutParams(oldParams);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class InstreamVideoView extends FrameLayout {

void setup(Context context) {

SDKSettings.init(context, null);
SDKSettings.init(context, null, true, true, false, false);

Clog.d(Clog.publicFunctionsLogTag, Clog.getString(R.string.new_adview));

Expand Down Expand Up @@ -253,4 +253,4 @@ private boolean alreadyAddedToFriendlyObstruction(View view) {
protected ArrayList<WeakReference<View>> getFriendlyObstructionList() {
return friendlyObstructionList;
}
}
}
2 changes: 1 addition & 1 deletion sdk/src/com/appnexus/opensdk/AdView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1667,4 +1667,4 @@ public Long getFinishTime() {
* */
public boolean isEligibleForNativeAssemblyRendering() { return eligibleForNativeAssemblyRendering; }

}
}
6 changes: 3 additions & 3 deletions sdk/src/com/appnexus/opensdk/NativeAdRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class NativeAdRequest implements Ad, MultiAd {

public NativeAdRequest(Context context, String placementID) {

SDKSettings.init(context, null);
SDKSettings.init(context, null, true, true, false, false);

requestParameters = new UTRequestParameters(context);
requestParameters.setPlacementID(placementID);
Expand All @@ -57,7 +57,7 @@ public NativeAdRequest(Context context, String placementID) {

public NativeAdRequest(Context context, String inventoryCode, int memberID) {

SDKSettings.init(context, null);
SDKSettings.init(context, null, true, true, false, false);

requestParameters = new UTRequestParameters(context);
requestParameters.setInventoryCodeAndMemberID(memberID, inventoryCode);
Expand Down Expand Up @@ -617,4 +617,4 @@ public Long getFinishTime() {
return 0L;
}

}
}
42 changes: 31 additions & 11 deletions sdk/src/com/appnexus/opensdk/SDKSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public class SDKSettings {
* */
private static Boolean useBackgroundThreads = false;

@Deprecated
private static Boolean enableBannerOptimization = true;

/**
* For internal use only
* */
private static boolean isOmidActivationDone = false, isUserAgentFetched = false, isAAIDFetched = false;
private static boolean isOmidActivationDone = false, isUserAgentFetched = false, isAAIDFetched = false, isWarmupAdCallDone = false, isPrefetchWebViewDone = false;

private static boolean isWarmupAdCallDone = false;

// hide the constructor from javadocs
private SDKSettings() {
Expand Down Expand Up @@ -429,21 +429,42 @@ public static void enableBackgroundThreading(boolean enable) {
}

public static void init(Context context, final InitListener listener) {
init(context, listener, true, true);
init(context, listener, true, true, true, true);
}

/**
* This is an overloaded init method which provides flexibility to enable/disable booleans for activateOmid, fetcbUserAgent and fetchAAID.
* This is an overloaded init method which provides flexibility to enable/disable booleans for activateOmid, fetchUserAgent and fetchAAID.
* @param fetchUserAgent enable / disable fetching of User Agent.
* @param fetchAAID enable / disable fetching of AAID.
* Use {@link SDKSettings#init(Context, InitListener, boolean, boolean, boolean, boolean)} signature instead
* To be removed in v9.0
* */
@Deprecated
public static void init(final Context context, final InitListener listener, final boolean fetchUserAgent, final boolean fetchAAID) {
prefetchWebview(context);
warmupAdCall();
init(context, listener, fetchUserAgent, fetchAAID, true, true);
}

/**
* This is an overloaded init method which provides flexibility to enable/disable booleans for activateOmid, fetchUserAgent, fetchAAID, enableWarmUpAdCall and preFetchWebView.
* @param fetchUserAgent enable / disable fetching of User Agent.
* @param fetchAAID enable / disable fetching of AAID.
* @param enableWarmUpAdCall enable / disable of the warm up ad call.
* @param preFetchWebView enable / disable pre-fetching of the webview.
* */
public static void init(final Context context, final InitListener listener, final boolean fetchUserAgent, final boolean fetchAAID, final boolean enableWarmUpAdCall, final boolean preFetchWebView) {
// Store the UA in the settings
isOmidActivationDone = Omid.isActive();
isUserAgentFetched = !fetchUserAgent || !StringUtil.isEmpty(Settings.getSettings().ua);
isAAIDFetched = !fetchAAID || !StringUtil.isEmpty(getAAID());
// Execute prefetchWebview() if !isPrefetchWebViewDone or prefetchWebView is enabled.
if(!isPrefetchWebViewDone && preFetchWebView){
isPrefetchWebViewDone = true;
prefetchWebview(context);
}
// Execute warmupAdCall() if !isWarmupAdCallDone or warm up ad call is enabled.
if (!isWarmupAdCallDone && enableWarmUpAdCall) {
warmupAdCall();
}
if (!isOmidActivationDone) {
ANOmidViewabilty.getInstance().activateOmidAndCreatePartner(context.getApplicationContext());
isOmidActivationDone = true;
Expand Down Expand Up @@ -496,9 +517,6 @@ public void onInitFinished(boolean success) {
}

private static void warmupAdCall() {
if (isWarmupAdCallDone) {
return;
}
new HTTPGet() {

@Override
Expand All @@ -514,7 +532,7 @@ protected String getUrl() {
}

private static void prefetchWebview(Context context) {
if (isBannerOptimizationEnabled()) {
if (enableBannerOptimization) {
List cachedAdWebView = Settings.getSettings().getCachedAdWebView();
if (cachedAdWebView.size() == 0) {
AdWebView webView = new AdWebView(context);
Expand Down Expand Up @@ -549,6 +567,8 @@ public void run() {
/**
* Experimental API, to be used in case of issue with banner optimization
* To be removed in v9.0
* Use {@link SDKSettings#init(Context, InitListener, boolean, boolean, boolean, boolean)} signature instead
* passing preFetchWebView = true/false while calling SDKSettings.init() has the same effect of setting enableBannerOptimization to true/false
* */
@Deprecated
public static void enableBannerOptimization(boolean enable) {
Expand All @@ -563,4 +583,4 @@ public static void enableBannerOptimization(boolean enable) {
public static Boolean isBannerOptimizationEnabled() {
return enableBannerOptimization;
}
}
}
4 changes: 2 additions & 2 deletions sdk/src/com/appnexus/opensdk/XandrAd.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
public class XandrAd {

/**
* memberId will be set using the {@link XandrAd#init(int, Context, boolean, boolean, InitListener)}
**/
* memberId will be set using the {@link XandrAd#init(int, Context, boolean, boolean, InitListener)}
**/
private static int memberId = -1;
/**
* Cached member IDs list
Expand Down
6 changes: 3 additions & 3 deletions sdk/test/com/appnexus/opensdk/AdFetcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void testStartWithRefreshOnWithLazyLoad() {
adFetcher.setPeriod(15000);
adFetcher.start();
Lock.pause(1000); // added this so jenkins can have enough time to process
// assert 3 here because a AAID async task
// assert 2 here because a AAID async task
assertExpectedBGTasksAfterOneAdRequest(2);

assertEquals(AdFetcher.STATE.AUTO_REFRESH, adFetcher.getState());
Expand Down Expand Up @@ -179,7 +179,7 @@ public void testStartWithRefreshOnWithLazyLoadAndReload() {
adFetcher.setPeriod(15000);
adFetcher.start();
Lock.pause(1000); // added this so jenkins can have enough time to process
// assert 3 here because a AAID async task
// assert 2 here because a AAID async task
assertExpectedBGTasksAfterOneAdRequest(2);

assertEquals(AdFetcher.STATE.AUTO_REFRESH, adFetcher.getState());
Expand Down Expand Up @@ -207,7 +207,7 @@ public void testStartWithRefreshOnWithLazyLoadAndReload() {

owner.loadAd();
Lock.pause(1000); // added this so jenkins can have enough time to process
// assert 3 here because a AAID async task
// assert 4 here because a AAID async task
assertExpectedBGTasksAfterOneAdRequest(4);

assertEquals(AdFetcher.STATE.AUTO_REFRESH, adFetcher.getState());
Expand Down
2 changes: 1 addition & 1 deletion sdk/test/com/appnexus/opensdk/SDKSettingsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ public void testSDKSettingsInitAboveHONEY_COMB() {
assertNotNull(Settings.getSettings().ua);
assertNotEquals(Settings.getSettings().ua, (userAgentWebView.getSettings().getUserAgentString().trim().toLowerCase(Locale.ROOT)));
}
}
}

0 comments on commit 2881eb9

Please sign in to comment.