diff --git a/ChangeLog.txt b/ChangeLog.txt index e212e3e37..b148d2320 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,14 @@ Google Mobile Ads Unity Plugin Change Log +************* +Version 3.0.3 +************* +- Restrict simultaneous rewarded video requests on Android. + +Built and tested with: +- Google Play Services 8.4.0 +- Google Mobile Ads iOS SDK 7.7.0 + ************* Version 3.0.2 ************* diff --git a/GoogleMobileAds.unitypackage b/GoogleMobileAds.unitypackage index 162c8e120..8306ab0da 100644 Binary files a/GoogleMobileAds.unitypackage and b/GoogleMobileAds.unitypackage differ diff --git a/source/android-library/app/src/main/java/com/google/unity/ads/RewardBasedVideo.java b/source/android-library/app/src/main/java/com/google/unity/ads/RewardBasedVideo.java index ab0db91e9..9e409c8a9 100644 --- a/source/android-library/app/src/main/java/com/google/unity/ads/RewardBasedVideo.java +++ b/source/android-library/app/src/main/java/com/google/unity/ads/RewardBasedVideo.java @@ -51,10 +51,18 @@ public class RewardBasedVideo { */ private boolean isLoaded; + /** + * Whether or not there is an ad request in progress. + */ + private boolean isLoading; + + private final Object mLock = new Object(); + public RewardBasedVideo(Activity activity, UnityRewardBasedVideoAdListener adListener) { this.activity = activity; this.adListener = adListener; this.isLoaded = false; + this.isLoading = false; } /** @@ -68,13 +76,19 @@ public void run() { rewardBasedVideo.setRewardedVideoAdListener(new RewardedVideoAdListener() { @Override public void onRewardedVideoAdLoaded() { - isLoaded = true; - adListener.onAdLoaded(); + synchronized (mLock) { + isLoaded = true; + isLoading = false; + adListener.onAdLoaded(); + } } @Override public void onRewardedVideoAdFailedToLoad(int errorCode) { - adListener.onAdFailedToLoad(PluginUtils.getErrorReason(errorCode)); + synchronized (mLock) { + isLoading = false; + adListener.onAdFailedToLoad(PluginUtils.getErrorReason(errorCode)); + } } @Override @@ -121,7 +135,16 @@ public void run() { if (extras != null) { extras.putBoolean("_noRefresh", true); } - rewardBasedVideo.loadAd(adUnitId, request); + synchronized (mLock) { + if (!isLoading) { + isLoading = true; + rewardBasedVideo.loadAd(adUnitId, request); + } else { + Log.w(PluginUtils.LOGTAG, "Cannot make a new rewarded video ad request " + + "until previous request has completed."); + } + } + } }); } diff --git a/source/plugin/Assets/GoogleMobileAds/Api/AdRequest.cs b/source/plugin/Assets/GoogleMobileAds/Api/AdRequest.cs index 60cae7f23..baacd141c 100644 --- a/source/plugin/Assets/GoogleMobileAds/Api/AdRequest.cs +++ b/source/plugin/Assets/GoogleMobileAds/Api/AdRequest.cs @@ -20,7 +20,7 @@ namespace GoogleMobileAds.Api { public class AdRequest { - public const string Version = "3.0.2"; + public const string Version = "3.0.3"; public const string TestDeviceSimulator = "SIMULATOR"; public class Builder