Skip to content

Commit 55416d7

Browse files
Internal Updates (#1439)
* Internal Updates
1 parent f81dfe1 commit 55416d7

File tree

10 files changed

+66
-15
lines changed

10 files changed

+66
-15
lines changed

gma/src/android/gma_android.cc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,7 @@ void JNI_completeLoadedAd(JNIEnv* env, jclass clazz, jlong data_ptr,
904904
void JNI_NativeAd_completeLoadedAd(JNIEnv* env, jclass clazz, jlong data_ptr,
905905
jlong native_internal_data_ptr,
906906
jobject j_icon, jobjectArray j_images,
907+
jobject j_adchoices_icon,
907908
jobject j_response_info) {
908909
FIREBASE_ASSERT(env);
909910
FIREBASE_ASSERT(data_ptr);
@@ -922,18 +923,30 @@ void JNI_NativeAd_completeLoadedAd(JNIEnv* env, jclass clazz, jlong data_ptr,
922923

923924
// Invoke a friend of NativeAdInternal to update its icon image asset.
924925
GmaInternal::InsertNativeInternalImage(native_ad_internal, icon_internal,
925-
true, true);
926+
"icon", true);
926927
env->DeleteLocalRef(j_icon);
927928
}
928929

930+
// getAdChoicesInfo().getImages() can return an empty list and a valid ad can
931+
// exist without an adchoices icon image.
932+
if (j_adchoices_icon != nullptr) {
933+
NativeAdImageInternal adchoices_icon_internal;
934+
adchoices_icon_internal.native_ad_image = j_adchoices_icon;
935+
936+
// Invoke a friend of NativeAdInternal to update its icon image asset.
937+
GmaInternal::InsertNativeInternalImage(
938+
native_ad_internal, adchoices_icon_internal, "adchoices_icon", true);
939+
env->DeleteLocalRef(j_adchoices_icon);
940+
}
941+
929942
const size_t len = env->GetArrayLength(j_images);
930943
// Loop through images array.
931944
for (size_t i = 0; i < len; ++i) {
932945
jobject j_image = env->GetObjectArrayElement(j_images, i);
933946
NativeAdImageInternal image_internal;
934947
image_internal.native_ad_image = j_image;
935948
GmaInternal::InsertNativeInternalImage(native_ad_internal, image_internal,
936-
false, false);
949+
"image", false);
937950
}
938951

939952
FutureCallbackData<AdResult>* callback_data =
@@ -1224,7 +1237,7 @@ bool RegisterNatives() {
12241237
{"completeNativeLoadedAd",
12251238
"(JJLcom/google/android/gms/ads/nativead/NativeAd$Image;[Lcom/google/"
12261239
"android/gms/ads/nativead/NativeAd$Image;Lcom/google/android/gms/ads/"
1227-
"ResponseInfo;)V",
1240+
"nativead/NativeAd$Image;Lcom/google/android/gms/ads/ResponseInfo;)V",
12281241
reinterpret_cast<void*>(&JNI_NativeAd_completeLoadedAd)},
12291242
{"completeNativeLoadAdError",
12301243
"(JLcom/google/android/gms/ads/LoadAdError;ILjava/lang/String;)V",

gma/src/common/gma_common.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ void GmaInternal::UpdateAdViewInternalAdSizeDimensions(
123123

124124
void GmaInternal::InsertNativeInternalImage(
125125
internal::NativeAdInternal* native_ad_internal,
126-
const NativeAdImageInternal& native_image_internal, const bool& is_icon,
127-
const bool& clear_existing_images) {
126+
const NativeAdImageInternal& native_image_internal,
127+
const std::string& image_type, const bool& clear_existing_images) {
128128
assert(native_ad_internal);
129129

130130
if (clear_existing_images) {
131131
native_ad_internal->clear_existing_images();
132132
}
133133
NativeAdImage image_asset = NativeAdImage(native_image_internal);
134-
native_ad_internal->insert_image(image_asset, is_icon);
134+
native_ad_internal->insert_image(image_asset, image_type);
135135
}
136136

137137
// AdInspectorClosedListener

gma/src/common/gma_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ class GmaInternal {
200200
// NativeAdInternal.
201201
static void InsertNativeInternalImage(
202202
internal::NativeAdInternal* native_ad_internal,
203-
const NativeAdImageInternal& native_image_internal, const bool& is_icon,
204-
const bool& clear_existing_images);
203+
const NativeAdImageInternal& native_image_internal,
204+
const std::string& image_type, const bool& clear_existing_images);
205205
};
206206

207207
} // namespace gma

gma/src/common/native_ad.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ const std::vector<NativeAdImage>& NativeAd::images() const {
8585
return internal_->images();
8686
}
8787

88+
const NativeAdImage& NativeAd::adchoices_icon() const {
89+
return internal_->adchoices_icon();
90+
}
91+
8892
Future<void> NativeAd::RecordImpression(const Variant& impression_data) {
8993
if (!impression_data.is_map()) {
9094
return CreateAndCompleteFuture(

gma/src/common/native_ad_internal.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ Future<AdResult> NativeAdInternal::GetLoadAdLastResult() {
6262
}
6363

6464
void NativeAdInternal::insert_image(const NativeAdImage& image,
65-
const bool& is_icon) {
66-
if (is_icon) {
65+
const std::string& image_type) {
66+
if (image_type == "icon") {
6767
icon_ = image;
68+
} else if (image_type == "adchoices_icon") {
69+
adchoices_icon_ = image;
6870
} else {
6971
images_.push_back(image);
7072
}
7173
}
74+
7275
void NativeAdInternal::clear_existing_images() { images_.clear(); }
7376

7477
} // namespace internal

gma/src/common/native_ad_internal.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class NativeAdInternal {
7070
// Returns the associated image assets of the native ad.
7171
const std::vector<NativeAdImage>& images() const { return images_; }
7272

73+
// Returns the associated icon asset of the native ad.
74+
const NativeAdImage& adchoices_icon() const { return adchoices_icon_; }
75+
7376
// Only used by allowlisted ad units.
7477
virtual Future<void> RecordImpression(const Variant& impression_data) = 0;
7578

@@ -86,7 +89,8 @@ class NativeAdInternal {
8689
explicit NativeAdInternal(NativeAd* base);
8790

8891
// Invoked after a native ad has been loaded to fill native ad image assets.
89-
void insert_image(const NativeAdImage& ad_image, const bool& is_icon);
92+
void insert_image(const NativeAdImage& ad_image,
93+
const std::string& image_type);
9094

9195
// Invoked before filling native ad image assets.
9296
void clear_existing_images();
@@ -102,6 +106,9 @@ class NativeAdInternal {
102106

103107
// Tracks the native ad image assets.
104108
std::vector<NativeAdImage> images_;
109+
110+
// Tracks the native ad choices icon asset.
111+
NativeAdImage adchoices_icon_;
105112
};
106113

107114
} // namespace internal

gma/src/include/firebase/gma/internal/native_ad.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class NativeAd {
7373
/// Returns the associated image assets of the native ad.
7474
const std::vector<NativeAdImage>& images() const;
7575

76+
// Returns the associated adchoices icon asset of the native ad.
77+
const NativeAdImage& adchoices_icon() const;
78+
7679
/// Only allowlisted ad units use this api.
7780
Future<void> RecordImpression(const Variant& impression_data);
7881

gma/src/ios/GADNativeAdCpp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
@interface GADNativeAd()
2222

23+
/// AdChoices icon image.
24+
@property(nonatomic, readonly, strong, nullable) GADNativeAdImage *adChoicesIcon;
25+
2326
/// Used only by allowlisted ad units. Provide a dictionary containing click data.
2427
- (void)performClickWithData:(nonnull NSDictionary *)clickData;
2528

gma/src/ios/native_ad_internal_ios.mm

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,23 @@
227227
{
228228
NativeAdImageInternal icon_internal;
229229
icon_internal.native_ad_image = gad_icon;
230-
GmaInternal::InsertNativeInternalImage(this, icon_internal, true, true );
230+
GmaInternal::InsertNativeInternalImage(this, icon_internal, "icon", true );
231+
}
232+
233+
NSObject *gad_choices_icon = ad.adChoicesIcon;
234+
if (gad_choices_icon != nil)
235+
{
236+
NativeAdImageInternal adchoices_icon_internal;
237+
adchoices_icon_internal.native_ad_image = gad_choices_icon;
238+
GmaInternal::InsertNativeInternalImage(this, adchoices_icon_internal, "adchoices_icon", true );
231239
}
232240

233241
NSArray *gad_images = ad.images;
234242
for(NSObject *gad_image in gad_images)
235243
{
236244
NativeAdImageInternal image_internal;
237245
image_internal.native_ad_image = gad_image;
238-
GmaInternal::InsertNativeInternalImage(this, image_internal, false, false );
246+
GmaInternal::InsertNativeInternalImage(this, image_internal, "image", false );
239247
}
240248

241249
if (ad_load_callback_data_ != nil) {

gma/src_java/com/google/firebase/gma/internal/cpp/NativeAdHelper.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,18 @@ public void onNativeAdLoaded(NativeAd ad) {
247247
NativeAd.Image[] imgArray = new NativeAd.Image[imgList.size()];
248248
imgArray = imgList.toArray(imgArray);
249249

250+
NativeAd.Image adChoicesIcon = null;
251+
NativeAd.AdChoicesInfo adChoicesInfo = ad.getAdChoicesInfo();
252+
if (adChoicesInfo != null) {
253+
List<NativeAd.Image> adChoicesImgList = adChoicesInfo.getImages();
254+
if (!adChoicesImgList.isEmpty()) {
255+
// Gets only the first image to keep the api in sync with its ios counterpart.
256+
adChoicesIcon = adChoicesImgList.get(0);
257+
}
258+
}
259+
250260
completeNativeLoadedAd(mLoadAdCallbackDataPtr, mNativeAdInternalPtr, ad.getIcon(),
251-
imgArray, ad.getResponseInfo());
261+
imgArray, adChoicesIcon, ad.getResponseInfo());
252262
mLoadAdCallbackDataPtr = CPP_NULLPTR;
253263
}
254264
}
@@ -262,7 +272,7 @@ public static native void completeNativeAdFutureCallback(
262272
/** Native callback invoked upon successfully loading an ad. */
263273
public static native void completeNativeLoadedAd(long nativeInternalPtr,
264274
long mNativeAdInternalPtr, NativeAd.Image icon, NativeAd.Image[] images,
265-
ResponseInfo responseInfo);
275+
NativeAd.Image adChoicesIcon, ResponseInfo responseInfo);
266276

267277
/**
268278
* Native callback upon encountering an error loading an Ad Request. Returns Android Google Mobile

0 commit comments

Comments
 (0)