Skip to content

Commit

Permalink
Merge pull request #684 in MOBILE-SDK/app_mobile-sdk-android from rel…
Browse files Browse the repository at this point in the history
…ease_branch_8.4 to master

* commit '6d1aa90c5ffcd3cc8886532b35bb54888071f122':
  removed MS-5030 treewalker changes
  release 8.4
  MS-5106_additional_flag to disable prefetching of webview
  preCacheMraidSupports -> false by default
  Code cleaning
  Code cleaning
  Fixed merge conflicts, added desired optimization
  Merge pull request #667 in MOBILE-SDK/app_mobile-sdk-android from MS-5143_analyze_CSM_load_time to develop
  MS-5229 Schibsted PR with tweaks
  optimise onInitFinished
  updated oninitfinished logic
  mraid changes
  MS-5030 treewalker eats cpu
  • Loading branch information
Ritesh Zaveri committed Feb 10, 2023
2 parents 4fa708b + 6d1aa90 commit 1165975
Show file tree
Hide file tree
Showing 26 changed files with 600 additions and 43 deletions.
7 changes: 7 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 8.4

### Improvement/Bug Fixes
+ MS-5106 & MS-5143 Banner load time performance improvements
+ MS-5228 Fix for MRAID related performance issue [https://docs.xandr.com/bundle/mobile-sdk/page/android-sdk-initialization-v8-0.html]
+ MS-5229 Added missing equals/hashcode for ANUserId [Github #78]

## 8.3.0

### Improvement/Bug Fixes
Expand Down
4 changes: 2 additions & 2 deletions instreamvideo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Project Properties
version = "1.41" // Instream SDK version
version = "1.42" // Instream SDK version

apply plugin: 'com.android.library'

Expand All @@ -10,7 +10,7 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 32
versionCode 40 // An integer value that represents the version of the code, relative to other versions. Increase for each release.
versionCode 41 // An integer value that represents the version of the code, relative to other versions. Increase for each release.
versionName version
consumerProguardFiles 'proguard-project.txt'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,16 @@ public MultiAd getMultiAd() {
return this;
}

@Override
public Long getStartTime() {
return 0L;
}

@Override
public Long getFinishTime() {
return 0L;
}

public ANAdResponseInfo getAdResponseInfo() {
return adResponseInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public void onBannerAdVideoEvent(SASBannerView sasBannerView, int i) {
}
});

Clog.logTime(getClass().getSimpleName() + " - requestAd");
// Load the banner
bannerView.loadAd(adPlacement);

Expand Down
4 changes: 2 additions & 2 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Project properties
version = "8.3"
version = "8.4"
group='com.appnexus.opensdk'

// Android build
Expand All @@ -9,7 +9,7 @@ android {
compileSdkVersion 32
buildToolsVersion '32.0.0'
defaultConfig {
versionCode 99 // An integer value that represents the version of the code, relative to other versions. Increase for each release.
versionCode 100 // An integer value that represents the version of the code, relative to other versions. Increase for each release.
versionName version
consumerProguardFiles 'proguard-project.txt'
minSdkVersion 14
Expand Down
21 changes: 21 additions & 0 deletions sdk/src/com/appnexus/opensdk/ANUserId.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package com.appnexus.opensdk;

import java.util.Objects;

public class ANUserId {

private String source;
Expand Down Expand Up @@ -70,4 +72,23 @@ public String getUserId() {
public String getSource() {
return source;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ANUserId anUserId = (ANUserId) o;
return Objects.equals(source, anUserId.source) && Objects.equals(userId, anUserId.userId);
}

@Override
public int hashCode() {
return Objects.hash(source, userId);
}

@Override
public String toString() {
// Maybe include RTI Partner in future (TBD)
return "{\"source\":\"" + source + "\",\"id\":\"" + userId + "\"}";
}
}
12 changes: 11 additions & 1 deletion sdk/src/com/appnexus/opensdk/Ad.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,15 @@ public interface Ad {
* Not intended to be used outside of SDK.
* */
MultiAd getMultiAd();


/**
* Not intended to be used outside of SDK
*/
Long getStartTime();

/**
* Not intended to be used outside of SDK
*/
Long getFinishTime();

}
1 change: 1 addition & 0 deletions sdk/src/com/appnexus/opensdk/AdFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public void start() {
if (!XandrAd.isInitialised()) {
XandrAd.throwUninitialisedException();
}
Clog.logTime(getClass().getSimpleName() + " - start");
initHandler();
Clog.d(Clog.baseLogTag, Clog.getString(R.string.start));
switch (state) {
Expand Down
27 changes: 25 additions & 2 deletions sdk/src/com/appnexus/opensdk/AdView.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
*/
public abstract class AdView extends FrameLayout implements Ad, MultiAd, VisibilityListener {

protected Long startTime = 0L;
protected Long finishTime = 0L;
AdFetcher mAdFetcher;
private AdResponse ad = null;
boolean mraid_changing_size_or_visibility = false;
Expand Down Expand Up @@ -161,6 +163,7 @@ public void init() {
isFetching = true;
activateWebview = false;
adResponseInfo = null;
startTime = System.currentTimeMillis();
}

/**
Expand Down Expand Up @@ -262,7 +265,8 @@ public boolean loadAd(String placementID) {
protected void loadAdFromHtml(String html, int width, int height, int buyerMemberId) {
// load an ad directly from html
loadedOffscreen = true;
AdWebView output = new AdWebView(this, null);
AdWebView output = SDKSettings.fetchWebView(getContext());
output.init(this, null);
ANAdResponseInfo adResponseInfo = new ANAdResponseInfo();
adResponseInfo.setBuyMemberId(buyerMemberId);
RTBHTMLAdResponse response = new RTBHTMLAdResponse(width, height, getMediaType().toString(), null, adResponseInfo);
Expand All @@ -275,7 +279,8 @@ protected void loadAdFromHtml(String html, int width, int height, int buyerMembe
protected void loadAdFromVAST(String VASTXML, int width, int height, int buyerMemberId) {
// load an ad directly from VASTXML
loadedOffscreen = true;
AdWebView output = new AdWebView(this, null);
AdWebView output = SDKSettings.fetchWebView(getContext());
output.init(this, null);
ANAdResponseInfo adResponseInfo = new ANAdResponseInfo();
adResponseInfo.setBuyMemberId(buyerMemberId);
RTBVASTAdResponse response = new RTBVASTAdResponse(width, height, AdType.VIDEO.toString(), null, null, adResponseInfo);
Expand Down Expand Up @@ -1086,6 +1091,7 @@ private void processAdFailed(final ResultCode code, final ANAdResponseInfo adRes
@Override
public void run() {
setAdResponseInfo(adResponseInfo);
recordFinishTime();
if (adListener != null) {
adListener.onAdRequestFailed(AdView.this, code);
}
Expand Down Expand Up @@ -1181,6 +1187,7 @@ private void handleNativeAd(AdResponse ad) {
final NativeAdResponse response = ad.getNativeAdResponse();
response.setAdResponseInfo(ad.getResponseData().getAdResponseInfo());
// setAdResponseInfo(ad.getResponseData().getAdResponseInfo());
recordFinishTime();
if (adListener != null) {
adListener.onAdLoaded(response);
}
Expand Down Expand Up @@ -1237,6 +1244,7 @@ public void run() {
} else if (ad.getResponseData().getAdType().equalsIgnoreCase(UTConstants.AD_TYPE_BANNER)) {
setAdType(AdType.BANNER);
}
recordFinishTime();
if (adListener != null) {
adListener.onAdLoaded(AdView.this);
}
Expand Down Expand Up @@ -1290,6 +1298,11 @@ public void onLazyAdLoaded(ANAdResponseInfo adResponseInfo) {
}
}

private void recordFinishTime() {
finishTime = System.currentTimeMillis();
Clog.logLoadTime(AdView.this);
}

void setImpressionTrackerVariables(BaseAdResponse ad) {
impressionTrackers = ad.getImpressionURLs();
countOfImpressionTrackersFired = 0;
Expand Down Expand Up @@ -1616,4 +1629,14 @@ public void onVisibilityChanged(boolean visible) {
VisibilityDetector.getInstance().destroy(this);
}
}

@Override
public Long getStartTime() {
return startTime;
}

@Override
public Long getFinishTime() {
return finishTime;
}
}
9 changes: 7 additions & 2 deletions sdk/src/com/appnexus/opensdk/AdViewRequestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public void nativeRenderingFailed() {

@Override
public void onReceiveAd(AdResponse ad) {
Clog.logTime(getClass().getSimpleName() + " - onReceiveAd");
printMediatedClasses();
if (controller != null) {
// do not hold a reference of current mediated ad controller after ad is loaded
Expand Down Expand Up @@ -196,6 +197,7 @@ private void fireImpressionTrackerIfBeginToRender(AdView adView, BaseAdResponse
}

private void processUTResponse(UTAdResponse response) {
Clog.logTime(getClass().getSimpleName() + " - processUTResponse");
final Ad owner = this.owner.get();
if ((owner != null) && doesAdListExists(response)) {
setAdList(response.getAdList());
Expand Down Expand Up @@ -379,6 +381,7 @@ private void handleCSMVASTAdResponse(Ad owner, CSMVASTAdResponse csmvastAdRespon


private void handleCSMResponse(Ad ownerAd, final CSMSDKAdResponse csmSdkAdResponse) {
Clog.logTime(getClass().getSimpleName() + " - handleCSMResponse");
Clog.i(Clog.baseLogTag, "Mediation type is CSM, passing it to MediatedAdViewController.");
if (csmSdkAdResponse.getAdType().equals(UTConstants.AD_TYPE_NATIVE)) {
mediatedNativeAdController = MediatedNativeAdController.create(csmSdkAdResponse,
Expand Down Expand Up @@ -421,12 +424,14 @@ private void initiateWebview(final Ad owner, final BaseAdResponse response) {
TasksManager.getInstance().executeOnMainThread(new Runnable() {
@Override
public void run() {
adWebview = new AdWebView((AdView) owner, AdViewRequestManager.this);
adWebview = SDKSettings.fetchWebView(((AdView) owner).getContext());
adWebview.init((AdView) owner, AdViewRequestManager.this);
adWebview.loadAd(response);
}
});
} else {
adWebview = new AdWebView((AdView) owner, AdViewRequestManager.this);
adWebview = SDKSettings.fetchWebView(((AdView) owner).getContext());
adWebview.init((AdView) owner, AdViewRequestManager.this);
adWebview.loadAd(response);

}
Expand Down
17 changes: 15 additions & 2 deletions sdk/src/com/appnexus/opensdk/AdWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,31 @@ class AdWebView extends WebView implements Displayable,
String RENDERER_JSON = "AN_NATIVE_RESPONSE_OBJECT";
private boolean isDestroyTriggered;

public AdWebView(Context context) {
super(new MutableContextWrapper(context));
setupSettings();
}

public AdWebView(AdView adView, UTAdRequester requester) {
super(new MutableContextWrapper(adView.getContext()));
init(adView, requester);
setupSettings();
setup();
}

public void init(AdView adView, UTAdRequester requester) {
Context context = getContext();
if (context instanceof MutableContextWrapper) {
((MutableContextWrapper) context).setBaseContext(adView.getContext());
}
this.adView = adView;
this.adView.setCurrentDisplayable(this);
this.caller_requester = requester;
this.initialMraidStateString = MRAIDImplementation.MRAID_INIT_STATE_STRINGS[
MRAIDImplementation.MRAID_INIT_STATE.STARTING_DEFAULT.ordinal()];
setupSettings();
setup();
}


@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
protected void setupSettings() {
Expand Down
19 changes: 4 additions & 15 deletions sdk/src/com/appnexus/opensdk/MRAIDImplementation.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
import android.media.AudioManager;
import android.media.MediaRouter;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.CalendarContract;
import android.util.Base64;
import android.util.Pair;
import android.view.Gravity;
Expand All @@ -45,7 +43,6 @@

import com.appnexus.opensdk.utils.Clog;
import com.appnexus.opensdk.utils.Hex;
import com.appnexus.opensdk.utils.Settings;
import com.appnexus.opensdk.utils.StringUtil;
import com.appnexus.opensdk.utils.ViewUtil;
import com.appnexus.opensdk.utils.W3CEvent;
Expand Down Expand Up @@ -188,20 +185,20 @@ private void setSupportsValues(AdWebView view) {
PackageManager pm = owner.getContext().getPackageManager();

//SMS
if (hasIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("sms:5555555555")), pm)) {
if (XandrAd.hasSMSIntent(pm)) {
setSupports(view, "sms", true);
}

//Tel
if (hasIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("tel:5555555555")), pm)) {
if (XandrAd.hasTelIntent(pm)) {
setSupports(view, "tel", true);
}

//Calendar
if (hasIntent(new Intent(Intent.ACTION_EDIT).setData(CalendarContract.Events.CONTENT_URI), pm)) {
if (XandrAd.hasCalendarIntent(pm)) {
setSupports(view, "calendar", true);
supportsCalendar = true;
} else if (hasIntent(new Intent(Intent.ACTION_EDIT).setType("vnd.android.cursor.item/event"), pm)) {
} else if (XandrAd.hasCalendarEventIntent(pm)) {
setSupports(view, "calendar", true);
supportsCalendar = true;
W3CEvent.useMIME = true;
Expand All @@ -218,14 +215,6 @@ private void setSupportsValues(AdWebView view) {
setSupports(view, "inlineVideo", true);
}

boolean hasIntent(Intent i, PackageManager pm) {
String intentUri = i.toUri(0);
if (Settings.getCachedIntentForAction(intentUri)==null) {
Settings.cacheIntentForAction(pm.queryIntentActivities(i, 0).size() > 0,intentUri);
}
return Boolean.TRUE.equals(Settings.getCachedIntentForAction(i.getAction()));
}

void onViewableChange(boolean viewable) {
if (!readyFired) return;
isViewable = viewable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private MediatedBannerAdViewController(

try {
if(activity!=null && !destroyed){
Clog.logTime(getClass().getSimpleName() + " - constructor - requesting Ad");
View viewFromMediatedAdaptor = ((MediatedBannerAdView) mAV).requestAd(this,
activity,
currentAd.getParam(),
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/com/appnexus/opensdk/MediatedSSMAdViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.appnexus.opensdk;

import android.os.Build;
import android.os.Handler;
import android.os.Message;

Expand Down Expand Up @@ -116,7 +115,8 @@ private void handleSSMServerResponse() {
fireResponseURL(ssmHtmlAdResponse, ResultCode.getNewInstance(ResultCode.SUCCESS));
UTAdRequester requester = this.caller_requester.get();
if (requester != null) {
final AdWebView output = new AdWebView(owner, requester);
final AdWebView output = SDKSettings.fetchWebView(owner.getContext());
output.init(owner, requester);
output.loadAd(ssmHtmlAdResponse);
}
}
Expand Down
10 changes: 10 additions & 0 deletions sdk/src/com/appnexus/opensdk/NativeAdRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -602,4 +602,14 @@ public MultiAd getMultiAd() {
return this;
}

@Override
public Long getStartTime() {
return 0L;
}

@Override
public Long getFinishTime() {
return 0L;
}

}
Loading

0 comments on commit 1165975

Please sign in to comment.