Skip to content

Commit f6ce35d

Browse files
Mobile Ads Developer Relationscopybara-github
authored andcommitted
Add PeekAdResponseInfo API to AppOpenAdPreloader.
PiperOrigin-RevId: 957225291
1 parent f515681 commit f6ce35d

10 files changed

Lines changed: 99 additions & 1 deletion

File tree

source/plugin/Assets/GoogleMobileAds/Api/AppOpenAdPreloader.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static Dictionary<string, PreloadConfiguration> GetConfigurations()
127127
/// Returns a preloaded ad and removes it from the cache.
128128
/// </summary>
129129
/// <param name="preloadId">
130-
/// The ad's preload ID.
130+
/// A string identifier used to preload the ads for that configuration.
131131
/// </param>
132132
/// <returns>
133133
/// The preloaded ad for the given preload ID, or null if no ad is available.
@@ -146,6 +146,26 @@ public static AppOpenAd DequeueAd(string preloadId)
146146
return new AppOpenAd(client);
147147
}
148148

149+
/// <summary>
150+
/// Returns the ResponseInfo of a preloaded ad for the given preload ID without
151+
/// dequeuing it, or null if no ad is available.
152+
/// </summary>
153+
/// <param name="preloadId">
154+
/// A string identifier used to preload the ads for that configuration.
155+
/// </param>
156+
/// <returns>
157+
/// The ResponseInfo of the preloaded ad for the given preload ID, or null if no ad is available.
158+
/// </returns>
159+
public static ResponseInfo PeekAdResponseInfo(string preloadId)
160+
{
161+
var responseInfoClient = _client.PeekAdResponseInfo(preloadId);
162+
if (responseInfoClient == null)
163+
{
164+
return null;
165+
}
166+
return new ResponseInfo(responseInfoClient);
167+
}
168+
149169
/// <summary>
150170
/// Get the number of ads available for the given preload ID.
151171
/// </summary>

source/plugin/Assets/GoogleMobileAds/Common/IAppOpenAdPreloaderClient.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ bool Preload(string preloadId, PreloadConfiguration preloadConfiguration,
7676
/// </remarks>
7777
IAppOpenAdClient DequeueAd(string preloadId);
7878

79+
/// <summary>
80+
/// Returns the ResponseInfo of an ad available for the given preload ID without
81+
/// dequeuing it, or null if no ad is available.
82+
/// </summary>
83+
/// <param name="preloadId">
84+
/// A string identifier used to preload the ads for that configuration.
85+
/// </param>
86+
/// <returns>
87+
/// The ResponseInfo of the preloaded ad for the given preload ID, or null if no ad is available.
88+
/// </returns>
89+
IResponseInfoClient PeekAdResponseInfo(string preloadId);
90+
7991
/// <summary>
8092
/// Get the number of ads available for the given preload ID.
8193
/// </summary>

source/plugin/Assets/GoogleMobileAds/Platforms/Android/AppOpenAdPreloaderClient.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ public IAppOpenAdClient DequeueAd(string preloadId)
7070
return appOpenAdClient;
7171
}
7272

73+
public IResponseInfoClient PeekAdResponseInfo(string preloadId)
74+
{
75+
UnityEngine.Debug.LogError(
76+
"PeekAdResponseInfo API is not available on the Legacy version of Google Mobile Ads Android SDK.");
77+
return null;
78+
}
79+
7380
public int GetNumAdsAvailable(string preloadId)
7481
{
7582
return _unityAppOpenAdPreloader.Call<int>("getNumAdsAvailable", preloadId);

source/plugin/Assets/GoogleMobileAds/Platforms/Android/NextGenAppOpenAdPreloaderClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public IAppOpenAdClient DequeueAd(string preloadId) {
6262
return appOpenAdClient;
6363
}
6464

65+
public IResponseInfoClient PeekAdResponseInfo(string preloadId) {
66+
// TODO: Implement Android Peek API
67+
return null;
68+
}
69+
6570
public int GetNumAdsAvailable(string preloadId) {
6671
return _unityAppOpenAdPreloader.Call<int>("getNumAdsAvailable", preloadId);
6772
}

source/plugin/Assets/GoogleMobileAds/Platforms/Unity/AppOpenAdPreloaderClient.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ public IAppOpenAdClient DequeueAd(string preloadId)
126126
return null;
127127
}
128128

129+
public IResponseInfoClient PeekAdResponseInfo(string preloadId)
130+
{
131+
Queue<AppOpenAdClient> queue;
132+
if (_bufferedAds.TryGetValue(preloadId, out queue) && queue.Count > 0)
133+
{
134+
AppOpenAdClient adClient = queue.Peek();
135+
return adClient.GetResponseInfoClient();
136+
}
137+
return null;
138+
}
139+
129140
public int GetNumAdsAvailable(string preloadId)
130141
{
131142
Queue<AppOpenAdClient> queue;

source/plugin/Assets/GoogleMobileAds/Platforms/iOS/AppOpenAdPreloaderClient.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ public IAppOpenAdClient DequeueAd(string preloadId)
122122
return appOpenAdClient;
123123
}
124124

125+
public IResponseInfoClient PeekAdResponseInfo(string preloadId)
126+
{
127+
if (AppOpenAdPreloaderPtr == IntPtr.Zero)
128+
{
129+
return null;
130+
}
131+
var responseInfoPtr = Externs.GADUAppOpenAdPreloaderPeekAdResponseInfo(
132+
AppOpenAdPreloaderPtr, preloadId);
133+
if (responseInfoPtr == IntPtr.Zero)
134+
{
135+
return null;
136+
}
137+
return new ResponseInfoClient(responseInfoPtr);
138+
}
139+
125140
public int GetNumAdsAvailable(string preloadId)
126141
{
127142
if (AppOpenAdPreloaderPtr == IntPtr.Zero)

source/plugin/Assets/GoogleMobileAds/Platforms/iOS/Externs.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ internal static extern IntPtr GADUAppOpenAdPreloaderDequeueAd(IntPtr appOpenAdPr
325325
string preloadId,
326326
IntPtr appOpenAdClientPtr);
327327

328+
[DllImport("__Internal")]
329+
internal static extern IntPtr GADUAppOpenAdPreloaderPeekAdResponseInfo(
330+
IntPtr appOpenAdPreloader, string preloadId);
331+
328332
[DllImport("__Internal")]
329333
internal static extern int GADUAppOpenAdPreloaderGetNumAdsAvailable(IntPtr appOpenAdPreloader,
330334
string preloadId);

source/plugin/Assets/Plugins/iOS/GADUAppOpenAdPreloader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
appOpenAdClient:
7979
(_Nonnull GADUTypeAppOpenAdClientRef *_Nonnull)appOpenAdClient;
8080

81+
/// Returns the responseInfo of a preloaded app open ad for the given preload ID.
82+
- (nullable GADResponseInfo *)adResponseInfoWithPreloadID:(nonnull NSString *)preloadID;
83+
8184
/// Returns the corresponding configuration for the given preload ID.
8285
- (nullable GADUPreloadConfigurationV2 *)configurationWithPreloadID:(nonnull NSString *)preloadID;
8386

source/plugin/Assets/Plugins/iOS/GADUAppOpenAdPreloader.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ - (nullable GADUAppOpenAd *)adWithPreloadID:(nonnull NSString *)preloadID
7272
return nil;
7373
}
7474

75+
- (nullable GADResponseInfo *)adResponseInfoWithPreloadID:(nonnull NSString *)preloadID {
76+
return [GADAppOpenAdPreloader.sharedInstance adResponseInfoWithPreloadID:preloadID];
77+
}
78+
7579
- (nullable GADUPreloadConfigurationV2 *)configurationWithPreloadID:(nonnull NSString *)preloadID {
7680
GADPreloadConfigurationV2 *config =
7781
[GADAppOpenAdPreloader.sharedInstance configurationWithPreloadID:preloadID];

source/plugin/Assets/Plugins/iOS/GADUInterface.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,23 @@ GADUTypeAppOpenAdRef GADUAppOpenAdPreloaderDequeueAd(
959959
return nil;
960960
}
961961

962+
GADUTypeResponseInfoRef GADUAppOpenAdPreloaderPeekAdResponseInfo(
963+
GADUTypeAppOpenAdPreloaderRef appOpenAdPreloader, const char *preloadId) {
964+
GADUAppOpenAdPreloader *internalAppOpenAdPreloader =
965+
(__bridge GADUAppOpenAdPreloader *)appOpenAdPreloader;
966+
if (!internalAppOpenAdPreloader) {
967+
return nil;
968+
}
969+
GADResponseInfo *responseInfo = [internalAppOpenAdPreloader
970+
adResponseInfoWithPreloadID:GADUStringFromUTF8String(preloadId)];
971+
if (responseInfo) {
972+
GADUObjectCache *cache = GADUObjectCache.sharedInstance;
973+
cache[responseInfo.gadu_referenceKey] = responseInfo;
974+
return (__bridge GADUTypeResponseInfoRef)responseInfo;
975+
}
976+
return nil;
977+
}
978+
962979
unsigned long GADUAppOpenAdPreloaderGetNumAdsAvailable(
963980
GADUTypeAppOpenAdPreloaderRef appOpenAdPreloader, const char *preloadId) {
964981
GADUAppOpenAdPreloader *internalAppOpenAdPreloader =

0 commit comments

Comments
 (0)