Skip to content
Open
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
24 changes: 13 additions & 11 deletions src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -496,23 +496,25 @@ class AppsFlyerKit :
AppsFlyerConsentValues.DENIED.consentValue -> adPersonalizationConsentValue = false
}

val clientConsentSettings = parseToNestedMap(consentState.toString())
if (consentState != null) {
val clientConsentSettings = parseToNestedMap(consentState.toString())

parseConsentMapping(settings[CONSENT_MAPPING]).iterator().forEach { currentConsent ->
parseConsentMapping(settings[CONSENT_MAPPING]).iterator().forEach { currentConsent ->

val isConsentAvailable =
searchKeyInNestedMap(clientConsentSettings, key = currentConsent.key)
val isConsentAvailable =
searchKeyInNestedMap(clientConsentSettings, key = currentConsent.key)

if (isConsentAvailable != null) {
val isConsentGranted: Boolean =
JSONObject(isConsentAvailable.toString()).opt("consented") as Boolean
if (isConsentAvailable != null) {
val isConsentGranted: Boolean =
JSONObject(isConsentAvailable.toString()).opt("consented") as Boolean

when (currentConsent.value) {
"ad_storage" -> adStorageConsentValue = isConsentGranted
when (currentConsent.value) {
"ad_storage" -> adStorageConsentValue = isConsentGranted

"ad_user_data" -> adUserDataConsentValue = isConsentGranted
"ad_user_data" -> adUserDataConsentValue = isConsentGranted

"ad_personalization" -> adPersonalizationConsentValue = isConsentGranted
"ad_personalization" -> adPersonalizationConsentValue = isConsentGranted
}
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,35 @@ class AppsflyerKitTests {
Assert.assertEquals(false, notExpectedConsentKey3)
}

@Test
@Throws(Exception::class)
fun testSetConsentWhenGDPRAppliesWithoutConsentStateUsesDefaults() {
val map = HashMap<String?, String?>()
map["defaultAdStorageConsent"] = "Granted"
map["gdprApplies"] = "true"
map["consentMapping"] =
"[{\\\"jsmap\\\":null,\\\"map\\\":\\\"Performance\\\",\\\"maptype\\\":\\\"ConsentPurposes\\\",\\\"value\\\":\\\"ad_user_data\\\"},{\\\"jsmap\\\":null,\\\"map\\\":\\\"Marketing\\\",\\\"maptype\\\":\\\"ConsentPurposes\\\",\\\"value\\\":\\\"ad_personalization\\\"},{\\\"jsmap\\\":null,\\\"map\\\":\\\"testconsent\\\",\\\"maptype\\\":\\\"ConsentPurposes\\\",\\\"value\\\":\\\"ad_storage\\\"}]"
map["defaultAdUserDataConsent"] = "Denied"
map["defaultAdPersonalizationConsent"] = "Unspecified"

kit.configuration =
KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap()))

val method: Method =
AppsFlyerKit::class.java.getDeclaredMethod(
"setConsent",
ConsentState::class.java,
)
method.isAccessible = true
method.invoke(kit, null)

val afConsentResults = appsflyer.getConsentState()
Assert.assertEquals(true, afConsentResults["isUserSubjectToGDPR"])
Assert.assertEquals(false, afConsentResults["hasConsentForDataUsage"])
Assert.assertFalse(afConsentResults.containsKey("hasConsentForAdsPersonalization"))
Assert.assertEquals(true, afConsentResults["hasConsentForAdStorage"])
}

@Test
@Throws(Exception::class)
fun testConsentWhenGDPRAppliedWithConsentDefaults() {
Expand Down