From 722fcffe0365596ab84f6e01fa985f234a60f8cd Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Tue, 13 Feb 2024 16:22:17 -0800 Subject: [PATCH] Defined read values from host platform to dart layer of the Mediation Extras to avoid FormatExceptions --- .../plugins/googlemobileads/AdMessageCodec.java | 4 ++++ .../plugins/googlemobileads/FlutterAdRequest.java | 12 +++++++++--- .../FLTGoogleMobileAdsReaderWriter_Internal.m | 3 +++ .../lib/src/ad_instance_manager.dart | 8 ++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/AdMessageCodec.java b/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/AdMessageCodec.java index 9ebd90420..dfa5f888e 100644 --- a/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/AdMessageCodec.java +++ b/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/AdMessageCodec.java @@ -117,6 +117,7 @@ protected void writeValue(ByteArrayOutputStream stream, Object value) { writeValue(stream, request.getPublisherProvidedId()); writeValue(stream, request.getMediationExtrasIdentifier()); writeValue(stream, request.getAdMobExtras()); + writeValue(stream, request.getMediationExtras()); } else if (value instanceof FlutterAdRequest) { stream.write(VALUE_AD_REQUEST); final FlutterAdRequest request = (FlutterAdRequest) value; @@ -127,6 +128,9 @@ protected void writeValue(ByteArrayOutputStream stream, Object value) { writeValue(stream, request.getHttpTimeoutMillis()); writeValue(stream, request.getMediationExtrasIdentifier()); writeValue(stream, request.getAdMobExtras()); + writeValue(stream, request.getMediationExtras()); + } else if (value instanceof FlutterMediationExtras) { + // Left empty since there's no need to write it back to the dart layer } else if (value instanceof FlutterRewardedAd.FlutterRewardItem) { stream.write(VALUE_REWARD_ITEM); final FlutterRewardedAd.FlutterRewardItem item = (FlutterRewardedAd.FlutterRewardItem) value; diff --git a/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/FlutterAdRequest.java b/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/FlutterAdRequest.java index e6ae123ad..86d43435d 100644 --- a/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/FlutterAdRequest.java +++ b/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/FlutterAdRequest.java @@ -38,7 +38,6 @@ class FlutterAdRequest { @Nullable private final MediationNetworkExtrasProvider mediationNetworkExtrasProvider; @Nullable private final Map adMobExtras; @NonNull private final String requestAgent; - @Nullable private final List mediationExtras; protected static class Builder { @@ -305,6 +304,11 @@ protected String getRequestAgent() { return requestAgent; } + @Nullable + protected List getMediationExtras() { + return mediationExtras; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -321,7 +325,8 @@ public boolean equals(Object o) { && Objects.equals(httpTimeoutMillis, request.httpTimeoutMillis) && Objects.equals(mediationExtrasIdentifier, request.mediationExtrasIdentifier) && Objects.equals(mediationNetworkExtrasProvider, request.mediationNetworkExtrasProvider) - && Objects.equals(adMobExtras, request.adMobExtras); + && Objects.equals(adMobExtras, request.adMobExtras) + && Objects.equals(mediationExtras, request.mediationExtras); } @Override @@ -333,6 +338,7 @@ public int hashCode() { neighboringContentUrls, httpTimeoutMillis, mediationExtrasIdentifier, - mediationNetworkExtrasProvider); + mediationNetworkExtrasProvider, + mediationExtras); } } diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.m index 58481db7a..26ca5223a 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.m @@ -397,6 +397,9 @@ - (void)writeValue:(id)value { [self writeValue:request.neighboringContentURLs]; [self writeValue:request.mediationExtrasIdentifier]; [self writeValue:request.adMobExtras]; + [self writeValue:request.mediationExtras]; + } else if ([value conformsToProtocol:@protocol(FlutterMediationExtras)) { + // Left empty since there's no need to write it back to the dart layer } else if ([value isKindOfClass:[FLTRewardItem class]]) { [self writeByte:FLTAdMobFieldRewardItem]; FLTRewardItem *item = value; diff --git a/packages/google_mobile_ads/lib/src/ad_instance_manager.dart b/packages/google_mobile_ads/lib/src/ad_instance_manager.dart index 82c1f57ac..2ca5069d5 100644 --- a/packages/google_mobile_ads/lib/src/ad_instance_manager.dart +++ b/packages/google_mobile_ads/lib/src/ad_instance_manager.dart @@ -1065,7 +1065,13 @@ class AdMessageCodec extends StandardMessageCodec { mediationExtrasIdentifier: readValueOfType(buffer.getUint8(), buffer), extras: readValueOfType(buffer.getUint8(), buffer) ?.cast(), + mediationExtras: readValueOfType(buffer.getUint8(), buffer) + ?.cast>(), ); + case _valueMediationExtras: + // Returns null since there's no need to cast into MediationExtras + // instance + return null; case _valueRewardItem: return RewardItem( readValueOfType(buffer.getUint8(), buffer), @@ -1124,6 +1130,8 @@ class AdMessageCodec extends StandardMessageCodec { mediationExtrasIdentifier: readValueOfType(buffer.getUint8(), buffer), extras: readValueOfType(buffer.getUint8(), buffer) ?.cast(), + mediationExtras: readValueOfType(buffer.getUint8(), buffer) + ?.cast>(), ); case _valueInitializationState: switch (readValueOfType(buffer.getUint8(), buffer)) {