From 086eab173319c22c76029f6aaee1619c00267e5f Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Wed, 17 Apr 2024 16:34:14 -0700 Subject: [PATCH 1/4] Inmobi Adapter | Implementation of Mediation Extras (#1057) * Mediation Extras implementation * Added permissions to manifest --- .../gradle/wrapper/gradle-wrapper.properties | 7 + .../android/src/main/AndroidManifest.xml | 3 + .../InMobiFlutterMediationExtras.kt | 128 ++++++++++++++++++ .../InMobiFlutterMediationExtras.swift | 106 +++++++++++++++ .../lib/inmobi_mediation_extras.dart | 110 +++++++++++++++ 5 files changed, 354 insertions(+) create mode 100644 packages/mediation/gma_mediation_inmobi/android/gradle/wrapper/gradle-wrapper.properties create mode 100644 packages/mediation/gma_mediation_inmobi/android/src/main/kotlin/io/flutter/plugins/googlemobileads/mediation/gma_mediation_inmobi/InMobiFlutterMediationExtras.kt create mode 100644 packages/mediation/gma_mediation_inmobi/ios/Classes/InMobiFlutterMediationExtras.swift create mode 100644 packages/mediation/gma_mediation_inmobi/lib/inmobi_mediation_extras.dart diff --git a/packages/mediation/gma_mediation_inmobi/android/gradle/wrapper/gradle-wrapper.properties b/packages/mediation/gma_mediation_inmobi/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..62f495dfe --- /dev/null +++ b/packages/mediation/gma_mediation_inmobi/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/packages/mediation/gma_mediation_inmobi/android/src/main/AndroidManifest.xml b/packages/mediation/gma_mediation_inmobi/android/src/main/AndroidManifest.xml index da19ff5c1..4c5e032fd 100644 --- a/packages/mediation/gma_mediation_inmobi/android/src/main/AndroidManifest.xml +++ b/packages/mediation/gma_mediation_inmobi/android/src/main/AndroidManifest.xml @@ -1,3 +1,6 @@ + + + diff --git a/packages/mediation/gma_mediation_inmobi/android/src/main/kotlin/io/flutter/plugins/googlemobileads/mediation/gma_mediation_inmobi/InMobiFlutterMediationExtras.kt b/packages/mediation/gma_mediation_inmobi/android/src/main/kotlin/io/flutter/plugins/googlemobileads/mediation/gma_mediation_inmobi/InMobiFlutterMediationExtras.kt new file mode 100644 index 000000000..69ad5dbb5 --- /dev/null +++ b/packages/mediation/gma_mediation_inmobi/android/src/main/kotlin/io/flutter/plugins/googlemobileads/mediation/gma_mediation_inmobi/InMobiFlutterMediationExtras.kt @@ -0,0 +1,128 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package io.flutter.plugins.googlemobileads.mediation.gma_mediation_inmobi + +import android.os.Bundle +import android.util.Log +import android.util.Pair +import androidx.core.os.bundleOf +import com.google.ads.mediation.inmobi.InMobiAdapter +import com.google.ads.mediation.inmobi.InMobiNetworkKeys +import com.google.ads.mediation.inmobi.InMobiNetworkValues +import com.google.android.gms.ads.mediation.MediationExtrasReceiver +import io.flutter.plugins.googlemobileads.FlutterMediationExtras + +class InMobiFlutterMediationExtras : FlutterMediationExtras() { + private var flutterExtras: Map? = null + + override fun setMediationExtras(extras: MutableMap) { + flutterExtras = extras + } + + override fun getMediationExtras(): Pair, Bundle> { + val extrasMap = flutterExtras + if (extrasMap == null) { + return Pair, Bundle>(InMobiAdapter::class.java, bundleOf()) + } + val extrasBundle = bundleOf() + val ageGroupValue = extrasMap[AGE_GROUP] + if (ageGroupValue is Int) { + Log.d("InMobiMediationExtras", "ageGroup: $ageGroupValue") + when(ageGroupValue) { + 0 -> extrasBundle.putString(InMobiNetworkKeys.AGE_GROUP, InMobiNetworkValues.BELOW_18) + 1 -> extrasBundle.putString(InMobiNetworkKeys.AGE_GROUP, InMobiNetworkValues.BETWEEN_18_AND_24) + 2 -> extrasBundle.putString(InMobiNetworkKeys.AGE_GROUP, InMobiNetworkValues.BETWEEN_25_AND_29) + 3 -> extrasBundle.putString(InMobiNetworkKeys.AGE_GROUP, InMobiNetworkValues.BETWEEN_30_AND_34) + 4 -> extrasBundle.putString(InMobiNetworkKeys.AGE_GROUP, InMobiNetworkValues.BETWEEN_35_AND_44) + 5 -> extrasBundle.putString(InMobiNetworkKeys.AGE_GROUP, InMobiNetworkValues.BETWEEN_45_AND_54) + 6 -> extrasBundle.putString(InMobiNetworkKeys.AGE_GROUP, InMobiNetworkValues.BETWEEN_55_AND_65) + 7 -> extrasBundle.putString(InMobiNetworkKeys.AGE_GROUP, InMobiNetworkValues.ABOVE_65) + } + } + val educationValue = extrasMap[EDUCATION] + if (educationValue is Int) { + Log.d("InMobiMediationExtras", "education: $educationValue") + when (educationValue) { + 0 -> extrasBundle.putString(InMobiNetworkKeys.EDUCATION, InMobiNetworkValues.EDUCATION_HIGHSCHOOLORLESS) + 1 -> extrasBundle.putString(InMobiNetworkKeys.EDUCATION, InMobiNetworkValues.EDUCATION_COLLEGEORGRADUATE) + 2 -> extrasBundle.putString(InMobiNetworkKeys.EDUCATION, InMobiNetworkValues.EDUCATION_POSTGRADUATEORABOVE) + } + } + val ageValue = extrasMap[AGE] + if (ageValue is Int) { + Log.d("InMobiMediationExtras", "age: $ageValue") + extrasBundle.putString(InMobiNetworkKeys.AGE, ageValue.toString()) + } + val postalCodeValue = extrasMap[POSTAL_CODE] + if (postalCodeValue is String) { + Log.d("InMobiMediationExtras", "postalCode: $postalCodeValue") + extrasBundle.putString(InMobiNetworkKeys.POSTAL_CODE, postalCodeValue) + } + val areaCodeValue = extrasMap[AREA_CODE] + if (areaCodeValue is String) { + Log.d("InMobiMediationExtras", "areaCode: $areaCodeValue") + extrasBundle.putString(InMobiNetworkKeys.AREA_CODE, areaCodeValue) + } + val languageValue = extrasMap[LANGUAGE] + if (languageValue is String) { + Log.d("InMobiMediationExtras", "language: $languageValue") + extrasBundle.putString(InMobiNetworkKeys.LANGUAGE, languageValue) + } + val cityValue = extrasMap[CITY] + if (cityValue is String) { + Log.d("InMobiMediationExtras", "city: $cityValue") + extrasBundle.putString(InMobiNetworkKeys.CITY, cityValue) + } + val stateValue = extrasMap[STATE] + if (stateValue is String) { + Log.d("InMobiMediationExtras", "state: $stateValue") + extrasBundle.putString(InMobiNetworkKeys.STATE, stateValue) + } + val countryValue = extrasMap[COUNTRY] + if (countryValue is String) { + Log.d("InMobiMediationExtras", "country: $countryValue") + extrasBundle.putString(InMobiNetworkKeys.COUNTRY, countryValue) + } + val logLevelValue = extrasMap[LOGLEVEL] + if (logLevelValue is Int) { + Log.d("InMobiMediationExtras", "logLevel: $logLevelValue") + when (logLevelValue) { + 0 -> extrasBundle.putString(InMobiNetworkKeys.LOGLEVEL, InMobiNetworkValues.LOGLEVEL_NONE) + 1 -> extrasBundle.putString(InMobiNetworkKeys.LOGLEVEL, InMobiNetworkValues.LOGLEVEL_DEBUG) + 2 -> extrasBundle.putString(InMobiNetworkKeys.LOGLEVEL, InMobiNetworkValues.LOGLEVEL_ERROR) + } + } + val interestsValue = extrasMap[INTERESTS] + if (interestsValue is String) { + Log.d("InMobiMediationExtras", "interests: $interestsValue") + extrasBundle.putString(InMobiNetworkKeys.INTERESTS, interestsValue) + } + return Pair, Bundle>(InMobiAdapter::class.java, extrasBundle) + } + + companion object { + private const val AGE_GROUP = "ageGroup" + private const val EDUCATION = "education" + private const val AGE = "age" + private const val POSTAL_CODE = "postalCode" + private const val AREA_CODE = "areaCode" + private const val LANGUAGE = "language" + private const val CITY = "city" + private const val STATE = "state" + private const val COUNTRY = "country" + private const val INTERESTS = "interests" + private const val LOGLEVEL = "logLevel" + } +} \ No newline at end of file diff --git a/packages/mediation/gma_mediation_inmobi/ios/Classes/InMobiFlutterMediationExtras.swift b/packages/mediation/gma_mediation_inmobi/ios/Classes/InMobiFlutterMediationExtras.swift new file mode 100644 index 000000000..fd78705fc --- /dev/null +++ b/packages/mediation/gma_mediation_inmobi/ios/Classes/InMobiFlutterMediationExtras.swift @@ -0,0 +1,106 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation +import InMobiAdapter + +@objc protocol FLTMediationExtras { + var extras: NSMutableDictionary { get } + func getMediationExtras() -> GADAdNetworkExtras +} + +@objc(InMobiFlutterMediationExtras) +class InMobiFlutterMediationExtras : NSObject, FLTMediationExtras { + var extras: NSMutableDictionary = [:] + + func getMediationExtras() -> GADAdNetworkExtras { + let inMobiExtras = GADInMobiExtras() + if let ageGroup = extras["ageGroup"] as? Int { + switch ageGroup { + case 0: + inMobiExtras.ageGroup = IMSDKAgeGroup.below18 + case 1: + inMobiExtras.ageGroup = IMSDKAgeGroup.between18And24 + case 2: + inMobiExtras.ageGroup = IMSDKAgeGroup.between25And29 + case 3: + inMobiExtras.ageGroup = IMSDKAgeGroup.between30And34 + case 4: + inMobiExtras.ageGroup = IMSDKAgeGroup.between35And44 + case 5: + inMobiExtras.ageGroup = IMSDKAgeGroup.between45And54 + case 6: + inMobiExtras.ageGroup = IMSDKAgeGroup.between55And65 + case 7: + inMobiExtras.ageGroup = IMSDKAgeGroup.above65 + default: + break; + } + } + if let educationType = extras["educationType"] as? Int { + switch educationType { + case 0: + inMobiExtras.educationType = IMSDKEducation.highSchoolOrLess + case 1: + inMobiExtras.educationType = IMSDKEducation.collageOrGraduate + case 2: + inMobiExtras.educationType = IMSDKEducation.postGraduateOrAbove + default: + break; + } + } + if let logLevel = extras["logLevel"] as? Int { + switch logLevel { + case 0: + inMobiExtras.logLevel = IMSDKLogLevel.none + case 1: + inMobiExtras.logLevel = IMSDKLogLevel.debug + case 2: + inMobiExtras.logLevel = IMSDKLogLevel.error + default: + break; + } + + } + if let age = extras["age"] as? UInt { + inMobiExtras.age = age + } + if let yearOfBirth = extras["yearOfBirth"] as? Int { + inMobiExtras.yearOfBirth = yearOfBirth + } + if let postalCode = extras["postalCode"] as? String { + inMobiExtras.postalCode = postalCode + } + if let areaCode = extras["areaCode"] as? String { + inMobiExtras.areaCode = areaCode + } + if let language = extras["language"] as? String { + inMobiExtras.language = language + } + if let keywords = extras["keywords"] as? String { + inMobiExtras.keywords = keywords + } + if let interests = extras["interests"] as? String { + inMobiExtras.interests = interests + } + let city = extras["city"] as? String + let state = extras["state"] as? String + let country = extras["country"] as? String + if city != nil && state != nil && country != nil { + inMobiExtras.setLocationWithCity(city, state: state, country: country) + } + + return inMobiExtras + } +} diff --git a/packages/mediation/gma_mediation_inmobi/lib/inmobi_mediation_extras.dart b/packages/mediation/gma_mediation_inmobi/lib/inmobi_mediation_extras.dart new file mode 100644 index 000000000..a66108382 --- /dev/null +++ b/packages/mediation/gma_mediation_inmobi/lib/inmobi_mediation_extras.dart @@ -0,0 +1,110 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import 'package:gma_mediation_inmobi/gma_mediation_inmobi.dart'; +import 'package:google_mobile_ads/google_mobile_ads.dart'; + +/// Class with additional parameters to attach to the [AdRequest] or [AdManagerAdRequest] when using the [GmaMediationInMobi] adapter. +class InMobiMediationExtras implements MediationExtras { + InMobiMediationExtras({ + this.ageGroup, + this.education, + this.age, + this.yearOfBirth, + this.postalCode, + this.areaCode, + this.language, + this.city, + this.state, + this.country, + this.keywords, + this.interests, + this.logLevel, + }); + + InMobiAgeGroups? ageGroup; + InMobiEducation? education; + int? age; + int? yearOfBirth; + String? postalCode; + String? areaCode; + String? language; + String? city; + String? state; + String? country; + String? interests; + String? keywords; + InMobiLogLevel? logLevel; + + @override + String getAndroidClassName() { + return "io.flutter.plugins.googlemobileads.mediation.gma_mediation_inmobi.InMobiFlutterMediationExtras"; + } + + @override + String getIOSClassName() { + return "InMobiFlutterMediationExtras"; + } + + @override + Map getExtras() { + return { + "ageGroup": ageGroup?.intValue, + "education": education?.intValue, + "age": age, + "yearOfBirth": yearOfBirth, + "postalCode": postalCode, + "areaCode": areaCode, + "language": language, + "city": city, + "state": state, + "country": country, + "keywords": keywords, + "interests": interests, + "logLevel": logLevel?.intValue, + }; + } +} + +/// Definition of the age groups. +enum InMobiAgeGroups { + below18, // index = 0 + between18And24, + between25And29, + between30And34, + between35And44, + between45And54, + between55And65, + above65; + + int get intValue => index; +} + +/// Definition of different level of education. +enum InMobiEducation { + highschoolOrLess, // index = 0 + collegeOrGraduate, + postgraduateOrAbove; + + int get intValue => index; +} + +/// Used in the InMobiSDK to set the log level. +enum InMobiLogLevel { + none, + debug, + error; + + int get intValue => index; +} From 26a47b43ac601bc85a9c1edc91e563019a2135d7 Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Wed, 17 Apr 2024 20:02:32 -0700 Subject: [PATCH 2/4] Excluding mediation adapters Analysis from main plugin (#1060) * Updated iOS GMA SDK to 11.2.0 * Excluding mediation plugins from main plugin analysis --- analysis_options.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/analysis_options.yaml b/analysis_options.yaml index 0cf07a527..8cd5f4207 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -17,6 +17,8 @@ include: package:pedantic/analysis_options.1.11.0.yaml analyzer: exclude: [ packages/mediation/gma_mediation_applovin/**, + packages/mediation/gma_mediation_dtexchange/** + packages/mediation/gma_mediation_inmobi/** packages/mediation/gma_mediation_ironsource/** packages/mediation/gma_mediation_meta/** ] From 3b473c8420c36ceac074a3d0355727210d3a533f Mon Sep 17 00:00:00 2001 From: Justin Malandruccolo Date: Thu, 18 Apr 2024 11:15:02 -0400 Subject: [PATCH 3/4] Update Sample iOS APP IDs (#1059) * Update Info.plist * Update Info.plist * Update Info.plist * Update Info.plist * Update Info.plist * Update Info.plist * Update Info.plist --- samples/admob/adaptive_banner_example/ios/Runner/Info.plist | 2 +- samples/admob/banner_example/ios/Runner/Info.plist | 2 +- samples/admob/interstitial_example/ios/Runner/Info.plist | 2 +- samples/admob/native_platform_example/ios/Runner/Info.plist | 2 +- samples/admob/native_template_example/ios/Runner/Info.plist | 2 +- samples/admob/rewarded_example/ios/Runner/Info.plist | 2 +- .../admob/rewarded_interstitial_example/ios/Runner/Info.plist | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/samples/admob/adaptive_banner_example/ios/Runner/Info.plist b/samples/admob/adaptive_banner_example/ios/Runner/Info.plist index d05424708..01a2ee7e5 100644 --- a/samples/admob/adaptive_banner_example/ios/Runner/Info.plist +++ b/samples/admob/adaptive_banner_example/ios/Runner/Info.plist @@ -46,7 +46,7 @@ UIApplicationSupportsIndirectInputEvents GADApplicationIdentifier - ca-app-pub-3940256099942544~3347511713 + ca-app-pub-3940256099942544~1458002511 SKAdNetworkItems diff --git a/samples/admob/banner_example/ios/Runner/Info.plist b/samples/admob/banner_example/ios/Runner/Info.plist index 760e7e009..f7baeaab2 100644 --- a/samples/admob/banner_example/ios/Runner/Info.plist +++ b/samples/admob/banner_example/ios/Runner/Info.plist @@ -48,7 +48,7 @@ UIApplicationSupportsIndirectInputEvents GADApplicationIdentifier - ca-app-pub-3940256099942544~3347511713 + ca-app-pub-3940256099942544~1458002511 SKAdNetworkItems diff --git a/samples/admob/interstitial_example/ios/Runner/Info.plist b/samples/admob/interstitial_example/ios/Runner/Info.plist index 33378ba39..bde98268e 100644 --- a/samples/admob/interstitial_example/ios/Runner/Info.plist +++ b/samples/admob/interstitial_example/ios/Runner/Info.plist @@ -46,7 +46,7 @@ UIApplicationSupportsIndirectInputEvents GADApplicationIdentifier - ca-app-pub-3940256099942544~3347511713 + ca-app-pub-3940256099942544~1458002511 SKAdNetworkItems diff --git a/samples/admob/native_platform_example/ios/Runner/Info.plist b/samples/admob/native_platform_example/ios/Runner/Info.plist index a7886632a..07558cff2 100644 --- a/samples/admob/native_platform_example/ios/Runner/Info.plist +++ b/samples/admob/native_platform_example/ios/Runner/Info.plist @@ -23,7 +23,7 @@ CFBundleVersion $(FLUTTER_BUILD_NUMBER) GADApplicationIdentifier - ca-app-pub-3940256099942544~3347511713 + ca-app-pub-3940256099942544~1458002511 LSRequiresIPhoneOS UILaunchStoryboardName diff --git a/samples/admob/native_template_example/ios/Runner/Info.plist b/samples/admob/native_template_example/ios/Runner/Info.plist index 4c3b760e5..aaaf52730 100644 --- a/samples/admob/native_template_example/ios/Runner/Info.plist +++ b/samples/admob/native_template_example/ios/Runner/Info.plist @@ -25,7 +25,7 @@ CFBundleVersion $(FLUTTER_BUILD_NUMBER) GADApplicationIdentifier - ca-app-pub-3940256099942544~3347511713 + ca-app-pub-3940256099942544~1458002511 LSRequiresIPhoneOS UIApplicationSupportsIndirectInputEvents diff --git a/samples/admob/rewarded_example/ios/Runner/Info.plist b/samples/admob/rewarded_example/ios/Runner/Info.plist index 658da0c54..be2661556 100644 --- a/samples/admob/rewarded_example/ios/Runner/Info.plist +++ b/samples/admob/rewarded_example/ios/Runner/Info.plist @@ -46,7 +46,7 @@ UIApplicationSupportsIndirectInputEvents GADApplicationIdentifier - ca-app-pub-3940256099942544~3347511713 + ca-app-pub-3940256099942544~1458002511 SKAdNetworkItems diff --git a/samples/admob/rewarded_interstitial_example/ios/Runner/Info.plist b/samples/admob/rewarded_interstitial_example/ios/Runner/Info.plist index 2b7b934a0..dfbb6c5b3 100644 --- a/samples/admob/rewarded_interstitial_example/ios/Runner/Info.plist +++ b/samples/admob/rewarded_interstitial_example/ios/Runner/Info.plist @@ -46,7 +46,7 @@ UIApplicationSupportsIndirectInputEvents GADApplicationIdentifier - ca-app-pub-3940256099942544~3347511713 + ca-app-pub-3940256099942544~1458002511 SKAdNetworkItems From aabe81a7297f35f5a7f73b02d19cf7d6ac9c1c2a Mon Sep 17 00:00:00 2001 From: Justin Malandruccolo Date: Thu, 18 Apr 2024 11:20:23 -0400 Subject: [PATCH 4/4] Update inline_adaptive_example.dart (#1058) Co-authored-by: Justin Malandruccolo --- .../google_mobile_ads/example/lib/inline_adaptive_example.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google_mobile_ads/example/lib/inline_adaptive_example.dart b/packages/google_mobile_ads/example/lib/inline_adaptive_example.dart index 26df3999d..48709bae4 100644 --- a/packages/google_mobile_ads/example/lib/inline_adaptive_example.dart +++ b/packages/google_mobile_ads/example/lib/inline_adaptive_example.dart @@ -55,7 +55,7 @@ class _InlineAdaptiveExampleState extends State { _adWidth.truncate()); _inlineAdaptiveAd = AdManagerBannerAd( - adUnitId: '/6499/example/banner', + adUnitId: '/6499/example/adaptive-banner', sizes: [size], request: AdManagerAdRequest(), listener: AdManagerBannerAdListener(