Skip to content

Commit

Permalink
Defined read values from host platform to dart layer of the Mediation…
Browse files Browse the repository at this point in the history
… Extras to avoid FormatExceptions
  • Loading branch information
LTPhantom committed Feb 14, 2024
1 parent d73dbc2 commit 722fcff
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class FlutterAdRequest {
@Nullable private final MediationNetworkExtrasProvider mediationNetworkExtrasProvider;
@Nullable private final Map<String, String> adMobExtras;
@NonNull private final String requestAgent;

@Nullable private final List<FlutterMediationExtras> mediationExtras;

protected static class Builder {
Expand Down Expand Up @@ -305,6 +304,11 @@ protected String getRequestAgent() {
return requestAgent;
}

@Nullable
protected List<FlutterMediationExtras> getMediationExtras() {
return mediationExtras;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -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
Expand All @@ -333,6 +338,7 @@ public int hashCode() {
neighboringContentUrls,
httpTimeoutMillis,
mediationExtrasIdentifier,
mediationNetworkExtrasProvider);
mediationNetworkExtrasProvider,
mediationExtras);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions packages/google_mobile_ads/lib/src/ad_instance_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,13 @@ class AdMessageCodec extends StandardMessageCodec {
mediationExtrasIdentifier: readValueOfType(buffer.getUint8(), buffer),
extras: readValueOfType(buffer.getUint8(), buffer)
?.cast<String, String>(),
mediationExtras: readValueOfType(buffer.getUint8(), buffer)
?.cast<List<MediationExtras>>(),
);
case _valueMediationExtras:
// Returns null since there's no need to cast into MediationExtras
// instance
return null;
case _valueRewardItem:
return RewardItem(
readValueOfType(buffer.getUint8(), buffer),
Expand Down Expand Up @@ -1124,6 +1130,8 @@ class AdMessageCodec extends StandardMessageCodec {
mediationExtrasIdentifier: readValueOfType(buffer.getUint8(), buffer),
extras: readValueOfType(buffer.getUint8(), buffer)
?.cast<String, String>(),
mediationExtras: readValueOfType(buffer.getUint8(), buffer)
?.cast<List<MediationExtras>>(),
);
case _valueInitializationState:
switch (readValueOfType(buffer.getUint8(), buffer)) {
Expand Down

0 comments on commit 722fcff

Please sign in to comment.