From f0514246ee10ef123664f42797b0fa35da3ff5a1 Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Tue, 7 May 2024 09:31:40 -0700 Subject: [PATCH] General code health improvement for release (#1070) * Addressed issue of Dart conventions and Static analysis * Suppressed deprecation warnings --- packages/google_mobile_ads/README.md | 2 +- .../googlemobileads/AdMessageCodec.java | 8 +++- .../FlutterAdManagerAdRequest.java | 1 + .../googlemobileads/FlutterAdRequest.java | 15 ++++++- .../GoogleMobileAdsPlugin.java | 6 ++- .../lib/src/ad_containers.dart | 40 ++++++++++++++++++- .../lib/src/ad_instance_manager.dart | 2 +- .../lib/src/ump/consent_form_impl.dart | 3 ++ .../src/ump/consent_request_parameters.dart | 7 ++++ .../lib/src/ump/form_error.dart | 3 ++ 10 files changed, 78 insertions(+), 9 deletions(-) diff --git a/packages/google_mobile_ads/README.md b/packages/google_mobile_ads/README.md index 922f5a4e5..622eb3c9e 100644 --- a/packages/google_mobile_ads/README.md +++ b/packages/google_mobile_ads/README.md @@ -30,4 +30,4 @@ use [github's issue tracker](https://github.com/googleads/googleads-mobile-flutt ## License -[Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0.html) \ No newline at end of file +[Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0) \ No newline at end of file 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 1ea1eaa3b..91dd267cc 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 @@ -41,7 +41,6 @@ * Encodes and decodes values by reading from a ByteBuffer and writing to a ByteArrayOutputStream. */ class AdMessageCodec extends StandardMessageCodec { - // The type values below must be consistent for each platform. private static final byte VALUE_AD_SIZE = (byte) 128; private static final byte VALUE_AD_REQUEST = (byte) 129; @@ -71,7 +70,11 @@ class AdMessageCodec extends StandardMessageCodec { @NonNull Context context; @NonNull final FlutterAdSize.AdSizeFactory adSizeFactory; - @Nullable private MediationNetworkExtrasProvider mediationNetworkExtrasProvider; + + @SuppressWarnings("deprecation") + @Nullable + private MediationNetworkExtrasProvider mediationNetworkExtrasProvider; + @NonNull private final FlutterRequestAgentProvider requestAgentProvider; AdMessageCodec( @@ -95,6 +98,7 @@ void setContext(@NonNull Context context) { this.context = context; } + @SuppressWarnings("deprecation") void setMediationNetworkExtrasProvider( @Nullable MediationNetworkExtrasProvider mediationNetworkExtrasProvider) { this.mediationNetworkExtrasProvider = mediationNetworkExtrasProvider; diff --git a/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/FlutterAdManagerAdRequest.java b/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/FlutterAdManagerAdRequest.java index 8d055bb38..68c86b63a 100644 --- a/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/FlutterAdManagerAdRequest.java +++ b/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/FlutterAdManagerAdRequest.java @@ -76,6 +76,7 @@ FlutterAdManagerAdRequest build() { } } + @SuppressWarnings("deprecation") private FlutterAdManagerAdRequest( @Nullable List keywords, @Nullable String contentUrl, 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 9f6186949..53ee98f91 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 @@ -36,7 +36,11 @@ class FlutterAdRequest { @Nullable private final List neighboringContentUrls; @Nullable private final Integer httpTimeoutMillis; @Nullable private final String mediationExtrasIdentifier; - @Nullable private final MediationNetworkExtrasProvider mediationNetworkExtrasProvider; + + @SuppressWarnings("deprecation") + @Nullable + private final MediationNetworkExtrasProvider mediationNetworkExtrasProvider; + @Nullable private final Map adMobExtras; @NonNull private final String requestAgent; @Nullable private final List mediationExtras; @@ -48,7 +52,11 @@ protected static class Builder { @Nullable private List neighboringContentUrls; @Nullable private Integer httpTimeoutMillis; @Nullable private String mediationExtrasIdentifier; - @Nullable private MediationNetworkExtrasProvider mediationNetworkExtrasProvider; + + @SuppressWarnings("deprecation") + @Nullable + private MediationNetworkExtrasProvider mediationNetworkExtrasProvider; + @Nullable private Map adMobExtras; @NonNull private String requestAgent; @@ -97,6 +105,7 @@ Builder setMediationNetworkExtrasIdentifier(@Nullable String mediationExtrasIden } @CanIgnoreReturnValue + @SuppressWarnings("deprecation") Builder setMediationNetworkExtrasProvider( @Nullable MediationNetworkExtrasProvider mediationNetworkExtrasProvider) { this.mediationNetworkExtrasProvider = mediationNetworkExtrasProvider; @@ -145,6 +154,7 @@ protected String getMediationExtrasIdentifier() { return mediationExtrasIdentifier; } + @SuppressWarnings("deprecation") @Nullable protected MediationNetworkExtrasProvider getMediationNetworkExtrasProvider() { return mediationNetworkExtrasProvider; @@ -180,6 +190,7 @@ FlutterAdRequest build() { } } + @SuppressWarnings("deprecation") protected FlutterAdRequest( @Nullable List keywords, @Nullable String contentUrl, diff --git a/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/GoogleMobileAdsPlugin.java b/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/GoogleMobileAdsPlugin.java index e9d4b3444..89cc8b589 100644 --- a/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/GoogleMobileAdsPlugin.java +++ b/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/GoogleMobileAdsPlugin.java @@ -68,7 +68,11 @@ private static T requireNonNull(T obj) { @Nullable private AppStateNotifier appStateNotifier; @Nullable private UserMessagingPlatformManager userMessagingPlatformManager; private final Map nativeAdFactories = new HashMap<>(); - @Nullable private MediationNetworkExtrasProvider mediationNetworkExtrasProvider; + + @SuppressWarnings("deprecation") + @Nullable + private MediationNetworkExtrasProvider mediationNetworkExtrasProvider; + private final FlutterMobileAdsWrapper flutterMobileAds; /** * Public constructor for the plugin. Dependency initialization is handled in lifecycle methods diff --git a/packages/google_mobile_ads/lib/src/ad_containers.dart b/packages/google_mobile_ads/lib/src/ad_containers.dart index 80d679c15..83a038b7f 100644 --- a/packages/google_mobile_ads/lib/src/ad_containers.dart +++ b/packages/google_mobile_ads/lib/src/ad_containers.dart @@ -198,7 +198,8 @@ class AdRequest { this.neighboringContentUrls, this.nonPersonalizedAds, this.httpTimeoutMillis, - @deprecated this.mediationExtrasIdentifier, + @Deprecated('Use mediationExtras instead.') + this.mediationExtrasIdentifier, this.extras, this.mediationExtras}); @@ -230,7 +231,7 @@ class AdRequest { /// to the ad request. This identifier will get passed to your platform-side /// mediation extras factory class, allowing for additional customization /// of network extras. - @deprecated + @Deprecated('Use mediationExtras instead.') final String? mediationExtrasIdentifier; /// Extras to pass to the AdMob adapter. @@ -252,6 +253,18 @@ class AdRequest { mapEquals(extras, other.extras) && mediationExtras == other.mediationExtras; } + + @override + int get hashCode => Object.hash( + keywords, + contentUrl, + nonPersonalizedAds, + neighboringContentUrls, + httpTimeoutMillis, + //ignore: deprecated_member_use_from_same_package + mediationExtrasIdentifier, + extras, + mediationExtras); } /// Targeting info per the Ad Manager API. @@ -303,6 +316,10 @@ class AdManagerAdRequest extends AdRequest { other.customTargetingLists.toString() && publisherProvidedId == other.publisherProvidedId; } + + @override + int get hashCode => + Object.hash(customTargeting, customTargetingLists, publisherProvidedId); } /// An [AdSize] with the given width and a Google-optimized height to create a banner ad. @@ -554,6 +571,9 @@ class AdSize { bool operator ==(Object other) { return other is AdSize && width == other.width && height == other.height; } + + @override + int get hashCode => Object.hash(width, height); } /// The base class for all ads. @@ -1353,6 +1373,9 @@ class ServerSideVerificationOptions { userId == other.userId && customData == other.customData; } + + @override + int get hashCode => Object.hash(userId, customData); } /// A full-screen app open ad for the Google Mobile Ads Plugin. @@ -1505,6 +1528,15 @@ class NativeAdOptions { shouldRequestMultipleImages == other.shouldRequestMultipleImages && shouldReturnUrlsForImageAssets == other.shouldReturnUrlsForImageAssets; } + + @override + int get hashCode => Object.hash( + adChoicesPlacement, + mediaAspectRatio, + videoOptions, + requestCustomMuteThisAd, + shouldRequestMultipleImages, + shouldReturnUrlsForImageAssets); } /// Options for controlling video playback in supported ad formats. @@ -1539,4 +1571,8 @@ class VideoOptions { customControlsRequested == other.customControlsRequested && startMuted == other.startMuted; } + + @override + int get hashCode => + Object.hash(clickToExpandRequested, customControlsRequested, startMuted); } 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 3bb29bcb6..9b93ad3e6 100644 --- a/packages/google_mobile_ads/lib/src/ad_instance_manager.dart +++ b/packages/google_mobile_ads/lib/src/ad_instance_manager.dart @@ -1270,7 +1270,7 @@ class AdMessageCodec extends StandardMessageCodec { writeValue(buffer, value.orientationValue); } else if (value is AnchoredAdaptiveBannerAdSize) { buffer.putUint8(_valueAnchoredAdaptiveBannerAdSize); - var orientationValue; + String? orientationValue; if (value.orientation != null) { orientationValue = (value.orientation as Orientation).name; } diff --git a/packages/google_mobile_ads/lib/src/ump/consent_form_impl.dart b/packages/google_mobile_ads/lib/src/ump/consent_form_impl.dart index 45dff718d..8ad486f75 100644 --- a/packages/google_mobile_ads/lib/src/ump/consent_form_impl.dart +++ b/packages/google_mobile_ads/lib/src/ump/consent_form_impl.dart @@ -37,4 +37,7 @@ class ConsentFormImpl extends ConsentForm { bool operator ==(Object other) { return other is ConsentFormImpl && platformHash == other.platformHash; } + + @override + int get hashCode => platformHash.hashCode; } diff --git a/packages/google_mobile_ads/lib/src/ump/consent_request_parameters.dart b/packages/google_mobile_ads/lib/src/ump/consent_request_parameters.dart index 91f5f346e..7873c0abc 100644 --- a/packages/google_mobile_ads/lib/src/ump/consent_request_parameters.dart +++ b/packages/google_mobile_ads/lib/src/ump/consent_request_parameters.dart @@ -34,6 +34,10 @@ class ConsentRequestParameters { tagForUnderAgeOfConsent == other.tagForUnderAgeOfConsent && consentDebugSettings == other.consentDebugSettings; } + + @override + int get hashCode => + Object.hash(tagForUnderAgeOfConsent, consentDebugSettings); } /// Debug settings to hardcode in test requests. @@ -55,6 +59,9 @@ class ConsentDebugSettings { debugGeography == other.debugGeography && listEquals(testIdentifiers, other.testIdentifiers); } + + @override + int get hashCode => Object.hash(debugGeography, testIdentifiers); } /// Debug values for testing geography. diff --git a/packages/google_mobile_ads/lib/src/ump/form_error.dart b/packages/google_mobile_ads/lib/src/ump/form_error.dart index 911e5fb58..7ff1c006d 100644 --- a/packages/google_mobile_ads/lib/src/ump/form_error.dart +++ b/packages/google_mobile_ads/lib/src/ump/form_error.dart @@ -37,4 +37,7 @@ class FormError { errorCode == other.errorCode && message == other.message; } + + @override + int get hashCode => Object.hash(errorCode, message); }