-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Privacy API implementation for DT Exchange Flutter Adapter (#1056)
* Added DT Exchange Privacy API usage * Added Android and iOS jobs to the DT Exchange github action * Updated iOS versions to run swift tests
- Loading branch information
Showing
18 changed files
with
965 additions
and
64 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
139 changes: 139 additions & 0 deletions
139
...tter/plugins/googlemobileads/mediation/gma_mediation_dtexchange/DTExchangePrivacyApi.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,139 @@ | ||
// Autogenerated from Pigeon (v19.0.0), do not edit directly. | ||
// See also: https://pub.dev/packages/pigeon | ||
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") | ||
|
||
package io.flutter.plugins.googlemobileads.mediation.gma_mediation_dtexchange | ||
|
||
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?> { | ||
return if (exception is FlutterError) { | ||
listOf( | ||
exception.code, | ||
exception.message, | ||
exception.details | ||
) | ||
} else { | ||
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 FlutterError ( | ||
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 DTExchangePrivacyApi interface and swift DTExchangePrivacyApi protocol from the dart layer. | ||
* | ||
* Generated interface from Pigeon that represents a handler of messages from Flutter. | ||
*/ | ||
interface DTExchangePrivacyApi { | ||
/** Used to configure LGDP on the Android or iOS DTExchange SDK. */ | ||
fun setLgpdConsent(wasConsentGiven: Boolean) | ||
/** Used to clear the LGDP flag on the Android or iOS DTExchange SDK. */ | ||
fun clearLgpdConsentData() | ||
/** Used to configure consent to Sell Personal Information on the Android or iOS DTExchange SDK. */ | ||
fun setUSPrivacyString(usPrivacyString: String) | ||
/** Used to clear the US Privacy flag on the Android or iOS DTExchange SDK. */ | ||
fun clearUSPrivacyString() | ||
|
||
companion object { | ||
/** The codec used by DTExchangePrivacyApi. */ | ||
val codec: MessageCodec<Any?> by lazy { | ||
StandardMessageCodec() | ||
} | ||
/** Sets up an instance of `DTExchangePrivacyApi` to handle messages through the `binaryMessenger`. */ | ||
fun setUp(binaryMessenger: BinaryMessenger, api: DTExchangePrivacyApi?, messageChannelSuffix: String = "") { | ||
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" | ||
run { | ||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.gma_mediation_dtexchange.DTExchangePrivacyApi.setLgpdConsent$separatedMessageChannelSuffix", codec) | ||
if (api != null) { | ||
channel.setMessageHandler { message, reply -> | ||
val args = message as List<Any?> | ||
val wasConsentGivenArg = args[0] as Boolean | ||
val wrapped: List<Any?> = try { | ||
api.setLgpdConsent(wasConsentGivenArg) | ||
listOf<Any?>(null) | ||
} catch (exception: Throwable) { | ||
wrapError(exception) | ||
} | ||
reply.reply(wrapped) | ||
} | ||
} else { | ||
channel.setMessageHandler(null) | ||
} | ||
} | ||
run { | ||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.gma_mediation_dtexchange.DTExchangePrivacyApi.clearLgpdConsentData$separatedMessageChannelSuffix", codec) | ||
if (api != null) { | ||
channel.setMessageHandler { _, reply -> | ||
val wrapped: List<Any?> = try { | ||
api.clearLgpdConsentData() | ||
listOf<Any?>(null) | ||
} catch (exception: Throwable) { | ||
wrapError(exception) | ||
} | ||
reply.reply(wrapped) | ||
} | ||
} else { | ||
channel.setMessageHandler(null) | ||
} | ||
} | ||
run { | ||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.gma_mediation_dtexchange.DTExchangePrivacyApi.setUSPrivacyString$separatedMessageChannelSuffix", codec) | ||
if (api != null) { | ||
channel.setMessageHandler { message, reply -> | ||
val args = message as List<Any?> | ||
val usPrivacyStringArg = args[0] as String | ||
val wrapped: List<Any?> = try { | ||
api.setUSPrivacyString(usPrivacyStringArg) | ||
listOf<Any?>(null) | ||
} catch (exception: Throwable) { | ||
wrapError(exception) | ||
} | ||
reply.reply(wrapped) | ||
} | ||
} else { | ||
channel.setMessageHandler(null) | ||
} | ||
} | ||
run { | ||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.gma_mediation_dtexchange.DTExchangePrivacyApi.clearUSPrivacyString$separatedMessageChannelSuffix", codec) | ||
if (api != null) { | ||
channel.setMessageHandler { _, reply -> | ||
val wrapped: List<Any?> = try { | ||
api.clearUSPrivacyString() | ||
listOf<Any?>(null) | ||
} catch (exception: Throwable) { | ||
wrapError(exception) | ||
} | ||
reply.reply(wrapped) | ||
} | ||
} else { | ||
channel.setMessageHandler(null) | ||
} | ||
} | ||
} | ||
} | ||
} |
29 changes: 25 additions & 4 deletions
29
...lugins/googlemobileads/mediation/gma_mediation_dtexchange/GmaMediationDTExchangePlugin.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,10 +1,31 @@ | ||
package io.flutter.plugins.googlemobileads.mediation.gma_mediation_dtexchange | ||
|
||
import com.fyber.inneractive.sdk.external.InneractiveAdManager | ||
import io.flutter.embedding.engine.plugins.FlutterPlugin | ||
|
||
/** Class that serves as bridge to get the adapter android dependency and make it available to a Flutter app. */ | ||
class GmaMediationDTExchangePlugin: FlutterPlugin { | ||
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {} | ||
/** Manages DTExchangePrivacyApi and implements the needed methods. */ | ||
class GmaMediationDTExchangePlugin: FlutterPlugin, DTExchangePrivacyApi { | ||
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { | ||
DTExchangePrivacyApi.setUp(flutterPluginBinding.binaryMessenger, this) | ||
} | ||
|
||
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {} | ||
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { | ||
DTExchangePrivacyApi.setUp(binding.binaryMessenger, null) | ||
} | ||
|
||
override fun setLgpdConsent(wasConsentGiven: Boolean) { | ||
InneractiveAdManager.setLgpdConsent(wasConsentGiven) | ||
} | ||
|
||
override fun clearLgpdConsentData() { | ||
InneractiveAdManager.clearLgpdConsentData() | ||
} | ||
|
||
override fun setUSPrivacyString(usPrivacyString: String) { | ||
InneractiveAdManager.setUSPrivacyString(usPrivacyString) | ||
} | ||
|
||
override fun clearUSPrivacyString() { | ||
InneractiveAdManager.clearUSPrivacyString() | ||
} | ||
} |
89 changes: 71 additions & 18 deletions
89
...ns/googlemobileads/mediation/gma_mediation_dtexchange/GmaMediationDtexchangePluginTest.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_dtexchange | ||
|
||
import io.flutter.plugin.common.MethodCall | ||
import io.flutter.plugin.common.MethodChannel | ||
import kotlin.test.Test | ||
import org.mockito.Mockito | ||
|
||
/* | ||
* 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.fyber.inneractive.sdk.external.InneractiveAdManager | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mockito.mockStatic | ||
import org.mockito.kotlin.eq | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
internal class GmaMediationDtexchangePluginTest { | ||
@Test | ||
fun onMethodCall_getPlatformVersion_returnsExpectedValue() { | ||
val plugin = GmaMediationDtexchangePlugin() | ||
fun setLgpdConsent_withTrueValue_invokesSetLgpdConsentWithTrueValue() { | ||
val plugin = GmaMediationDTExchangePlugin() | ||
mockStatic(InneractiveAdManager::class.java).use { mockedDTExchangeAdManager -> | ||
|
||
val call = MethodCall("getPlatformVersion", null) | ||
val mockResult: MethodChannel.Result = Mockito.mock(MethodChannel.Result::class.java) | ||
plugin.onMethodCall(call, mockResult) | ||
plugin.setLgpdConsent(true) | ||
|
||
Mockito.verify(mockResult).success("Android " + android.os.Build.VERSION.RELEASE) | ||
mockedDTExchangeAdManager.verify { | ||
InneractiveAdManager.setLgpdConsent(eq(true)) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun setLgpdConsent_withFalseValue_invokesSetLgpdConsentWithFalseValue() { | ||
val plugin = GmaMediationDTExchangePlugin() | ||
mockStatic(InneractiveAdManager::class.java).use { mockedDTExchangeAdManager -> | ||
|
||
plugin.setLgpdConsent(false) | ||
|
||
mockedDTExchangeAdManager.verify { | ||
InneractiveAdManager.setLgpdConsent(eq(false)) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun clearLgpdConsentData_invokesClearLgpdConsentData() { | ||
val plugin = GmaMediationDTExchangePlugin() | ||
mockStatic(InneractiveAdManager::class.java).use { mockedDTExchangeAdManager -> | ||
|
||
plugin.clearLgpdConsentData() | ||
|
||
mockedDTExchangeAdManager.verify { | ||
InneractiveAdManager.clearLgpdConsentData() | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun setUSPrivacyString_invokesSetUSPrivacyString() { | ||
val plugin = GmaMediationDTExchangePlugin() | ||
mockStatic(InneractiveAdManager::class.java).use { mockedDTExchangeAdManager -> | ||
|
||
plugin.setUSPrivacyString(TEST_CONSENT_STRING) | ||
|
||
mockedDTExchangeAdManager.verify { | ||
InneractiveAdManager.setUSPrivacyString(eq(TEST_CONSENT_STRING)) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun clearUSPrivacyString_invokesClearUSPrivacyString() { | ||
val plugin = GmaMediationDTExchangePlugin() | ||
mockStatic(InneractiveAdManager::class.java).use { mockedDTExchangeAdManager -> | ||
|
||
plugin.clearUSPrivacyString() | ||
|
||
mockedDTExchangeAdManager.verify { | ||
InneractiveAdManager.clearUSPrivacyString() | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
const val TEST_CONSENT_STRING = "testConsentString" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/mediation/gma_mediation_dtexchange/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_dtexchange/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.