Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 21 additions & 1 deletion source/plugin/Assets/GoogleMobileAds/Api/AppOpenAdPreloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static Dictionary<string, PreloadConfiguration> GetConfigurations()
/// Returns a preloaded ad and removes it from the cache.
/// </summary>
/// <param name="preloadId">
/// The ad's preload ID.
/// A string identifier used to preload the ads for that configuration.
/// </param>
/// <returns>
/// The preloaded ad for the given preload ID, or null if no ad is available.
Expand All @@ -146,6 +146,26 @@ public static AppOpenAd DequeueAd(string preloadId)
return new AppOpenAd(client);
}

/// <summary>
/// Returns the ResponseInfo of a preloaded ad for the given preload ID without
/// dequeuing it, or null if no ad is available.
/// </summary>
/// <param name="preloadId">
/// A string identifier used to preload the ads for that configuration.
/// </param>
/// <returns>
/// The ResponseInfo of the preloaded ad for the given preload ID, or null if no ad is available.
/// </returns>
public static ResponseInfo PeekAdResponseInfo(string preloadId)
{
var responseInfoClient = _client.PeekAdResponseInfo(preloadId);
if (responseInfoClient == null)
{
return null;
}
return new ResponseInfo(responseInfoClient);
}

/// <summary>
/// Get the number of ads available for the given preload ID.
/// </summary>
Expand Down
22 changes: 21 additions & 1 deletion source/plugin/Assets/GoogleMobileAds/Api/RewardedAdPreloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static Dictionary<string, PreloadConfiguration> GetConfigurations()
/// Returns a preloaded ad and removes it from the cache.
/// </summary>
/// <param name="preloadId">
/// The ad's preload ID.
/// A string identifier used to preload the ads for that configuration.
/// </param>
/// <returns>
/// The preloaded ad for the given preload ID, or null if no ad is available.
Expand All @@ -145,6 +145,26 @@ public static RewardedAd DequeueAd(string preloadId)
return new RewardedAd(client);
}

/// <summary>
/// Returns the ResponseInfo of a preloaded ad for the given preload ID without
/// dequeuing it, or null if no ad is available.
/// </summary>
/// <param name="preloadId">
/// A string identifier used to preload the ads for that configuration.
/// </param>
/// <returns>
/// The ResponseInfo of the preloaded ad for the given preload ID, or null if no ad is available.
/// </returns>
public static ResponseInfo PeekAdResponseInfo(string preloadId)
{
var responseInfoClient = _client.PeekAdResponseInfo(preloadId);
if (responseInfoClient == null)
{
return null;
}
return new ResponseInfo(responseInfoClient);
}

/// <summary>
/// Get the number of ads available for the given preload ID.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ bool Preload(string preloadId, PreloadConfiguration preloadConfiguration,
/// </remarks>
IAppOpenAdClient DequeueAd(string preloadId);

/// <summary>
/// Returns the ResponseInfo of an ad available for the given preload ID without
/// dequeuing it, or null if no ad is available.
/// </summary>
/// <param name="preloadId">
/// A string identifier used to preload the ads for that configuration.
/// </param>
/// <returns>
/// The ResponseInfo of the preloaded ad for the given preload ID, or null if no ad is available.
/// </returns>
IResponseInfoClient PeekAdResponseInfo(string preloadId);

/// <summary>
/// Get the number of ads available for the given preload ID.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool Preload(string preloadId, PreloadConfiguration preloadConfiguration,
/// Returns a preloaded ad and removes it from the cache.
/// </summary>
/// <param name="preloadId">
/// The ad's preload ID.
/// A string identifier used to preload the ads for that configuration.
/// </param>
/// <returns>
/// The preloaded ad for the given preload ID, or null if no ad is available.
Expand All @@ -76,6 +76,18 @@ bool Preload(string preloadId, PreloadConfiguration preloadConfiguration,
/// </remarks>
IRewardedAdClient DequeueAd(string preloadId);

/// <summary>
/// Returns the ResponseInfo of an ad available for the given preload ID without
/// dequeuing it, or null if no ad is available.
/// </summary>
/// <param name="preloadId">
/// A string identifier used to preload the ads for that configuration.
/// </param>
/// <returns>
/// The ResponseInfo of the preloaded ad for the given preload ID, or null if no ad is available.
/// </returns>
IResponseInfoClient PeekAdResponseInfo(string preloadId);

/// <summary>
/// Get the number of ads available for the given preload ID.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public IAppOpenAdClient DequeueAd(string preloadId)
return appOpenAdClient;
}

public IResponseInfoClient PeekAdResponseInfo(string preloadId)
{
UnityEngine.Debug.LogError(
"PeekAdResponseInfo API is not available on the Legacy version of Google Mobile Ads Android SDK.");
return null;
}

public int GetNumAdsAvailable(string preloadId)
{
return _unityAppOpenAdPreloader.Call<int>("getNumAdsAvailable", preloadId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ public IAppOpenAdClient DequeueAd(string preloadId) {
return appOpenAdClient;
}

public IResponseInfoClient PeekAdResponseInfo(string preloadId) {
var responseInfo = _unityAppOpenAdPreloader.Call<AndroidJavaObject>(
"peekAdResponseInfo", preloadId);
if (responseInfo == null) {
return null;
}
return new NextGenResponseInfoClient(responseInfo);
}

public int GetNumAdsAvailable(string preloadId) {
return _unityAppOpenAdPreloader.Call<int>("getNumAdsAvailable", preloadId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ public IInterstitialClient DequeueAd(string preloadId) {
}

public IResponseInfoClient PeekAdResponseInfo(string preloadId) {
// TODO: Implement Android Peek API
return null;
var responseInfo = _unityInterstitialAdPreloader.Call<AndroidJavaObject>(
"peekAdResponseInfo", preloadId);
if (responseInfo == null) {
return null;
}
return new NextGenResponseInfoClient(responseInfo);
}

public int GetNumAdsAvailable(string preloadId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ public IRewardedAdClient DequeueAd(string preloadId) {
return rewardedAdClient;
}

public IResponseInfoClient PeekAdResponseInfo(string preloadId) {
var responseInfo = _unityRewardedAdPreloader.Call<AndroidJavaObject>(
"peekAdResponseInfo", preloadId);
if (responseInfo == null) {
return null;
}
return new NextGenResponseInfoClient(responseInfo);
}

public int GetNumAdsAvailable(string preloadId) {
return _unityRewardedAdPreloader.Call<int>("getNumAdsAvailable", preloadId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public IRewardedAdClient DequeueAd(string preloadId)
return rewardedAdClient;
}

public IResponseInfoClient PeekAdResponseInfo(string preloadId)
{
UnityEngine.Debug.LogError(
"PeekAdResponseInfo API is not available on the Legacy version of Google Mobile Ads Android SDK.");
return null;
}

public int GetNumAdsAvailable(string preloadId)
{
return _unityRewardedAdPreloader.Call<int>("getNumAdsAvailable", preloadId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ public IAppOpenAdClient DequeueAd(string preloadId)
return null;
}

public IResponseInfoClient PeekAdResponseInfo(string preloadId)
{
Queue<AppOpenAdClient> queue;
if (_bufferedAds.TryGetValue(preloadId, out queue) && queue.Count > 0)
{
AppOpenAdClient adClient = queue.Peek();
return adClient.GetResponseInfoClient();
}
return null;
}

public int GetNumAdsAvailable(string preloadId)
{
Queue<AppOpenAdClient> queue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ public IRewardedAdClient DequeueAd(string preloadId)
return null;
}

public IResponseInfoClient PeekAdResponseInfo(string preloadId)
{
Queue<RewardedAdClient> queue;
if (_bufferedAds.TryGetValue(preloadId, out queue) && queue.Count > 0)
{
RewardedAdClient adClient = queue.Peek();
return adClient.GetResponseInfoClient();
}
return null;
}

public int GetNumAdsAvailable(string preloadId)
{
Queue<RewardedAdClient> queue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ public IAppOpenAdClient DequeueAd(string preloadId)
return appOpenAdClient;
}

public IResponseInfoClient PeekAdResponseInfo(string preloadId)
{
if (AppOpenAdPreloaderPtr == IntPtr.Zero)
{
return null;
}
var responseInfoPtr = Externs.GADUAppOpenAdPreloaderPeekAdResponseInfo(
AppOpenAdPreloaderPtr, preloadId);
if (responseInfoPtr == IntPtr.Zero)
{
return null;
}
return new ResponseInfoClient(responseInfoPtr);
}

public int GetNumAdsAvailable(string preloadId)
{
if (AppOpenAdPreloaderPtr == IntPtr.Zero)
Expand Down
8 changes: 8 additions & 0 deletions source/plugin/Assets/GoogleMobileAds/Platforms/iOS/Externs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ internal static extern IntPtr GADUAppOpenAdPreloaderDequeueAd(IntPtr appOpenAdPr
string preloadId,
IntPtr appOpenAdClientPtr);

[DllImport("__Internal")]
internal static extern IntPtr GADUAppOpenAdPreloaderPeekAdResponseInfo(
IntPtr appOpenAdPreloader, string preloadId);

[DllImport("__Internal")]
internal static extern int GADUAppOpenAdPreloaderGetNumAdsAvailable(IntPtr appOpenAdPreloader,
string preloadId);
Expand Down Expand Up @@ -370,6 +374,10 @@ internal static extern IntPtr GADURewardedAdPreloaderDequeueAd(IntPtr rewardedAd
string preloadId,
IntPtr appOpenAdClientPtr);

[DllImport("__Internal")]
internal static extern IntPtr GADURewardedAdPreloaderPeekAdResponseInfo(
IntPtr rewardedAdPreloader, string preloadId);

[DllImport("__Internal")]
internal static extern int GADURewardedAdPreloaderGetNumAdsAvailable(
IntPtr rewardedAdPreloader, string preloadId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ public IRewardedAdClient DequeueAd(string preloadId)
return rewardedAdClient;
}

public IResponseInfoClient PeekAdResponseInfo(string preloadId)
{
if (RewardedAdPreloaderPtr == IntPtr.Zero)
{
return null;
}
var responseInfoPtr = Externs.GADURewardedAdPreloaderPeekAdResponseInfo(
RewardedAdPreloaderPtr, preloadId);
if (responseInfoPtr == IntPtr.Zero)
{
return null;
}
return new ResponseInfoClient(responseInfoPtr);
}

public int GetNumAdsAvailable(string preloadId)
{
if (RewardedAdPreloaderPtr == IntPtr.Zero)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public UnityAppOpenAd pollAd(String preloadId, UnityAppOpenAdCallback callback)
return new UnityAppOpenAd(activity, callback, appOpenAd);
}

@Nullable
public ResponseInfo peekAdResponseInfo(String preloadId) {
return preloaderWrapper.peekAdResponseInfo(preloadId);
}

@Nullable
public PreloadConfiguration getConfiguration(String preloadId) {
return preloaderWrapper.getConfiguration(preloadId);
Expand Down Expand Up @@ -140,6 +145,11 @@ public AppOpenAd pollAd(String preloadId) {
return AppOpenAdPreloader.pollAd(preloadId);
}

@Nullable
public ResponseInfo peekAdResponseInfo(String preloadId) {
return AppOpenAdPreloader.peekAdResponseInfo(preloadId);
}

public PreloadConfiguration getConfiguration(String preloadId) {
return AppOpenAdPreloader.getConfiguration(preloadId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public UnityInterstitialAd pollAd(String preloadId, UnityInterstitialAdCallback
return new UnityInterstitialAd(activity, callback, interstitialAd);
}

@Nullable
public ResponseInfo peekAdResponseInfo(String preloadId) {
return preloaderWrapper.peekAdResponseInfo(preloadId);
}

@Nullable
public PreloadConfiguration getConfiguration(String preloadId) {
return preloaderWrapper.getConfiguration(preloadId);
Expand Down Expand Up @@ -140,6 +145,11 @@ public InterstitialAd pollAd(String preloadId) {
return InterstitialAdPreloader.pollAd(preloadId);
}

@Nullable
public ResponseInfo peekAdResponseInfo(String preloadId) {
return InterstitialAdPreloader.peekAdResponseInfo(preloadId);
}

public PreloadConfiguration getConfiguration(String preloadId) {
return InterstitialAdPreloader.getConfiguration(preloadId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public UnityRewardedAd pollAd(String preloadId, UnityRewardedAdCallback callback
return new UnityRewardedAd(activity, callback, rewardedAd);
}

@Nullable
public ResponseInfo peekAdResponseInfo(String preloadId) {
return preloaderWrapper.peekAdResponseInfo(preloadId);
}

@Nullable
public PreloadConfiguration getConfiguration(String preloadId) {
return preloaderWrapper.getConfiguration(preloadId);
Expand Down Expand Up @@ -140,6 +145,11 @@ public RewardedAd pollAd(String preloadId) {
return RewardedAdPreloader.pollAd(preloadId);
}

@Nullable
public ResponseInfo peekAdResponseInfo(String preloadId) {
return RewardedAdPreloader.peekAdResponseInfo(preloadId);
}

public PreloadConfiguration getConfiguration(String preloadId) {
return RewardedAdPreloader.getConfiguration(preloadId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ public void testIsAdAvailable() {
verify(mockWrapper).isAdAvailable(PRELOAD_ID);
}

@Test
public void testPeekAdResponseInfo() {
ResponseInfo responseInfo =
new ResponseInfo("AdapterName", "responseId", new Bundle(), null, new ArrayList<>());
when(mockWrapper.peekAdResponseInfo(PRELOAD_ID)).thenReturn(responseInfo);

ResponseInfo result = unityInterstitialAdPreloader.peekAdResponseInfo(PRELOAD_ID);

assertThat(result).isEqualTo(responseInfo);
verify(mockWrapper).peekAdResponseInfo(PRELOAD_ID);
}

@Test
public void testGetNumAdsAvailable() {
int unused = unityInterstitialAdPreloader.getNumAdsAvailable(PRELOAD_ID);
Expand Down
Loading