-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GDPR and CCPA consent APIs to Chartboost Flutter Adapter Plugin
PiperOrigin-RevId: 702353803
- Loading branch information
Showing
12 changed files
with
651 additions
and
41 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
132 changes: 132 additions & 0 deletions
132
.../flutter/plugins/googlemobileads/mediation/gma_mediation_chartboost/ChartboostSDKApi.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,132 @@ | ||
// Autogenerated from Pigeon (v22.6.2), do not edit directly. | ||
// See also: https://pub.dev/packages/pigeon | ||
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") | ||
|
||
package io.flutter.plugins.googlemobileads.mediation.gma_mediation_chartboost | ||
|
||
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() | ||
|
||
private open class ChartboostSDKApiPigeonCodec : StandardMessageCodec() { | ||
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { | ||
return super.readValueOfType(type, buffer) | ||
} | ||
|
||
override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { | ||
super.writeValue(stream, value) | ||
} | ||
} | ||
|
||
/** | ||
* The generated classes set the channels to call the methods in the corresponding kotlin | ||
* ChartboostSDKApi interface and swift ChartboostSDKApi protocol from the dart layer. | ||
* | ||
* Generated interface from Pigeon that represents a handler of messages from Flutter. | ||
*/ | ||
interface ChartboostSDKApi { | ||
/** Used to configure GDPR consent on the Android or iOS Chartboost SDK */ | ||
fun setGDPRConsent(userConsent: Boolean) | ||
|
||
/** Used to opt out of the sale of personal information in Chartboost SDK. */ | ||
fun setCCPAConsent(userOptIn: Boolean) | ||
|
||
companion object { | ||
/** The codec used by ChartboostSDKApi. */ | ||
val codec: MessageCodec<Any?> by lazy { ChartboostSDKApiPigeonCodec() } | ||
|
||
/** | ||
* Sets up an instance of `ChartboostSDKApi` to handle messages through the `binaryMessenger`. | ||
*/ | ||
@JvmOverloads | ||
fun setUp( | ||
binaryMessenger: BinaryMessenger, | ||
api: ChartboostSDKApi?, | ||
messageChannelSuffix: String = "", | ||
) { | ||
val separatedMessageChannelSuffix = | ||
if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" | ||
run { | ||
val channel = | ||
BasicMessageChannel<Any?>( | ||
binaryMessenger, | ||
"dev.flutter.pigeon.gma_mediation_chartboost.ChartboostSDKApi.setGDPRConsent$separatedMessageChannelSuffix", | ||
codec, | ||
) | ||
if (api != null) { | ||
channel.setMessageHandler { message, reply -> | ||
val args = message as List<Any?> | ||
val userConsentArg = args[0] as Boolean | ||
val wrapped: List<Any?> = | ||
try { | ||
api.setGDPRConsent(userConsentArg) | ||
listOf(null) | ||
} catch (exception: Throwable) { | ||
wrapError(exception) | ||
} | ||
reply.reply(wrapped) | ||
} | ||
} else { | ||
channel.setMessageHandler(null) | ||
} | ||
} | ||
run { | ||
val channel = | ||
BasicMessageChannel<Any?>( | ||
binaryMessenger, | ||
"dev.flutter.pigeon.gma_mediation_chartboost.ChartboostSDKApi.setCCPAConsent$separatedMessageChannelSuffix", | ||
codec, | ||
) | ||
if (api != null) { | ||
channel.setMessageHandler { message, reply -> | ||
val args = message as List<Any?> | ||
val userOptInArg = args[0] as Boolean | ||
val wrapped: List<Any?> = | ||
try { | ||
api.setCCPAConsent(userOptInArg) | ||
listOf(null) | ||
} catch (exception: Throwable) { | ||
wrapError(exception) | ||
} | ||
reply.reply(wrapped) | ||
} | ||
} else { | ||
channel.setMessageHandler(null) | ||
} | ||
} | ||
} | ||
} | ||
} |
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
20 changes: 0 additions & 20 deletions
20
...n/gma_mediation_chartboost/example/ios/RunnerTests/GmaMediationChartboostPluginTest.swift
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
.../gma_mediation_chartboost/example/ios/RunnerTests/GmaMediationChartboostPluginTests.swift
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,49 @@ | ||
// 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 UIKit | ||
import XCTest | ||
|
||
@testable import gma_mediation_chartboost | ||
|
||
class GmaMediationChartboostPluginTests: XCTestCase { | ||
func testSetGDPRConsent() { | ||
let chartboostApiFake = ChartboostApiFake() | ||
|
||
GmaMediationChartboostPlugin(chartboostApi: chartboostApiFake).setGDPRConsent(gdprConsent: true) | ||
|
||
XCTAssertTrue(chartboostApiFake.gdprConsent) | ||
} | ||
|
||
func testSetCCPAConsent() { | ||
let chartboostApiFake = ChartboostApiFake() | ||
|
||
GmaMediationChartboostPlugin(chartboostApi: chartboostApiFake).setCCPAConsent(ccpaConsent: true) | ||
|
||
XCTAssertTrue(chartboostApiFake.ccpaConsent) | ||
} | ||
} | ||
|
||
class ChartboostApiFake: ChartboostApiProtocol { | ||
var gdprConsent: Bool = false | ||
var ccpaConsent: Bool = false | ||
|
||
func setGDPRConsent(gdprConsent: Bool) { | ||
self.gdprConsent = gdprConsent | ||
} | ||
|
||
func setCCPAConsent(ccpaConsent: Bool) { | ||
self.ccpaConsent = ccpaConsent | ||
} | ||
} |
Oops, something went wrong.