-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of IronSource Privacy API in the adapter (#1050)
* IronSource Privacy APIs implementation * Updated ironSource GitHub workflow to run unit tests
- Loading branch information
Showing
25 changed files
with
697 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
## 1.0.0 | ||
## ironSource Flutter Mediation Adapter Changelog | ||
|
||
#### 1.0.0 | ||
* Initial release. | ||
* Verified compatibility with ironSource Android adapter version 7.9.0.0 | ||
* Verified compatibility with ironSource iOS adapter version 7.9.1.0.0 | ||
* Verified compatibility with ironSource Android adapter version 8.0.0.0 | ||
* Verified compatibility with ironSource iOS adapter version 8.0.0.0.0 | ||
* Built and tested with the Google Mobile Ads Flutter Plugin version 5.1.0. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/mediation/gma_mediation_ironsource/android/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
android.useAndroidX=true |
6 changes: 6 additions & 0 deletions
6
packages/mediation/gma_mediation_ironsource/android/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip | ||
networkTimeout=10000 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...tter/plugins/googlemobileads/mediation/gma_mediation_ironsource/IronSourcePrivacyApi.g.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Autogenerated from Pigeon (v17.3.0), do not edit directly. | ||
// See also: https://pub.dev/packages/pigeon | ||
|
||
package io.flutter.plugins.googlemobileads.mediation.gma_mediation_ironsource | ||
|
||
import android.util.Log | ||
import io.flutter.plugin.common.BasicMessageChannel | ||
import io.flutter.plugin.common.BinaryMessenger | ||
import io.flutter.plugin.common.MessageCodec | ||
import io.flutter.plugin.common.StandardMessageCodec | ||
import java.io.ByteArrayOutputStream | ||
import java.nio.ByteBuffer | ||
|
||
private fun wrapResult(result: Any?): List<Any?> { | ||
return listOf(result) | ||
} | ||
|
||
private fun wrapError(exception: Throwable): List<Any?> { | ||
if (exception is IronSourcePrivacyError) { | ||
return listOf( | ||
exception.code, | ||
exception.message, | ||
exception.details | ||
) | ||
} else { | ||
return listOf( | ||
exception.javaClass.simpleName, | ||
exception.toString(), | ||
"Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception) | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Error class for passing custom error details to Flutter via a thrown PlatformException. | ||
* @property code The error code. | ||
* @property message The error message. | ||
* @property details The error details. Must be a datatype supported by the api codec. | ||
*/ | ||
class IronSourcePrivacyError ( | ||
val code: String, | ||
override val message: String? = null, | ||
val details: Any? = null | ||
) : Throwable() | ||
/** | ||
* The generated classes set the channels to call the methods in the corresponding kotlin IronSourcePrivacyApi interface and swift IronSourcePrivacyApi protocol from the dart layer. | ||
* | ||
* Generated interface from Pigeon that represents a handler of messages from Flutter. | ||
*/ | ||
interface IronSourcePrivacyApi { | ||
fun setConsent(gdprConsent: Boolean) | ||
fun setDoNotSell(doNotSell: Boolean) | ||
|
||
companion object { | ||
/** The codec used by IronSourcePrivacyApi. */ | ||
val codec: MessageCodec<Any?> by lazy { | ||
StandardMessageCodec() | ||
} | ||
/** Sets up an instance of `IronSourcePrivacyApi` to handle messages through the `binaryMessenger`. */ | ||
@Suppress("UNCHECKED_CAST") | ||
fun setUp(binaryMessenger: BinaryMessenger, api: IronSourcePrivacyApi?) { | ||
run { | ||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.gma_mediation_ironsource.IronSourcePrivacyApi.setConsent", codec) | ||
if (api != null) { | ||
channel.setMessageHandler { message, reply -> | ||
val args = message as List<Any?> | ||
val gdprConsentArg = args[0] as Boolean | ||
var wrapped: List<Any?> | ||
try { | ||
api.setConsent(gdprConsentArg) | ||
wrapped = listOf<Any?>(null) | ||
} catch (exception: Throwable) { | ||
wrapped = wrapError(exception) | ||
} | ||
reply.reply(wrapped) | ||
} | ||
} else { | ||
channel.setMessageHandler(null) | ||
} | ||
} | ||
run { | ||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.gma_mediation_ironsource.IronSourcePrivacyApi.setDoNotSell", codec) | ||
if (api != null) { | ||
channel.setMessageHandler { message, reply -> | ||
val args = message as List<Any?> | ||
val doNotSellArg = args[0] as Boolean | ||
var wrapped: List<Any?> | ||
try { | ||
api.setDoNotSell(doNotSellArg) | ||
wrapped = listOf<Any?>(null) | ||
} catch (exception: Throwable) { | ||
wrapped = wrapError(exception) | ||
} | ||
reply.reply(wrapped) | ||
} | ||
} else { | ||
channel.setMessageHandler(null) | ||
} | ||
} | ||
} | ||
} | ||
} |
87 changes: 70 additions & 17 deletions
87
...ns/googlemobileads/mediation/gma_mediation_ironsource/GmaMediationIronsourcePluginTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,80 @@ | ||
package io.flutter.plugins.googlemobileads.mediation.gma_mediation_ironsource | ||
// 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 io.flutter.plugin.common.MethodCall | ||
import io.flutter.plugin.common.MethodChannel | ||
import kotlin.test.Test | ||
import org.mockito.Mockito | ||
package io.flutter.plugins.googlemobileads.mediation.gma_mediation_ironsource | ||
|
||
/* | ||
* This demonstrates a simple unit test of the Kotlin portion of this plugin's implementation. | ||
* | ||
* Once you have built the plugin's example app, you can run these tests from the command | ||
* line by running `./gradlew testDebugUnitTest` in the `example/android/` directory, or | ||
* you can run them directly from IDEs that support JUnit such as Android Studio. | ||
*/ | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.ironsource.mediationsdk.IronSource | ||
import io.flutter.plugins.googlemobileads.mediation.gma_mediation_ironsource.GmaMediationIronsourcePlugin.Companion.FALSE | ||
import io.flutter.plugins.googlemobileads.mediation.gma_mediation_ironsource.GmaMediationIronsourcePlugin.Companion.IRONSOURCE_DONOTSELL_KEY | ||
import io.flutter.plugins.googlemobileads.mediation.gma_mediation_ironsource.GmaMediationIronsourcePlugin.Companion.TRUE | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mockito.mockStatic | ||
import org.mockito.kotlin.eq | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
internal class GmaMediationIronsourcePluginTest { | ||
@Test | ||
fun onMethodCall_getPlatformVersion_returnsExpectedValue() { | ||
fun setConsent_withTrueValue_invokesIronSourceSetConsent() { | ||
val plugin = GmaMediationIronsourcePlugin() | ||
mockStatic(IronSource::class.java).use { mockedIronSource -> | ||
|
||
plugin.setConsent(true) | ||
|
||
mockedIronSource.verify { | ||
IronSource.setConsent(eq(true)) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun setConsent_withFalseValue_invokesIronSourceSetConsent() { | ||
val plugin = GmaMediationIronsourcePlugin() | ||
mockStatic(IronSource::class.java).use { mockedIronSource -> | ||
|
||
plugin.setConsent(false) | ||
|
||
mockedIronSource.verify { | ||
IronSource.setConsent(eq(false)) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun setDoNotSell_withTrueValue_invokesIronSourceMetaDataWithCorrectKeyAndValue() { | ||
val plugin = GmaMediationIronsourcePlugin() | ||
mockStatic(IronSource::class.java).use { mockedIronSource -> | ||
|
||
plugin.setDoNotSell(true) | ||
|
||
mockedIronSource.verify { | ||
IronSource.setMetaData(eq(IRONSOURCE_DONOTSELL_KEY), eq(TRUE)) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun setDoNotSell_withFalseValue_invokesIronSourceMetaDataWithCorrectKeyAndValue() { | ||
val plugin = GmaMediationIronsourcePlugin() | ||
mockStatic(IronSource::class.java).use { mockedIronSource -> | ||
|
||
val call = MethodCall("getPlatformVersion", null) | ||
val mockResult: MethodChannel.Result = Mockito.mock(MethodChannel.Result::class.java) | ||
plugin.onMethodCall(call, mockResult) | ||
plugin.setDoNotSell(false) | ||
|
||
Mockito.verify(mockResult).success("Android " + android.os.Build.VERSION.RELEASE) | ||
mockedIronSource.verify { | ||
IronSource.setMetaData(eq(IRONSOURCE_DONOTSELL_KEY), eq(FALSE)) | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/mediation/gma_mediation_ironsource/example/ios/Flutter/Debug.xcconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" | ||
#include "Generated.xcconfig" |
1 change: 1 addition & 0 deletions
1
packages/mediation/gma_mediation_ironsource/example/ios/Flutter/Release.xcconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" | ||
#include "Generated.xcconfig" |
Oops, something went wrong.