Skip to content

Commit

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

* commit '7edbbdbf51f743967c0aabbdff06a80a979e1a79':
  Updated RELEASE-NOTES, sdk version
  MS-4811 Fix: Crash with MAR.stop on BGThread
  MS-4850 Fix: VisibilityDetector memoryLeak
  Merge pull request #568 in MOBILE-SDK/app_mobile-sdk-android from MS-4710_expose_bid_price to develop
  • Loading branch information
avohraa committed Sep 30, 2021
2 parents 949947a + 7edbbdb commit ca77c83
Show file tree
Hide file tree
Showing 20 changed files with 232 additions and 112 deletions.
8 changes: 8 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 7.18
### New Features:
+ MS-4710 Make bid price available as part of AdResponseInfo [https://wiki.xandr.com/x/WoBKC]
### Bug Fixes
###### Fixed:
+ MS-4811 Issue with MAR.stop() api when used with enabled background threading [Github #58]
+ MS-4850 Memory Leak caused by VisibilityDetector

## 7.17
### New Features:
+ MS-4838 TTL SDK expiry listener logic for Index Exchange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.os.Bundle
import android.webkit.WebView
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.appnexus.opensdk.SDKSettings
import com.appnexus.opensdk.utils.Settings

class MainActivity : AppCompatActivity() {
Expand All @@ -14,6 +15,8 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

SDKSettings.setCountImpressionOn1pxRendering(true)

Settings.getSettings().debug_mode = true
Settings.getSettings().useHttps = true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
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.31" // Instream SDK version
version = "1.32" // Instream SDK version

apply plugin: 'com.android.library'

Expand All @@ -10,7 +10,7 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 29 // An integer value that represents the version of the code, relative to other versions. Increase for each release.
versionCode 30 // 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 @@ -73,6 +73,9 @@ public void testAdResponseInfoRTBVideo() {
assertEquals(videoAd.getAdResponseInfo().getContentSource(), UTConstants.RTB);
assertEquals(videoAd.getAdResponseInfo().getNetworkName(), "");
assertEquals(videoAd.getAdResponseInfo().getAuctionId(), "123456789");
assertEquals(videoAd.getAdResponseInfo().getCpm(), 0.000010);
assertEquals(videoAd.getAdResponseInfo().getCpmPublisherCurrency(), 0.000010);
assertEquals(videoAd.getAdResponseInfo().getPublisherCurrencyCode(), "$");
}

@Test
Expand All @@ -88,6 +91,10 @@ public void testAdResponseInfoRTBVideoNoBid() {
assertEquals(videoAd.getAdResponseInfo().getContentSource(), "");
assertEquals(videoAd.getAdResponseInfo().getNetworkName(), "");
assertEquals(videoAd.getAdResponseInfo().getAuctionId(), "3552547938089377051000000");
assertEquals(videoAd.getAdResponseInfo().getCpm(), 0d);
assertEquals(videoAd.getAdResponseInfo().getCpmPublisherCurrency(), 0d);
assertEquals(videoAd.getAdResponseInfo().getPublisherCurrencyCode(), "");

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public class TestUTResponses {
public static final String ADS = "\"ads\":[%s]";


public static final String RTB_VIDEO = "{\"content_source\":\"rtb\",\"ad_type\":\"video\",\"buyer_member_id\":123,\"creative_id\":6332753,\"media_type_id\":4,\"media_subtype_id\":64,\"client_initiated_ad_counting\":true,\"rtb\":{\"video\":{\"content\":\"%s\",\"duration_ms\":100}}}";
public static final String RTB_VIDEO = "{\"cpm\":0.000010,\"cpm_publisher_currency\":0.000010,\"publisher_currency_code\":\"$\",\"content_source\":\"rtb\",\"ad_type\":\"video\",\"buyer_member_id\":123,\"creative_id\":6332753,\"media_type_id\":4,\"media_subtype_id\":64,\"client_initiated_ad_counting\":true,\"rtb\":{\"video\":{\"content\":\"%s\",\"duration_ms\":100}}}";

public static String blank() {
return "";
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 = "7.17"
version = "7.18"
group='com.appnexus.opensdk'

// Android build
Expand All @@ -9,7 +9,7 @@ android {
compileSdkVersion 28
buildToolsVersion '29.0.0'
defaultConfig {
versionCode 88 // An integer value that represents the version of the code, relative to other versions. Increase for each release.
versionCode 89 // 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
1 change: 1 addition & 0 deletions sdk/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
<string name="deny">Deny</string>
<string name="loading">Loading</string>
<string name="native_tag">View has been registered.</string>
<string name="native_view_tag">VisibilityListener</string>

</resources>
36 changes: 36 additions & 0 deletions sdk/src/com/appnexus/opensdk/ANAdResponseInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class ANAdResponseInfo {
String contentSource = "";
String networkName = "";
String auctionId = "";
private double cpm;
private double cpmPublisherCurrency;
private String publisherCurrencyCode = "";


/**
Expand Down Expand Up @@ -118,4 +121,37 @@ public void setAuctionId(String auctionId) {
this.auctionId = auctionId;
}

/**
* Retrieve the cpm
* */
public double getCpm() {
return cpm;
}

public void setCpm(double cpm) {
this.cpm = cpm;
}

/**
* Retrieve the cpm publisher currency
* */
public double getCpmPublisherCurrency() {
return cpmPublisherCurrency;
}

public void setCpmPublisherCurrency(double cpmPublisherCurrency) {
this.cpmPublisherCurrency = cpmPublisherCurrency;
}

/**
* Retrieve the publisher currency code
* */
public String getPublisherCurrencyCode() {
return publisherCurrencyCode;
}

public void setPublisherCurrencyCode(String publisherCurrencyCode) {
this.publisherCurrencyCode = publisherCurrencyCode;
}

}
4 changes: 2 additions & 2 deletions sdk/src/com/appnexus/opensdk/ANNativeAdResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void run() {
registeredView = null;
clickables = null;
if (visibilityDetector != null) {
visibilityDetector.destroy(viewWeakReference);
visibilityDetector.destroy(viewWeakReference.get());
}
impressionTrackers = null;
listener = null;
Expand Down Expand Up @@ -339,7 +339,7 @@ protected boolean registerView(final View view, final NativeAdEventListener list
if (!expired && view != null) {
this.listener = listener;
viewWeakReference = new WeakReference<>(view);
visibilityDetector = VisibilityDetector.create(viewWeakReference);
visibilityDetector = VisibilityDetector.getInstance();
if (visibilityDetector == null) {
return false;
}
Expand Down
22 changes: 10 additions & 12 deletions sdk/src/com/appnexus/opensdk/AdFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,8 @@ public void setPeriod(int period) {
}

public void stop() {
if (requestManager != null) {
requestManager.cancel();
requestManager = null;
}

clearTasker();

destroy();
Clog.d(Clog.baseLogTag, Clog.getString(R.string.stop));
timePausedAt = System.currentTimeMillis();
state = STATE.STOPPED;
Expand Down Expand Up @@ -261,12 +256,15 @@ synchronized public void handleMessage(Message msg) {
fetcher.requestManager = new AdViewRequestManager(fetcher.anMultiAdRequest);
fetcher.requestManager.execute();
} else {
MediaType mediaType = fetcher.owner.getMediaType();
if (mediaType.equals(MediaType.NATIVE) || mediaType.equals(MediaType.INTERSTITIAL) || mediaType.equals(MediaType.BANNER) || mediaType.equals(MediaType.INSTREAM_VIDEO)) {
fetcher.requestManager = new AdViewRequestManager(fetcher.owner);
fetcher.requestManager.execute();
} else {
fetcher.owner.getAdDispatcher().onAdFailed(ResultCode.getNewInstance(ResultCode.INVALID_REQUEST), null);
// Sanity null check
if (fetcher.owner != null) {
MediaType mediaType = fetcher.owner.getMediaType();
if (mediaType.equals(MediaType.NATIVE) || mediaType.equals(MediaType.INTERSTITIAL) || mediaType.equals(MediaType.BANNER) || mediaType.equals(MediaType.INSTREAM_VIDEO)) {
fetcher.requestManager = new AdViewRequestManager(fetcher.owner);
fetcher.requestManager.execute();
} else {
fetcher.owner.getAdDispatcher().onAdFailed(ResultCode.getNewInstance(ResultCode.INVALID_REQUEST), null);
}
}
}
}
Expand Down
35 changes: 19 additions & 16 deletions sdk/src/com/appnexus/opensdk/AdView.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.appnexus.opensdk.VisibilityDetector.VisibilityListener;
import com.appnexus.opensdk.tasksmanager.TasksManager;
import com.appnexus.opensdk.ut.UTAdRequester;
import com.appnexus.opensdk.ut.UTConstants;
Expand All @@ -57,7 +58,7 @@
* BannerAdView}. This may not be instantiated directly. Its public
* methods are accessed through one of its sub classes.
*/
public abstract class AdView extends FrameLayout implements Ad, MultiAd {
public abstract class AdView extends FrameLayout implements Ad, MultiAd, VisibilityListener {

AdFetcher mAdFetcher;
private AdResponse ad = null;
Expand Down Expand Up @@ -169,19 +170,6 @@ boolean isMRAIDExpanded() {
return isMRAIDExpanded;
}

private void addVisibilityDetector(final WeakReference<View> view) {
final VisibilityDetector visibilityDetector = VisibilityDetector.create(view);
visibilityDetector.addVisibilityListener(view, new VisibilityDetector.VisibilityListener() {
@Override
public void onVisibilityChanged(boolean visible) {
if (visible && impressionTrackers != null && impressionTrackers.size() > 0) {
fireImpressionTracker();
visibilityDetector.destroy(view);
}
}
});
}

@Override
public boolean isReadyToStart() {
if (!(getContext() instanceof Activity)) {
Expand Down Expand Up @@ -400,6 +388,10 @@ public String getInventoryCode() {
* when permanently remove the AdView from the view hierarchy.
*/
public void destroy() {
if (VisibilityDetector.getInstance() != null) {
VisibilityDetector.getInstance().destroy(AdView.this);
}

Clog.d(Clog.baseLogTag, "called destroy() on AdView");
if (this.lastDisplayable != null) {
this.lastDisplayable.destroy();
Expand Down Expand Up @@ -1254,8 +1246,11 @@ public void run() {
}
if (ad.getDisplayable() != null && ad.getMediaType().equals(MediaType.BANNER) && ad.getResponseData().getAdType().equalsIgnoreCase(UTConstants.AD_TYPE_BANNER)) {
if (getEffectiveImpressionCountingMethod() == CountImpression.ONE_PX) {
WeakReference<View> weakReferenceView = new WeakReference<View>(ad.getDisplayable().getView());
addVisibilityDetector(weakReferenceView);
VisibilityDetector visibilityDetector = VisibilityDetector.getInstance();
if (visibilityDetector != null) {
visibilityDetector.destroy(AdView.this);
visibilityDetector.addVisibilityListener(AdView.this);
}
}
}
setCreativeWidth(ad.getDisplayable().getCreativeWidth());
Expand Down Expand Up @@ -1634,4 +1629,12 @@ public CountImpression getEffectiveImpressionCountingMethod() {
return CountImpression.DEFAULT;
}
}

@Override
public void onVisibilityChanged(boolean visible) {
if (visible && impressionTrackers != null && impressionTrackers.size() > 0) {
fireImpressionTracker();
VisibilityDetector.getInstance().destroy(this);
}
}
}
1 change: 1 addition & 0 deletions sdk/src/com/appnexus/opensdk/BannerAdView.java
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ public void activityOnDestroy() {
if (mAdFetcher != null) {
stop();
}
destroy();
}

@Override
Expand Down
8 changes: 6 additions & 2 deletions sdk/src/com/appnexus/opensdk/ImpressionTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ static ImpressionTracker create(WeakReference<View> viewWeakReference, String ur
return null;
} else {
ImpressionTracker impressionTracker = new ImpressionTracker(viewWeakReference, url, visibilityDetector, context, anOmidAdSession, impressionTrackerListener);
visibilityDetector.addVisibilityListener(viewWeakReference, impressionTracker.listener);
return impressionTracker;
}
}
Expand All @@ -56,6 +55,11 @@ private ImpressionTracker(WeakReference<View> viewWeakReference, String url, Vis
this.context = context;
this.anOmidAdSession = anOmidAdSession;
this.impressionTrackerListener = impressionTrackerListener;
View view = viewWeakReference.get();
if (view != null) {
view.setTag(R.string.native_view_tag, listener);
visibilityDetector.addVisibilityListener(viewWeakReference.get());
}
}

private void fire() {
Expand All @@ -78,7 +82,7 @@ protected String getUrl() {
}
};
asyncTask.execute();
visibilityDetector.destroy(viewWeakReference);
visibilityDetector.destroy(viewWeakReference.get());
listener = null;
} else {
nm.addURL(url, context, new ImpressionTrackerListener() {
Expand Down
Loading

0 comments on commit ca77c83

Please sign in to comment.