From f185e2943c0fad6366ad4620ace275820ec47fcd Mon Sep 17 00:00:00 2001 From: John Rosendahl Date: Thu, 29 Oct 2026 16:15:54 -0600 Subject: [PATCH] Use the consents passed in OptableConfig OptableConfig.consents was never read: OptableSDK created its ConsentsManager with empty consents, so consents passed in the config were silently dropped and only setConsents() had an effect. Start the ConsentsManager with config.consents; setConsents() still replaces them. The README note now says what the code does. Co-Authored-By: Claude Opus 5.5 --- README.md | 7 ++++++- .../src/main/java/co/optable/sdk/OptableSDK.kt | 2 +- .../src/test/java/co/optable/sdk/OptableSDKTest.kt | 13 +++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2590d19..ba92062 100644 --- a/README.md +++ b/README.md @@ -694,7 +694,12 @@ If not set, SDK will try to fetch data from SharedPreferences (key `IABGPP_2_TCS - `gppSid` A comma-separated list of up to two sections applicable in a given GPP privacy string. This value is required when gpp is present. - `req` Optable privacy regulation override, which can be one of: `gdpr`, `can`, `us`, or `null` and will override all other privacy regulations when present. -**NOTE**: The custom values provided to the `OptableConfig` will override all other privacy regulations when present. +You can also pass the consents when creating the SDK, with the `consents` parameter of `OptableConfig`. A +later call to `setConsents()` replaces them as a whole: a value not set in the new `OptableConsents` is no longer sent, +unless it is found in SharedPreferences. + +**NOTE**: The custom values provided to `OptableConfig` or `setConsents()` take precedence over the values found in +SharedPreferences. ## Demo Applications diff --git a/android_sdk/src/main/java/co/optable/sdk/OptableSDK.kt b/android_sdk/src/main/java/co/optable/sdk/OptableSDK.kt index 1b7690f..f06ab10 100644 --- a/android_sdk/src/main/java/co/optable/sdk/OptableSDK.kt +++ b/android_sdk/src/main/java/co/optable/sdk/OptableSDK.kt @@ -28,7 +28,7 @@ class OptableSDK( ) { private val storage = LocalStorage(config) - private val consentsManager = ConsentsManager(storage) + private val consentsManager = ConsentsManager(storage, config.consents) private val googleAdIdManager = GoogleAdIdManager(config) private val userAgentHolder = UserAgentHolder(config) private val appInfoHolder = AppInfoHolder(config) diff --git a/android_sdk/src/test/java/co/optable/sdk/OptableSDKTest.kt b/android_sdk/src/test/java/co/optable/sdk/OptableSDKTest.kt index 99bf105..6acb1e3 100644 --- a/android_sdk/src/test/java/co/optable/sdk/OptableSDKTest.kt +++ b/android_sdk/src/test/java/co/optable/sdk/OptableSDKTest.kt @@ -359,6 +359,19 @@ class OptableSDKTest { assertEquals(errorMessage, (slot.captured as OptableResult.Error).message) } + @Test + fun `consents from config should be used by consents manager`() { + val consents = OptableConsents(gdprSubject = true, gdprConsent = "consent", gpp = "gpp", gppSid = "2", reg = "us") + every { mockConfig.consents } returns consents + + val sdkWithConsents = OptableSDK(mockConfig) + + val field: Field = sdkWithConsents.javaClass.getDeclaredField("consentsManager") + field.isAccessible = true + val consentsManager = field.get(sdkWithConsents) as ConsentsManager + assertEquals(consents, consentsManager.customConsents) + } + @Test fun `setConsents should update consents manager`() { val consents = mockk()