From 86198bb73e4211f66db49c23acd4af63dd3bd1f3 Mon Sep 17 00:00:00 2001 From: nakirekommula <126601200+nakirekommula@users.noreply.github.com> Date: Fri, 11 Aug 2023 05:22:53 +0530 Subject: [PATCH] Internal Updates. (#1422) * Add logic to trim webp parameter from native image urls --- gma/src/android/native_ad_image_android.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gma/src/android/native_ad_image_android.cc b/gma/src/android/native_ad_image_android.cc index 8c63c9b244..23af8c4fb2 100644 --- a/gma/src/android/native_ad_image_android.cc +++ b/gma/src/android/native_ad_image_android.cc @@ -71,6 +71,15 @@ NativeAdImage::NativeAdImage( FIREBASE_ASSERT(j_uri); internal_->uri = util::JniUriToString(env, j_uri); + // Images requested with an android user agent may return webp images. Trim + // webp parameter from image url to get the original JPG/PNG image. + std::size_t eq_pos = internal_->uri.rfind("="); + std::size_t webp_pos = internal_->uri.rfind("-rw"); + if (webp_pos != std::string::npos && eq_pos != std::string::npos && + webp_pos > eq_pos) { + internal_->uri.replace(webp_pos, 3, ""); + } + // NativeAdImage scale. jdouble j_scale = env->CallDoubleMethod(internal_->native_ad_image,