diff --git a/securesignals-gma-dev-app/src/main/AndroidManifest.xml b/securesignals-gma-dev-app/src/main/AndroidManifest.xml index 02047f6..c2b9627 100644 --- a/securesignals-gma-dev-app/src/main/AndroidManifest.xml +++ b/securesignals-gma-dev-app/src/main/AndroidManifest.xml @@ -14,7 +14,10 @@ + android:value="ca-app-pub-9939518381636264~1092563270"/> + + + = Build.VERSION_CODES.TIRAMISU) { + @Suppress("WrongConstant") + getApplicationInfo(packageName, PackageManager.ApplicationInfoFlags.of(flags.toLong())) + } else { + @Suppress("DEPRECATION") + getApplicationInfo(packageName, flags) + } diff --git a/securesignals-gma-dev-app/src/main/res/values/strings.xml b/securesignals-gma-dev-app/src/main/res/values/strings.xml index a6e467a..e6ee491 100644 --- a/securesignals-gma-dev-app/src/main/res/values/strings.xml +++ b/securesignals-gma-dev-app/src/main/res/values/strings.xml @@ -6,6 +6,6 @@ Settings - ca-app-pub-3940256099942544/6300978111 + /21775744923/example/fixed-size-banner diff --git a/securesignals-gma/src/main/java/com/uid2/securesignals/gma/EUIDMediationAdapter.kt b/securesignals-gma/src/main/java/com/uid2/securesignals/gma/EUIDMediationAdapter.kt new file mode 100644 index 0000000..78e1e0f --- /dev/null +++ b/securesignals-gma/src/main/java/com/uid2/securesignals/gma/EUIDMediationAdapter.kt @@ -0,0 +1,76 @@ +package com.uid2.securesignals.gma + +import android.content.Context +import com.google.android.gms.ads.AdError +import com.google.android.gms.ads.mediation.InitializationCompleteCallback +import com.google.android.gms.ads.mediation.MediationConfiguration +import com.google.android.gms.ads.mediation.rtb.RtbAdapter +import com.google.android.gms.ads.mediation.rtb.RtbSignalData +import com.google.android.gms.ads.mediation.rtb.SignalCallbacks +import com.uid2.EUIDManager +import com.uid2.UID2 +import com.google.android.gms.ads.mediation.VersionInfo as GmaVersionInfo + +/** + * An implementation of Google's GMS RtbAdapter that integrates UID2 tokens, accessed via the UID2Manager. + */ +public class EUIDMediationAdapter : RtbAdapter() { + + /** + * Gets the version of the UID2 SDK. + */ + @Suppress("DEPRECATION") + public override fun getSDKVersionInfo(): GmaVersionInfo = UID2.getVersionInfo().let { + GmaVersionInfo(it.major, it.minor, it.patch) + } + + /** + * Gets the version of the UID2 Secure Signals plugin. + */ + @Suppress("DEPRECATION") + public override fun getVersionInfo(): GmaVersionInfo = PluginVersion.getVersionInfo().let { + GmaVersionInfo(it.major, it.minor, it.patch) + } + + /** + * Initialises the UID2 SDK with the given Context. + */ + override fun initialize( + context: Context, + initializationCompleteCallback: InitializationCompleteCallback, + mediationConfigurations: MutableList, + ) { + // It's possible that the UID2Manager is already initialised. If so, it's a no-op. + if (!EUIDManager.isInitialized()) { + EUIDManager.init(context) + } + + // After we've asked to initialize the manager, we should wait until it's complete before reporting success. + // This will potentially allow any previously persisted identity to be fully restored before we allow any + // signals to be collected. + EUIDManager.getInstance().addOnInitializedListener(initializationCompleteCallback::onInitializationSucceeded) + } + + /** + * Collects the UID2 advertising token, if available. + */ + override fun collectSignals(rtbSignalData: RtbSignalData, signalCallbacks: SignalCallbacks) { + EUIDManager.getInstance().let { manager -> + val token = manager.getAdvertisingToken() + if (token != null) { + signalCallbacks.onSuccess(token) + } else { + // We include the IdentityStatus in the "error" to have better visibility on why the Advertising Token + // was not present. There are a number of valid reasons why we don't have a token, but we are still + // required to report these as "failures". + signalCallbacks.onFailure( + AdError( + manager.currentIdentityStatus.value, + "No Advertising Token", + "UID2", + ), + ) + } + } + } +} diff --git a/securesignals-gma/src/test/java/com/uid2/securesignals/gma/EUIDMediationAdapterTest.kt b/securesignals-gma/src/test/java/com/uid2/securesignals/gma/EUIDMediationAdapterTest.kt new file mode 100644 index 0000000..edb1900 --- /dev/null +++ b/securesignals-gma/src/test/java/com/uid2/securesignals/gma/EUIDMediationAdapterTest.kt @@ -0,0 +1,29 @@ +package com.uid2.securesignals.gma + +import com.uid2.UID2 +import org.junit.Assert +import org.junit.Test + +class EUIDMediationAdapterTest { + @Test + fun `test SDK version`() { + val adapter = EUIDMediationAdapter() + val version = adapter.versionInfo + val expectedVersion = UID2.getVersionInfo() + + Assert.assertEquals(expectedVersion.major, version.majorVersion) + Assert.assertEquals(expectedVersion.minor, version.minorVersion) + Assert.assertEquals(expectedVersion.patch, version.microVersion) + } + + @Test + fun `test plugin version`() { + val adapter = EUIDMediationAdapter() + val version = adapter.sdkVersionInfo + val expectedVersion = PluginVersion.getVersionInfo() + + Assert.assertEquals(expectedVersion.major, version.majorVersion) + Assert.assertEquals(expectedVersion.minor, version.minorVersion) + Assert.assertEquals(expectedVersion.patch, version.microVersion) + } +}