Skip to content

Guard against Banner/Interstitial use of nullptr callbacks #744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ public void destroy(final long callbackDataPtr) {
completeBannerViewFutureCallback(callbackDataPtr,
ConstantsHelper.CALLBACK_ERROR_NONE,
ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE);
mNotifyBoundingBoxListenerOnNextDraw.set(true);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't have done anything, anyway, as the mAdView was already set to null. Also there's a synchronous bounding box changed event immediately prior to this.

}

/**
Expand Down Expand Up @@ -484,7 +483,7 @@ public class AdViewListener extends AdListener implements OnPaidEventListener {
@Override
public void onAdClicked() {
synchronized (mBannerViewLock) {
if (mAdView != null) {
if (mBannerViewInternalPtr != CPP_NULLPTR) {
notifyAdClicked(mBannerViewInternalPtr);
}
}
Expand All @@ -494,7 +493,7 @@ public void onAdClicked() {
@Override
public void onAdClosed() {
synchronized (mBannerViewLock) {
if (mAdView != null) {
if (mBannerViewInternalPtr != CPP_NULLPTR) {
notifyAdClosed(mBannerViewInternalPtr);
mNotifyBoundingBoxListenerOnNextDraw.set(true);
}
Expand All @@ -505,18 +504,18 @@ public void onAdClosed() {
@Override
public void onAdFailedToLoad(LoadAdError loadAdError) {
synchronized (mBannerViewLock) {
if (mAdView != null) {
if (mLoadAdCallbackDataPtr != CPP_NULLPTR) {
completeBannerViewLoadAdError(mLoadAdCallbackDataPtr, loadAdError, loadAdError.getCode(), loadAdError.getMessage());
mLoadAdCallbackDataPtr = CPP_NULLPTR;
}
mLoadAdCallbackDataPtr = CPP_NULLPTR;
}
super.onAdFailedToLoad(loadAdError);
}

@Override
public void onAdImpression() {
synchronized (mBannerViewLock) {
if (mAdView != null) {
if (mBannerViewInternalPtr != CPP_NULLPTR) {
notifyAdImpression(mBannerViewInternalPtr);
}
}
Expand All @@ -528,13 +527,15 @@ public void onAdLoaded() {
synchronized (mBannerViewLock) {
if (mAdView != null) {
mAdViewContainsAd = true;
}
if (mLoadAdCallbackDataPtr != CPP_NULLPTR) {
completeBannerViewLoadedAd(mLoadAdCallbackDataPtr);
mLoadAdCallbackDataPtr = CPP_NULLPTR;
// Only update the bounding box if the banner view is already visible.
if (mPopUp != null && mPopUp.isShowing()) {
// Loading an ad can sometimes cause the bounds to change.
mNotifyBoundingBoxListenerOnNextDraw.set(true);
}
}
// Only update the bounding box if the banner view is already visible.
if (mPopUp != null && mPopUp.isShowing()) {
// Loading an ad can sometimes cause the bounds to change.
mNotifyBoundingBoxListenerOnNextDraw.set(true);
}
}
super.onAdLoaded();
Expand All @@ -543,17 +544,17 @@ public void onAdLoaded() {
@Override
public void onAdOpened() {
synchronized (mBannerViewLock) {
if (mAdView != null) {
if (mBannerViewInternalPtr != CPP_NULLPTR) {
notifyAdOpened(mBannerViewInternalPtr);
mNotifyBoundingBoxListenerOnNextDraw.set(true);
}
mNotifyBoundingBoxListenerOnNextDraw.set(true);
}
super.onAdOpened();
}

public void onPaidEvent(AdValue value) {
synchronized (mBannerViewLock) {
if (mAdView != null) {
if (mBannerViewInternalPtr != CPP_NULLPTR) {
notifyPaidEvent(mBannerViewInternalPtr, value.getCurrencyCode(),
value.getPrecisionType(), value.getValueMicros());
}
Expand All @@ -575,7 +576,7 @@ public void onPaidEvent(AdValue value) {
@Override
public boolean onPreDraw() {
if (mNotifyBoundingBoxListenerOnNextDraw.compareAndSet(true, false)) {
if (mAdView != null) {
if (mAdView != null && mBannerViewInternalPtr != CPP_NULLPTR) {
notifyBoundingBoxChanged(mBannerViewInternalPtr);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,35 +219,45 @@ private class InterstitialAdFullScreenContentListener

public void onAdClicked() {
synchronized (mInterstitialLock) {
notifyAdClickedFullScreenContentEvent(mInterstitialAdInternalPtr);
if (mInterstitialAdInternalPtr != CPP_NULLPTR) {
notifyAdClickedFullScreenContentEvent(mInterstitialAdInternalPtr);
}
}
}

@Override
public void onAdDismissedFullScreenContent() {
synchronized (mInterstitialLock) {
notifyAdDismissedFullScreenContentEvent(mInterstitialAdInternalPtr);
if (mInterstitialAdInternalPtr != CPP_NULLPTR) {
notifyAdDismissedFullScreenContentEvent(mInterstitialAdInternalPtr);
}
}
}

@Override
public void onAdFailedToShowFullScreenContent(AdError error) {
synchronized (mInterstitialLock) {
notifyAdFailedToShowFullScreenContentEvent(mInterstitialAdInternalPtr, error);
if (mInterstitialAdInternalPtr != CPP_NULLPTR) {
notifyAdFailedToShowFullScreenContentEvent(mInterstitialAdInternalPtr, error);
}
}
}

@Override
public void onAdImpression() {
synchronized (mInterstitialLock) {
notifyAdImpressionEvent(mInterstitialAdInternalPtr);
if (mInterstitialAdInternalPtr != CPP_NULLPTR) {
notifyAdImpressionEvent(mInterstitialAdInternalPtr);
}
}
}

@Override
public void onAdShowedFullScreenContent() {
synchronized (mInterstitialLock) {
notifyAdShowedFullScreenContentEvent(mInterstitialAdInternalPtr);
if (mInterstitialAdInternalPtr != CPP_NULLPTR) {
notifyAdShowedFullScreenContentEvent(mInterstitialAdInternalPtr);
}
}
}

Expand All @@ -263,10 +273,12 @@ private class InterstitialAdListener extends InterstitialAdLoadCallback {
@Override
public void onAdFailedToLoad(LoadAdError loadAdError) {
synchronized (mInterstitialLock) {
completeInterstitialLoadAdError(
mLoadAdCallbackDataPtr, loadAdError, loadAdError.getCode(),
loadAdError.getMessage());
mLoadAdCallbackDataPtr = CPP_NULLPTR;
if (mLoadAdCallbackDataPtr != CPP_NULLPTR) {
completeInterstitialLoadAdError(
mLoadAdCallbackDataPtr, loadAdError, loadAdError.getCode(),
loadAdError.getMessage());
mLoadAdCallbackDataPtr = CPP_NULLPTR;
}
}
}

Expand All @@ -277,8 +289,10 @@ public void onAdLoaded(InterstitialAd ad) {
InterstitialAdFullScreenContentListener listener = new InterstitialAdFullScreenContentListener();
mInterstitial.setFullScreenContentCallback(listener);
mInterstitial.setOnPaidEventListener(listener);
completeInterstitialLoadedAd(mLoadAdCallbackDataPtr);
mLoadAdCallbackDataPtr = CPP_NULLPTR;
if (mLoadAdCallbackDataPtr != CPP_NULLPTR) {
completeInterstitialLoadedAd(mLoadAdCallbackDataPtr);
mLoadAdCallbackDataPtr = CPP_NULLPTR;
}
}
}
}
Expand Down