Skip to content

[interactive_media_ads] Updates native ProxyApis to prepare to add support for AdEvent.ad #9785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/interactive_media_ads/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.2.6+3

* Adds internal wrappers for iOS native `IMAAd` and `IMAUniversalAdID`.
* Updates internal wrapper for iOS native `IMAAdEvent`.
* Updates internal wrapper for Android native `AdEvent`.

## 0.2.6+2

* Updates kotlin version to 2.2.0 to enable gradle 8.11 support.
Expand Down
3 changes: 1 addition & 2 deletions packages/interactive_media_ads/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ a separate video player positioned on top of the app's content video player.
| **Support** | SDK 21+ | 12.0+ |

**NOTE:**
* Companion ads, Background Audio ads and Google Dynamic Ad Insertion methods are currently not
supported.
* Background Audio ads and Google Dynamic Ad Insertion methods are currently not supported.

## IMA client-side overview

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package dev.flutter.packages.interactive_media_ads

import com.google.ads.interactivemedia.v3.api.Ad
import com.google.ads.interactivemedia.v3.api.AdEvent

/**
Expand Down Expand Up @@ -50,4 +51,8 @@ class AdEventProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
override fun adData(pigeon_instance: AdEvent): Map<String, String>? {
return pigeon_instance.adData
}

override fun ad(pigeon_instance: AdEvent): Ad? {
return pigeon_instance.ad
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AdsRequestProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
*
* This must match the version in pubspec.yaml.
*/
const val pluginVersion = "0.2.6+2"
const val pluginVersion = "0.2.6+3"
}

override fun setAdTagUrl(pigeon_instance: AdsRequest, adTagUrl: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v26.0.0), do not edit directly.
// Autogenerated from Pigeon (v26.0.1), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")

Expand Down Expand Up @@ -2558,7 +2558,7 @@ abstract class PigeonApiBaseManager(
* Event to notify publisher that an event occurred with an Ad.
*
* See
* https://developers.google.com/interactive-media-ads/docs/sdks/android/client-side/api/reference/com/google/ads/interactivemedia/v3/api/AdEvent.html.
* https://developers.google.com/interactive-media-ads/docs/sdks/android/client-side/api/reference/kotlin/com/google/ads/interactivemedia/v3/api/AdEvent.
*/
@Suppress("UNCHECKED_CAST")
abstract class PigeonApiAdEvent(
Expand All @@ -2572,6 +2572,11 @@ abstract class PigeonApiAdEvent(
pigeon_instance: com.google.ads.interactivemedia.v3.api.AdEvent
): Map<String, String>?

/** The ad with which this event is associated. */
abstract fun ad(
pigeon_instance: com.google.ads.interactivemedia.v3.api.AdEvent
): com.google.ads.interactivemedia.v3.api.Ad?

@Suppress("LocalVariableName", "FunctionName")
/** Creates a Dart instance of AdEvent and attaches it to [pigeon_instanceArg]. */
fun pigeon_newInstance(
Expand All @@ -2589,11 +2594,12 @@ abstract class PigeonApiAdEvent(
pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
val typeArg = type(pigeon_instanceArg)
val adDataArg = adData(pigeon_instanceArg)
val adArg = ad(pigeon_instanceArg)
val binaryMessenger = pigeonRegistrar.binaryMessenger
val codec = pigeonRegistrar.codec
val channelName = "dev.flutter.pigeon.interactive_media_ads.AdEvent.pigeon_newInstance"
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
channel.send(listOf(pigeon_identifierArg, typeArg, adDataArg)) {
channel.send(listOf(pigeon_identifierArg, typeArg, adDataArg, adArg)) {
if (it is List<*>) {
if (it.size > 1) {
callback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package dev.flutter.packages.interactive_media_ads

import com.google.ads.interactivemedia.v3.api.Ad
import com.google.ads.interactivemedia.v3.api.AdEvent
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -30,4 +31,15 @@ class AdEventProxyApiTest {

assertEquals(mapOf("a" to "b", "c" to "d"), api.adData(instance))
}

@Test
fun ad() {
val api = TestProxyApiRegistrar().getPigeonApiAdEvent()

val ad = Mockito.mock<Ad>()
val instance = Mockito.mock<AdEvent>()
whenever(instance.ad).thenReturn(ad)

assertEquals(ad, api.ad(instance))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */ = {isa = PBXBuildFile; productRef = 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */; };
8F0EDFD12E0A2906001938E6 /* SettingsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F0EDFD02E0A2906001938E6 /* SettingsTests.swift */; };
8F0EDFD62E4AA191001938E6 /* UniversalAdIDProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F0EDFD52E4AA191001938E6 /* UniversalAdIDProxyAPITests.swift */; };
8F0EDFD72E4AA191001938E6 /* AdProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F0EDFD42E4AA191001938E6 /* AdProxyAPITests.swift */; };
8F0EDFD92E4AA1B0001938E6 /* ViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F0EDFD82E4AA1B0001938E6 /* ViewTests.swift */; };
8F599BB12C2DD1FD0090A0DF /* AdsManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F599BB02C2DD1FD0090A0DF /* AdsManagerTests.swift */; };
8F599BB32C2DD87D0090A0DF /* AdsLoaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F599BB22C2DD87D0090A0DF /* AdsLoaderTests.swift */; };
8F599BB52C2DD8EC0090A0DF /* AdsLoaderDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F599BB42C2DD8EC0090A0DF /* AdsLoaderDelegateTests.swift */; };
Expand Down Expand Up @@ -77,6 +80,9 @@
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
89C6230E68C80A6F4B207726 /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = "<group>"; };
8F0EDFD02E0A2906001938E6 /* SettingsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsTests.swift; sourceTree = "<group>"; };
8F0EDFD42E4AA191001938E6 /* AdProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdProxyAPITests.swift; sourceTree = "<group>"; };
8F0EDFD52E4AA191001938E6 /* UniversalAdIDProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UniversalAdIDProxyAPITests.swift; sourceTree = "<group>"; };
8F0EDFD82E4AA1B0001938E6 /* ViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewTests.swift; sourceTree = "<group>"; };
8F599BB02C2DD1FD0090A0DF /* AdsManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdsManagerTests.swift; sourceTree = "<group>"; };
8F599BB22C2DD87D0090A0DF /* AdsLoaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdsLoaderTests.swift; sourceTree = "<group>"; };
8F599BB42C2DD8EC0090A0DF /* AdsLoaderDelegateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdsLoaderDelegateTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -130,6 +136,9 @@
331C8082294A63A400263BE5 /* RunnerTests */ = {
isa = PBXGroup;
children = (
8F0EDFD82E4AA1B0001938E6 /* ViewTests.swift */,
8F0EDFD42E4AA191001938E6 /* AdProxyAPITests.swift */,
8F0EDFD52E4AA191001938E6 /* UniversalAdIDProxyAPITests.swift */,
8F0EDFD02E0A2906001938E6 /* SettingsTests.swift */,
8FC919912CA5D86F00188068 /* FriendlyObstructionTests.swift */,
8F977DCE2C2B99C600A90D4B /* AdDisplayContainerTests.swift */,
Expand Down Expand Up @@ -256,6 +265,7 @@
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
776DEB6D359E63A1B5E520A7 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -371,6 +381,23 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
};
776DEB6D359E63A1B5E520A7 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
8BF613E92E45E672229E9718 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -418,8 +445,11 @@
8F599BBF2C3335B40090A0DF /* ViewControllerTests.swift in Sources */,
8F8382A32CBDB4A4007F28E0 /* CompanionAdProxyApiTests.swift in Sources */,
8F0EDFD12E0A2906001938E6 /* SettingsTests.swift in Sources */,
8F0EDFD62E4AA191001938E6 /* UniversalAdIDProxyAPITests.swift in Sources */,
8F0EDFD72E4AA191001938E6 /* AdProxyAPITests.swift in Sources */,
8FC919922CA5D86F00188068 /* FriendlyObstructionTests.swift in Sources */,
8F977DD92C2C8C6A00A90D4B /* AdLoadingErrorDataTests.swift in Sources */,
8F0EDFD92E4AA1B0001938E6 /* ViewTests.swift in Sources */,
8F599BB32C2DD87D0090A0DF /* AdsLoaderTests.swift in Sources */,
8F977DD72C2C89A600A90D4B /* AdEventTests.swift in Sources */,
8F977DD32C2BA15100A90D4B /* TestProxyApiRegistrar.swift in Sources */,
Expand Down Expand Up @@ -520,7 +550,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -650,7 +680,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -701,7 +731,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,30 @@ final class AdEventTests: XCTestCase {

XCTAssertEqual(value as! [String: String], ["my": "string"])
}

func testAd() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiIMAAdEvent(registrar)

let instance = TestAdEvent.customInit()
let value = try? api.pigeonDelegate.ad(pigeonApi: api, pigeonInstance: instance)

XCTAssertNotNil(value)
XCTAssertEqual(value, instance.ad)
}
}

class TestAdEvent: IMAAdEvent {
// Workaround to subclass an Objective-C class that has an `init` constructor with NS_UNAVAILABLE
static func customInit() -> TestAdEvent {
let instance =
TestAdEvent.perform(NSSelectorFromString("new")).takeRetainedValue() as! TestAdEvent
instance._ad = TestAd.customInit()
return instance
}

var _ad: TestAd?

override var type: IMAAdEventType {
return .AD_BREAK_ENDED
}
Expand All @@ -62,4 +76,8 @@ class TestAdEvent: IMAAdEvent {
override var adData: [String: Any]? {
return ["my": "string"]
}

override var ad: IMAAd? {
return _ad!
}
}
Loading