Skip to content

Internal Updates #1439

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 3 commits into from
Sep 22, 2023
Merged
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
19 changes: 16 additions & 3 deletions gma/src/android/gma_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ void JNI_completeLoadedAd(JNIEnv* env, jclass clazz, jlong data_ptr,
void JNI_NativeAd_completeLoadedAd(JNIEnv* env, jclass clazz, jlong data_ptr,
jlong native_internal_data_ptr,
jobject j_icon, jobjectArray j_images,
jobject j_adchoices_icon,
jobject j_response_info) {
FIREBASE_ASSERT(env);
FIREBASE_ASSERT(data_ptr);
Expand All @@ -922,18 +923,30 @@ void JNI_NativeAd_completeLoadedAd(JNIEnv* env, jclass clazz, jlong data_ptr,

// Invoke a friend of NativeAdInternal to update its icon image asset.
GmaInternal::InsertNativeInternalImage(native_ad_internal, icon_internal,
true, true);
"icon", true);
env->DeleteLocalRef(j_icon);
}

// getAdChoicesInfo().getImages() can return an empty list and a valid ad can
// exist without an adchoices icon image.
if (j_adchoices_icon != nullptr) {
NativeAdImageInternal adchoices_icon_internal;
adchoices_icon_internal.native_ad_image = j_adchoices_icon;

// Invoke a friend of NativeAdInternal to update its icon image asset.
GmaInternal::InsertNativeInternalImage(
native_ad_internal, adchoices_icon_internal, "adchoices_icon", true);
env->DeleteLocalRef(j_adchoices_icon);
}

const size_t len = env->GetArrayLength(j_images);
// Loop through images array.
for (size_t i = 0; i < len; ++i) {
jobject j_image = env->GetObjectArrayElement(j_images, i);
NativeAdImageInternal image_internal;
image_internal.native_ad_image = j_image;
GmaInternal::InsertNativeInternalImage(native_ad_internal, image_internal,
false, false);
"image", false);
}

FutureCallbackData<AdResult>* callback_data =
Expand Down Expand Up @@ -1224,7 +1237,7 @@ bool RegisterNatives() {
{"completeNativeLoadedAd",
"(JJLcom/google/android/gms/ads/nativead/NativeAd$Image;[Lcom/google/"
"android/gms/ads/nativead/NativeAd$Image;Lcom/google/android/gms/ads/"
"ResponseInfo;)V",
"nativead/NativeAd$Image;Lcom/google/android/gms/ads/ResponseInfo;)V",
reinterpret_cast<void*>(&JNI_NativeAd_completeLoadedAd)},
{"completeNativeLoadAdError",
"(JLcom/google/android/gms/ads/LoadAdError;ILjava/lang/String;)V",
Expand Down
6 changes: 3 additions & 3 deletions gma/src/common/gma_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ void GmaInternal::UpdateAdViewInternalAdSizeDimensions(

void GmaInternal::InsertNativeInternalImage(
internal::NativeAdInternal* native_ad_internal,
const NativeAdImageInternal& native_image_internal, const bool& is_icon,
const bool& clear_existing_images) {
const NativeAdImageInternal& native_image_internal,
const std::string& image_type, const bool& clear_existing_images) {
assert(native_ad_internal);

if (clear_existing_images) {
native_ad_internal->clear_existing_images();
}
NativeAdImage image_asset = NativeAdImage(native_image_internal);
native_ad_internal->insert_image(image_asset, is_icon);
native_ad_internal->insert_image(image_asset, image_type);
}

// AdInspectorClosedListener
Expand Down
4 changes: 2 additions & 2 deletions gma/src/common/gma_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ class GmaInternal {
// NativeAdInternal.
static void InsertNativeInternalImage(
internal::NativeAdInternal* native_ad_internal,
const NativeAdImageInternal& native_image_internal, const bool& is_icon,
const bool& clear_existing_images);
const NativeAdImageInternal& native_image_internal,
const std::string& image_type, const bool& clear_existing_images);
};

} // namespace gma
Expand Down
4 changes: 4 additions & 0 deletions gma/src/common/native_ad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ const std::vector<NativeAdImage>& NativeAd::images() const {
return internal_->images();
}

const NativeAdImage& NativeAd::adchoices_icon() const {
return internal_->adchoices_icon();
}

Future<void> NativeAd::RecordImpression(const Variant& impression_data) {
if (!impression_data.is_map()) {
return CreateAndCompleteFuture(
Expand Down
7 changes: 5 additions & 2 deletions gma/src/common/native_ad_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ Future<AdResult> NativeAdInternal::GetLoadAdLastResult() {
}

void NativeAdInternal::insert_image(const NativeAdImage& image,
const bool& is_icon) {
if (is_icon) {
const std::string& image_type) {
if (image_type == "icon") {
icon_ = image;
} else if (image_type == "adchoices_icon") {
adchoices_icon_ = image;
} else {
images_.push_back(image);
}
}

void NativeAdInternal::clear_existing_images() { images_.clear(); }

} // namespace internal
Expand Down
9 changes: 8 additions & 1 deletion gma/src/common/native_ad_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class NativeAdInternal {
// Returns the associated image assets of the native ad.
const std::vector<NativeAdImage>& images() const { return images_; }

// Returns the associated icon asset of the native ad.
const NativeAdImage& adchoices_icon() const { return adchoices_icon_; }

// Only used by allowlisted ad units.
virtual Future<void> RecordImpression(const Variant& impression_data) = 0;

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

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

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

// Tracks the native ad image assets.
std::vector<NativeAdImage> images_;

// Tracks the native ad choices icon asset.
NativeAdImage adchoices_icon_;
};

} // namespace internal
Expand Down
3 changes: 3 additions & 0 deletions gma/src/include/firebase/gma/internal/native_ad.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class NativeAd {
/// Returns the associated image assets of the native ad.
const std::vector<NativeAdImage>& images() const;

// Returns the associated adchoices icon asset of the native ad.
const NativeAdImage& adchoices_icon() const;

/// Only allowlisted ad units use this api.
Future<void> RecordImpression(const Variant& impression_data);

Expand Down
3 changes: 3 additions & 0 deletions gma/src/ios/GADNativeAdCpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

@interface GADNativeAd()

/// AdChoices icon image.
@property(nonatomic, readonly, strong, nullable) GADNativeAdImage *adChoicesIcon;

/// Used only by allowlisted ad units. Provide a dictionary containing click data.
- (void)performClickWithData:(nonnull NSDictionary *)clickData;

Expand Down
12 changes: 10 additions & 2 deletions gma/src/ios/native_ad_internal_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,23 @@
{
NativeAdImageInternal icon_internal;
icon_internal.native_ad_image = gad_icon;
GmaInternal::InsertNativeInternalImage(this, icon_internal, true, true );
GmaInternal::InsertNativeInternalImage(this, icon_internal, "icon", true );
}

NSObject *gad_choices_icon = ad.adChoicesIcon;
if (gad_choices_icon != nil)
{
NativeAdImageInternal adchoices_icon_internal;
adchoices_icon_internal.native_ad_image = gad_choices_icon;
GmaInternal::InsertNativeInternalImage(this, adchoices_icon_internal, "adchoices_icon", true );
}

NSArray *gad_images = ad.images;
for(NSObject *gad_image in gad_images)
{
NativeAdImageInternal image_internal;
image_internal.native_ad_image = gad_image;
GmaInternal::InsertNativeInternalImage(this, image_internal, false, false );
GmaInternal::InsertNativeInternalImage(this, image_internal, "image", false );
}

if (ad_load_callback_data_ != nil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,18 @@ public void onNativeAdLoaded(NativeAd ad) {
NativeAd.Image[] imgArray = new NativeAd.Image[imgList.size()];
imgArray = imgList.toArray(imgArray);

NativeAd.Image adChoicesIcon = null;
NativeAd.AdChoicesInfo adChoicesInfo = ad.getAdChoicesInfo();
if (adChoicesInfo != null) {
List<NativeAd.Image> adChoicesImgList = adChoicesInfo.getImages();
if (!adChoicesImgList.isEmpty()) {
// Gets only the first image to keep the api in sync with its ios counterpart.
adChoicesIcon = adChoicesImgList.get(0);
}
}

completeNativeLoadedAd(mLoadAdCallbackDataPtr, mNativeAdInternalPtr, ad.getIcon(),
imgArray, ad.getResponseInfo());
imgArray, adChoicesIcon, ad.getResponseInfo());
mLoadAdCallbackDataPtr = CPP_NULLPTR;
}
}
Expand All @@ -262,7 +272,7 @@ public static native void completeNativeAdFutureCallback(
/** Native callback invoked upon successfully loading an ad. */
public static native void completeNativeLoadedAd(long nativeInternalPtr,
long mNativeAdInternalPtr, NativeAd.Image icon, NativeAd.Image[] images,
ResponseInfo responseInfo);
NativeAd.Image adChoicesIcon, ResponseInfo responseInfo);

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