From 429d744887cd483e4120970afc2d3a58e34f1f1d Mon Sep 17 00:00:00 2001 From: Dave Snabel-Caunt Date: Mon, 9 Sep 2024 15:18:25 +0100 Subject: [PATCH] Revert GMA and IMA changes --- .../src/main/AndroidManifest.xml | 3 - .../java/com/uid2/dev/BannerActivity.java | 11 +-- .../java/com/uid2/dev/GMADevApplication.kt | 20 ++--- .../main/java/com/uid2/dev/utils/BundleEx.kt | 7 -- .../main/java/com/uid2/dev/utils/ContextEx.kt | 10 --- .../com/uid2/dev/utils/PackageManagerEx.kt | 14 ---- .../securesignals/gma/EUIDMediationAdapter.kt | 76 ------------------- .../gma/EUIDMediationAdapterTest.kt | 29 ------- .../src/main/AndroidManifest.xml | 3 - .../java/com/uid2/dev/IMADevApplication.kt | 20 ++--- .../main/java/com/uid2/dev/MainActivity.java | 10 +-- .../main/java/com/uid2/dev/utils/BundleEx.kt | 7 -- .../main/java/com/uid2/dev/utils/ContextEx.kt | 10 --- .../com/uid2/dev/utils/PackageManagerEx.kt | 14 ---- .../ima/EUIDSecureSignalsAdapter.kt | 70 ----------------- .../ima/EUIDSecureSignalsAdapterTest.kt | 29 ------- 16 files changed, 13 insertions(+), 320 deletions(-) delete mode 100644 securesignals-gma-dev-app/src/main/java/com/uid2/dev/utils/BundleEx.kt delete mode 100644 securesignals-gma-dev-app/src/main/java/com/uid2/dev/utils/ContextEx.kt delete mode 100644 securesignals-gma-dev-app/src/main/java/com/uid2/dev/utils/PackageManagerEx.kt delete mode 100644 securesignals-gma/src/main/java/com/uid2/securesignals/gma/EUIDMediationAdapter.kt delete mode 100644 securesignals-gma/src/test/java/com/uid2/securesignals/gma/EUIDMediationAdapterTest.kt delete mode 100644 securesignals-ima-dev-app/src/main/java/com/uid2/dev/utils/BundleEx.kt delete mode 100644 securesignals-ima-dev-app/src/main/java/com/uid2/dev/utils/ContextEx.kt delete mode 100644 securesignals-ima-dev-app/src/main/java/com/uid2/dev/utils/PackageManagerEx.kt delete mode 100644 securesignals-ima/src/main/java/com/uid2/securesignals/ima/EUIDSecureSignalsAdapter.kt delete mode 100644 securesignals-ima/src/test/java/com/uid2/securesignals/ima/EUIDSecureSignalsAdapterTest.kt diff --git a/securesignals-gma-dev-app/src/main/AndroidManifest.xml b/securesignals-gma-dev-app/src/main/AndroidManifest.xml index 1311467..02047f6 100644 --- a/securesignals-gma-dev-app/src/main/AndroidManifest.xml +++ b/securesignals-gma-dev-app/src/main/AndroidManifest.xml @@ -16,9 +16,6 @@ android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-3940256099942544~3347511713"/> - - - diff --git a/securesignals-gma-dev-app/src/main/java/com/uid2/dev/BannerActivity.java b/securesignals-gma-dev-app/src/main/java/com/uid2/dev/BannerActivity.java index d5e4d37..6a3d3e8 100644 --- a/securesignals-gma-dev-app/src/main/java/com/uid2/dev/BannerActivity.java +++ b/securesignals-gma-dev-app/src/main/java/com/uid2/dev/BannerActivity.java @@ -1,8 +1,5 @@ package com.uid2.dev; -import static com.uid2.dev.utils.BundleExKt.isEnvironmentEUID; -import static com.uid2.dev.utils.ContextExKt.getMetadata; - import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; import android.util.Log; @@ -14,9 +11,9 @@ import com.google.android.gms.ads.RequestConfiguration; import com.google.android.gms.ads.initialization.InitializationStatus; import com.google.android.gms.ads.initialization.OnInitializationCompleteListener; -import com.uid2.EUIDManager; import com.uid2.UID2Manager; import com.uid2.data.UID2Identity; + import org.json.JSONObject; import java.io.BufferedReader; @@ -104,11 +101,7 @@ private void loadUID2Identity() { refreshFrom, refreshExpires, fromJsonIdentity.getRefreshResponseKey()); - if (isEnvironmentEUID(getMetadata(this))) { - EUIDManager.getInstance().setIdentity(identity); - } else { - UID2Manager.getInstance().setIdentity(identity); - } + UID2Manager.getInstance().setIdentity(identity); } catch (Exception e) { Log.e(TAG, "Error loading Identity: " + e); } diff --git a/securesignals-gma-dev-app/src/main/java/com/uid2/dev/GMADevApplication.kt b/securesignals-gma-dev-app/src/main/java/com/uid2/dev/GMADevApplication.kt index 0d34a6a..5becb71 100644 --- a/securesignals-gma-dev-app/src/main/java/com/uid2/dev/GMADevApplication.kt +++ b/securesignals-gma-dev-app/src/main/java/com/uid2/dev/GMADevApplication.kt @@ -2,11 +2,8 @@ package com.uid2.dev import android.app.Application import android.util.Log -import com.uid2.EUIDManager import com.uid2.UID2Manager import com.uid2.UID2Manager.Environment.Production -import com.uid2.dev.utils.getMetadata -import com.uid2.dev.utils.isEnvironmentEUID class GMADevApplication : Application() { @@ -16,18 +13,11 @@ class GMADevApplication : Application() { // Initialise the UID2Manager class. We will use it's DefaultNetworkSession rather than providing our own // custom implementation. This can be done to allow wrapping something like OkHttp. try { - if (getMetadata().isEnvironmentEUID()) { - EUIDManager.init( - context = this, - isLoggingEnabled = true, - ) - } else { - UID2Manager.init( - context = this, - environment = Production, - isLoggingEnabled = true, - ) - } + UID2Manager.init( + context = this, + environment = Production, + isLoggingEnabled = true, + ) } catch (ex: Exception) { Log.e("GMADevApplication", "Error initialising UID2Manager", ex) } diff --git a/securesignals-gma-dev-app/src/main/java/com/uid2/dev/utils/BundleEx.kt b/securesignals-gma-dev-app/src/main/java/com/uid2/dev/utils/BundleEx.kt deleted file mode 100644 index 2a68700..0000000 --- a/securesignals-gma-dev-app/src/main/java/com/uid2/dev/utils/BundleEx.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.uid2.dev.utils - -import android.os.Bundle - -private const val UID2_ENVIRONMENT_EUID = "uid2_environment_euid" - -fun Bundle.isEnvironmentEUID(): Boolean = getBoolean(UID2_ENVIRONMENT_EUID, false) diff --git a/securesignals-gma-dev-app/src/main/java/com/uid2/dev/utils/ContextEx.kt b/securesignals-gma-dev-app/src/main/java/com/uid2/dev/utils/ContextEx.kt deleted file mode 100644 index 91eef6c..0000000 --- a/securesignals-gma-dev-app/src/main/java/com/uid2/dev/utils/ContextEx.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.uid2.dev.utils - -import android.content.Context -import android.content.pm.PackageManager -import android.os.Bundle - -fun Context.getMetadata(): Bundle = packageManager.getApplicationInfoCompat( - packageName, - PackageManager.GET_META_DATA, -).metaData diff --git a/securesignals-gma-dev-app/src/main/java/com/uid2/dev/utils/PackageManagerEx.kt b/securesignals-gma-dev-app/src/main/java/com/uid2/dev/utils/PackageManagerEx.kt deleted file mode 100644 index e4f930c..0000000 --- a/securesignals-gma-dev-app/src/main/java/com/uid2/dev/utils/PackageManagerEx.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.uid2.dev.utils - -import android.content.pm.ApplicationInfo -import android.content.pm.PackageManager -import android.os.Build - -fun PackageManager.getApplicationInfoCompat(packageName: String, flags: Int = 0): ApplicationInfo = - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - @Suppress("WrongConstant") - getApplicationInfo(packageName, PackageManager.ApplicationInfoFlags.of(flags.toLong())) - } else { - @Suppress("DEPRECATION") - getApplicationInfo(packageName, flags) - } 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 deleted file mode 100644 index 78e1e0f..0000000 --- a/securesignals-gma/src/main/java/com/uid2/securesignals/gma/EUIDMediationAdapter.kt +++ /dev/null @@ -1,76 +0,0 @@ -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 deleted file mode 100644 index edb1900..0000000 --- a/securesignals-gma/src/test/java/com/uid2/securesignals/gma/EUIDMediationAdapterTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -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) - } -} diff --git a/securesignals-ima-dev-app/src/main/AndroidManifest.xml b/securesignals-ima-dev-app/src/main/AndroidManifest.xml index 4852817..13d22da 100644 --- a/securesignals-ima-dev-app/src/main/AndroidManifest.xml +++ b/securesignals-ima-dev-app/src/main/AndroidManifest.xml @@ -14,9 +14,6 @@ android:networkSecurityConfig="@xml/network_security_config" tools:ignore="UnusedAttribute"> - - - = Build.VERSION_CODES.TIRAMISU) { - @Suppress("WrongConstant") - getApplicationInfo(packageName, PackageManager.ApplicationInfoFlags.of(flags.toLong())) - } else { - @Suppress("DEPRECATION") - getApplicationInfo(packageName, flags) - } diff --git a/securesignals-ima/src/main/java/com/uid2/securesignals/ima/EUIDSecureSignalsAdapter.kt b/securesignals-ima/src/main/java/com/uid2/securesignals/ima/EUIDSecureSignalsAdapter.kt deleted file mode 100644 index 46c1eff..0000000 --- a/securesignals-ima/src/main/java/com/uid2/securesignals/ima/EUIDSecureSignalsAdapter.kt +++ /dev/null @@ -1,70 +0,0 @@ -package com.uid2.securesignals.ima - -import android.content.Context -import com.google.ads.interactivemedia.v3.api.VersionInfo -import com.google.ads.interactivemedia.v3.api.signals.SecureSignalsAdapter -import com.google.ads.interactivemedia.v3.api.signals.SecureSignalsCollectSignalsCallback -import com.google.ads.interactivemedia.v3.api.signals.SecureSignalsInitializeCallback -import com.uid2.EUIDManager -import com.uid2.UID2 - -/** - * A custom exception type that is used to report failures from the EUIDSecureSignalsAdapter when an error has occurred. - */ -public class EUIDSecureSignalsException(message: String? = null, cause: Throwable? = null) : Exception(message, cause) - -/** - * An implementation of Google's IMA SecureSignalsAdapter that integrates UID2 tokens, accessed via the UID2Manager. - */ -public class EUIDSecureSignalsAdapter : SecureSignalsAdapter { - - /** - * Gets the version of the UID2 SDK. - */ - public override fun getSDKVersion(): VersionInfo = UID2.getVersionInfo().let { - VersionInfo(it.major, it.minor, it.patch) - } - - /** - * Gets the version of the UID2 Secure Signals plugin. - */ - public override fun getVersion(): VersionInfo = PluginVersion.getVersionInfo().let { - VersionInfo(it.major, it.minor, it.patch) - } - - /** - * Initialises the UID2 SDK with the given Context. - */ - public override fun initialize(context: Context, callback: SecureSignalsInitializeCallback) { - // It's possible that the EUIDManager 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(callback::onSuccess) - } - - /** - * Collects the UID2 advertising token, if available. - */ - public override fun collectSignals(context: Context, callback: SecureSignalsCollectSignalsCallback) { - EUIDManager.getInstance().let { manager -> - val token = manager.getAdvertisingToken() - if (token != null) { - callback.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". - callback.onFailure( - EUIDSecureSignalsException( - "No Advertising Token available (Status: ${manager.currentIdentityStatus.value})", - ), - ) - } - } - } -} diff --git a/securesignals-ima/src/test/java/com/uid2/securesignals/ima/EUIDSecureSignalsAdapterTest.kt b/securesignals-ima/src/test/java/com/uid2/securesignals/ima/EUIDSecureSignalsAdapterTest.kt deleted file mode 100644 index 2f2125e..0000000 --- a/securesignals-ima/src/test/java/com/uid2/securesignals/ima/EUIDSecureSignalsAdapterTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.uid2.securesignals.ima - -import com.uid2.UID2 -import org.junit.Assert.assertEquals -import org.junit.Test - -class EUIDSecureSignalsAdapterTest { - @Test - fun `test SDK version`() { - val adapter = UID2SecureSignalsAdapter() - val version = adapter.sdkVersion - val expectedVersion = UID2.getVersionInfo() - - assertEquals(expectedVersion.major, version.majorVersion) - assertEquals(expectedVersion.minor, version.minorVersion) - assertEquals(expectedVersion.patch, version.microVersion) - } - - @Test - fun `test plugin version`() { - val adapter = UID2SecureSignalsAdapter() - val version = adapter.version - val expectedVersion = PluginVersion.getVersionInfo() - - assertEquals(expectedVersion.major, version.majorVersion) - assertEquals(expectedVersion.minor, version.minorVersion) - assertEquals(expectedVersion.patch, version.microVersion) - } -}