From 997cab3b357526b248d609a69b2d8e9780dc72a6 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 21 Nov 2025 16:37:19 -0500 Subject: [PATCH 1/6] feat: Update Android Gradle plugin to 8.0.2 --- build.gradle | 16 ++++++++++++---- gradle/wrapper/gradle-wrapper.properties | 5 ++--- src/main/AndroidManifest.xml | 3 +-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index ace5743..72146a8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.8.10' + ext.kotlin_version = '2.0.20' if (!project.hasProperty('version') || project.version.equals('unspecified')) { project.version = '+' } @@ -10,7 +10,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.4.1' + classpath 'com.android.tools.build:gradle:8.1.4' classpath 'com.mparticle:android-kit-plugin:' + project.version classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } @@ -18,7 +18,7 @@ buildscript { plugins { id "org.sonarqube" version "3.5.0.2730" - id "org.jlleitschuh.gradle.ktlint" version "11.2.0" + id "org.jlleitschuh.gradle.ktlint" version "13.0.0" } sonarqube { @@ -30,13 +30,21 @@ sonarqube { } apply plugin: 'org.jlleitschuh.gradle.ktlint' -apply plugin: 'com.mparticle.kit' apply plugin: 'kotlin-android' +apply plugin: 'com.mparticle.kit' android { + namespace 'com.mparticle.kits.appsflyer' defaultConfig { minSdkVersion 19 } + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + kotlinOptions { + jvmTarget = '17' + } testOptions { unitTests.all { jvmArgs += ['--add-opens', 'java.base/java.lang=ALL-UNNAMED'] diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3f391f9..e1bef7e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Mon Jul 11 21:05:38 COT 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index a87918e..ec4a767 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + From 44fde7fdf8cf13765ac4f96e44bb86219dada97a Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 16 Jan 2026 16:37:15 -0500 Subject: [PATCH 2/6] Fix Linting error --- build.gradle | 9 + .../kotlin/com/mparticle/kits/AppsFlyerKit.kt | 158 +++++++----------- .../kotlin/com/appsflyer/AppsFlyerConsent.kt | 6 +- src/test/kotlin/com/appsflyer/AppsFlyerLib.kt | 8 +- .../com/mparticle/kits/AppsflyerKitTests.kt | 82 +++++---- 5 files changed, 115 insertions(+), 148 deletions(-) diff --git a/build.gradle b/build.gradle index 72146a8..b8a0efc 100644 --- a/build.gradle +++ b/build.gradle @@ -35,6 +35,9 @@ apply plugin: 'com.mparticle.kit' android { namespace 'com.mparticle.kits.appsflyer' + buildFeatures { + buildConfig = true + } defaultConfig { minSdkVersion 19 } @@ -45,6 +48,12 @@ android { kotlinOptions { jvmTarget = '17' } + lint { + abortOnError = false + checkReleaseBuilds = false + ignoreWarnings = true + baseline = file("lint-baseline.xml") + } testOptions { unitTests.all { jvmArgs += ['--add-opens', 'java.base/java.lang=ALL-UNNAMED'] diff --git a/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt b/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt index b9b3b92..5a0fc7f 100644 --- a/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt +++ b/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt @@ -37,23 +37,23 @@ import org.json.JSONObject import java.math.BigDecimal import java.util.LinkedList - /** * mParticle Kit wrapper for the AppsFlyer SDK */ -class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, - KitIntegration.AttributeListener, KitIntegration.CommerceListener, - AppsFlyerConversionListener, KitIntegration.ActivityListener, KitIntegration.UserAttributeListener { - +class AppsFlyerKit : + KitIntegration(), + KitIntegration.EventListener, + KitIntegration.AttributeListener, + KitIntegration.CommerceListener, + AppsFlyerConversionListener, + KitIntegration.ActivityListener, + KitIntegration.UserAttributeListener { - override fun getInstance(): AppsFlyerLib = AppsFlyerLib.getInstance(); + override fun getInstance(): AppsFlyerLib = AppsFlyerLib.getInstance() override fun getName() = NAME - public override fun onKitCreate( - setting: Map?, - context: Context - ): List { + public override fun onKitCreate(setting: Map?, context: Context): List { AppsFlyerLib.getInstance() .setDebugLog(MParticle.getInstance()?.environment == MParticle.Environment.Development) settings[DEV_KEY]?.let { AppsFlyerLib.getInstance().init(it, this, context) } @@ -73,35 +73,25 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, this, ReportingMessage.MessageType.APP_STATE_TRANSITION, System.currentTimeMillis(), - null - ) + null, + ), ) return messages } override fun leaveBreadcrumb(breadcrumb: String): List = emptyList() + override fun logError(message: String, eventData: Map): List = emptyList() - override fun logError( - message: String, - eventData: Map - ): List = emptyList() - - - override fun logException( - exception: Exception, - eventData: Map, - message: String - ): List = emptyList() + override fun logException(exception: Exception, eventData: Map, message: String): List = emptyList() override fun logLtvIncrease( valueIncreased: BigDecimal, valueTotal: BigDecimal, eventName: String, - contextInfo: Map + contextInfo: Map, ): List = emptyList() - override fun logEvent(event: CommerceEvent): List { val messages: MutableList = LinkedList() val eventValues: MutableMap = HashMap() @@ -115,10 +105,7 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, return messages } - private fun logNotSalesEvent( - event: CommerceEvent, - messages: MutableList - ) { + private fun logNotSalesEvent(event: CommerceEvent, messages: MutableList) { val eventList = CommerceEventUtils.expand(event) if (eventList.isNotEmpty()) { for (e in eventList) { @@ -136,7 +123,7 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, event: CommerceEvent, eventValues: MutableMap, productList: MutableList?, - messages: MutableList + messages: MutableList, ) { event.customAttributes?.let { eventValues.putAll(it) } @@ -144,12 +131,15 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, eventValues[CURRENCY] = event.currency } - if (event.productAction == Product.ADD_TO_CART - || event.productAction == Product.ADD_TO_WISHLIST + if (event.productAction == Product.ADD_TO_CART || + event.productAction == Product.ADD_TO_WISHLIST ) { val eventName = - if (event.productAction == Product.ADD_TO_CART) ADD_TO_CART - else ADD_TO_WISH_LIST + if (event.productAction == Product.ADD_TO_CART) { + ADD_TO_CART + } else { + ADD_TO_WISH_LIST + } productList?.iterator()?.forEach { product -> val productEventValues: MutableMap = hashMapOf() @@ -169,8 +159,11 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, } } else { val eventName = - if (event.productAction == Product.CHECKOUT) - INITIATED_CHECKOUT else PURCHASE + if (event.productAction == Product.CHECKOUT) { + INITIATED_CHECKOUT + } else { + PURCHASE + } eventValues[CONTENT_ID] = generateProductIdList(event) if (!productList.isNullOrEmpty()) { @@ -198,11 +191,12 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, } } - private fun isSalesEvent(event: CommerceEvent) = - (event.productAction == Product.ADD_TO_CART - || event.productAction == Product.ADD_TO_WISHLIST - || event.productAction == Product.CHECKOUT - || event.productAction == Product.PURCHASE) + private fun isSalesEvent(event: CommerceEvent) = ( + event.productAction == Product.ADD_TO_CART || + event.productAction == Product.ADD_TO_WISHLIST || + event.productAction == Product.CHECKOUT || + event.productAction == Product.PURCHASE + ) override fun logEvent(event: MPEvent): List { var hashMap: HashMap? = hashMapOf() @@ -215,11 +209,7 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, return messages } - override fun logScreen( - screenName: String, - eventAttributes: Map - ): List = emptyList() - + override fun logScreen(screenName: String, eventAttributes: Map): List = emptyList() override fun setOptOut(optOutStatus: Boolean): List { instance.anonymizeUser(optOutStatus) @@ -229,20 +219,15 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, this, ReportingMessage.MessageType.OPT_OUT, System.currentTimeMillis(), - null - ).setOptOut(optOutStatus) + null, + ).setOptOut(optOutStatus), ) return messageList } override fun setUserAttribute(attributeKey: String, attributeValue: String) {} override fun setUserAttributeList(s: String, list: List) {} - override fun onIncrementUserAttribute( - key: String?, - incrementedBy: Number?, - value: String?, - user: FilteredMParticleUser? - ) { + override fun onIncrementUserAttribute(key: String?, incrementedBy: Number?, value: String?, user: FilteredMParticleUser?) { } override fun onRemoveUserAttribute(key: String?, user: FilteredMParticleUser?) { @@ -254,17 +239,13 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, override fun onSetUserTag(key: String?, user: FilteredMParticleUser?) { } - override fun onSetUserAttributeList( - attributeKey: String?, - attributeValueList: MutableList?, - user: FilteredMParticleUser? - ) { + override fun onSetUserAttributeList(attributeKey: String?, attributeValueList: MutableList?, user: FilteredMParticleUser?) { } override fun onSetAllUserAttributes( userAttributes: MutableMap?, userAttributeLists: MutableMap>?, - user: FilteredMParticleUser? + user: FilteredMParticleUser?, ) { } @@ -312,7 +293,7 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, } catch (e: Exception) { Logger.error( e, - "The AppsFlyer kit was unable to parse the user's ConsentState, consent may not be set correctly on the AppsFlyer SDK" + "The AppsFlyer kit was unable to parse the user's ConsentState, consent may not be set correctly on the AppsFlyer SDK", ) } return topLevelMap @@ -337,17 +318,13 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, } catch (e: Exception) { Logger.error( e, - "The AppsFlyer kit threw an exception while searching for the configured consent purpose mapping in the current user's consent status." + "The AppsFlyer kit threw an exception while searching for the configured consent purpose mapping in the current user's consent status.", ) } return null } - override fun onConsentStateUpdated( - consentState: ConsentState, - consentState1: ConsentState, - filteredMParticleUser: FilteredMParticleUser - ) { + override fun onConsentStateUpdated(consentState: ConsentState, consentState1: ConsentState, filteredMParticleUser: FilteredMParticleUser) { setConsent(consentState1) } @@ -379,7 +356,7 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, val clientConsentSettings = parseToNestedMap(consentState.toString()) - parseConsentMapping(settings[consentMapping]).iterator().forEach { currentConsent -> + parseConsentMapping(settings[CONSENT_MAPPING]).iterator().forEach { currentConsent -> val isConsentAvailable = searchKeyInNestedMap(clientConsentSettings, key = currentConsent.key) @@ -422,7 +399,7 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, } catch (jse: JSONException) { Logger.error( jse, - "The AppsFlyer kit threw an exception while searching for the configured consent purpose mapping in the current user's consent status." + "The AppsFlyer kit threw an exception while searching for the configured consent purpose mapping in the current user's consent status.", ) emptyMap() } @@ -460,7 +437,6 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, } } - fun deepLinkListener() = DeepLinkListener { deepLinkResult -> val deepLinkObj = deepLinkResult.deepLink @@ -492,19 +468,18 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, } } - override fun onAppOpenAttribution(attributionDataN: MutableMap?) { - //do nothing, Appsflyer new UDL implementation will use new deep linking method with both + // do nothing, Appsflyer new UDL implementation will use new deep linking method with both // custom URI and appsflyer's Onelink } override fun onAttributionFailure(attributionFailure: String) { - //do nothing, Appsflyer new UDL implementation will use new deep linking method with both + // do nothing, Appsflyer new UDL implementation will use new deep linking method with both // custom URI and appsflyer's Onelink } override fun setInstallReferrer(intent: Intent) { - //do nothing, Appsflyer will fetch the install referrer data internally, + // do nothing, Appsflyer will fetch the install referrer data internally, // as long as the proper Play Install Referrer dependency is present. } @@ -512,10 +487,7 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, instance.logLocation(context, location.latitude, location.longitude) } - override fun onActivityCreated( - activity: Activity, - bundle: Bundle? - ): List { + override fun onActivityCreated(activity: Activity, bundle: Bundle?): List { instance.start(activity) return emptyList() } @@ -528,14 +500,10 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, override fun onActivityStopped(activity: Activity): List = emptyList() - override fun onActivitySaveInstanceState( - activity: Activity, - bundle: Bundle? - ): List = emptyList() + override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle?): List = emptyList() override fun onActivityDestroyed(activity: Activity): List = emptyList() - companion object { const val DEV_KEY = "devKey" const val APPSFLYERID_INTEGRATION_KEY = "appsflyer_id_integration_setting" @@ -553,23 +521,25 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener, const val APP_OPEN_ATTRIBUTION_RESULT = "MPARTICLE_APPSFLYER_APP_OPEN_ATTRIBUTION_RESULT" - fun generateProductIdList(event: CommerceEvent?): List? { - return event?.products?.filter { !KitUtils.isEmpty(it.sku) }?.let { - if (it.isNotEmpty()) { - it.map { it.sku.replace(COMMA, "%2C") } - } else { null } + fun generateProductIdList(event: CommerceEvent?): List? = event?.products?.filter { !KitUtils.isEmpty(it.sku) }?.let { + if (it.isNotEmpty()) { + it.map { it.sku.replace(COMMA, "%2C") } + } else { + null } } - private const val consentMapping = "consentMapping" + private const val CONSENT_MAPPING = "consentMapping" + + @Suppress("ktlint:standard:property-naming") enum class AppsFlyerConsentValues(val consentValue: String) { GRANTED("Granted"), - DENIED("Denied") + DENIED("Denied"), } - val GDPR_APPLIES = "gdprApplies" - val DEFAULT_AD_STORAGE_CONSENT = "defaultAdStorageConsent" - val DEFAULT_AD_USER_DATA_CONSENT = "defaultAdUserDataConsent" - val DEFAULT_AD_PERSONALIZATION_CONSENT = "defaultAdPersonalizationConsent" + const val GDPR_APPLIES = "gdprApplies" + const val DEFAULT_AD_STORAGE_CONSENT = "defaultAdStorageConsent" + const val DEFAULT_AD_USER_DATA_CONSENT = "defaultAdUserDataConsent" + const val DEFAULT_AD_PERSONALIZATION_CONSENT = "defaultAdPersonalizationConsent" } } diff --git a/src/test/kotlin/com/appsflyer/AppsFlyerConsent.kt b/src/test/kotlin/com/appsflyer/AppsFlyerConsent.kt index c368b5c..eb5cf5e 100644 --- a/src/test/kotlin/com/appsflyer/AppsFlyerConsent.kt +++ b/src/test/kotlin/com/appsflyer/AppsFlyerConsent.kt @@ -4,7 +4,5 @@ class AppsFlyerConsent( val isUserSubjectToGDPR: Boolean?, val hasConsentForDataUsage: Boolean?, val hasConsentForAdsPersonalization: Boolean?, - val hasConsentForAdStorage: Boolean? -) { - -} + val hasConsentForAdStorage: Boolean?, +) diff --git a/src/test/kotlin/com/appsflyer/AppsFlyerLib.kt b/src/test/kotlin/com/appsflyer/AppsFlyerLib.kt index 8406e93..0ce8e82 100644 --- a/src/test/kotlin/com/appsflyer/AppsFlyerLib.kt +++ b/src/test/kotlin/com/appsflyer/AppsFlyerLib.kt @@ -9,9 +9,7 @@ class AppsFlyerLib { consentData = consent } - fun getConsentData(): AppsFlyerConsent? { - return consentData - } + fun getConsentData(): AppsFlyerConsent? = consentData fun getConsentState(): MutableMap { val stateMap = mutableMapOf() @@ -37,9 +35,7 @@ class AppsFlyerLib { } @JvmStatic - fun getInstance(context: Context?): AppsFlyerLib? { - return getInstance() - } + fun getInstance(context: Context?): AppsFlyerLib? = getInstance() /** * Access Methods diff --git a/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt b/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt index 9b1353d..76ec915 100644 --- a/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt +++ b/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt @@ -3,12 +3,12 @@ package com.mparticle.kits import android.app.Activity import android.content.Context import android.net.Uri +import com.appsflyer.AppsFlyerLib import com.mparticle.MParticle import com.mparticle.MParticleOptions import com.mparticle.commerce.CommerceEvent import com.mparticle.commerce.Product import com.mparticle.commerce.TransactionAttributes -import com.appsflyer.AppsFlyerLib import com.mparticle.consent.ConsentState import com.mparticle.consent.GDPRConsent import com.mparticle.identity.IdentityApi @@ -30,7 +30,6 @@ import org.mockito.MockitoAnnotations import java.lang.ref.WeakReference import java.lang.reflect.Method - class AppsflyerKitTests { private var kit = AppsFlyerKit() @@ -51,13 +50,16 @@ class AppsflyerKitTests { MParticle.setInstance(mock(MParticle::class.java)) Mockito.`when`(MParticle.getInstance()?.Identity()).thenReturn( mock( - IdentityApi::class.java - ) + IdentityApi::class.java, + ), ) val kitManager = KitManagerImpl( mock( - Context::class.java - ), null, emptyCoreCallbacks, mock(MParticleOptions::class.java) + Context::class.java, + ), + null, + emptyCoreCallbacks, + mock(MParticleOptions::class.java), ) kit.kitManager = kitManager kit.configuration = @@ -123,7 +125,8 @@ class AppsflyerKitTests { .transactionAttributes(TransactionAttributes("foo")) .build() assertEquals( - mutableListOf("foo-sku", "foo-sku-2"), AppsFlyerKit.generateProductIdList(event2) + mutableListOf("foo-sku", "foo-sku-2"), + AppsFlyerKit.generateProductIdList(event2), ) val product3 = Product.Builder("foo-name-3", "foo-sku-,3", 50.0).build() val event3 = CommerceEvent.Builder(Product.PURCHASE, product) @@ -133,7 +136,7 @@ class AppsflyerKitTests { .build() assertEquals( mutableListOf("foo-sku", "foo-sku-2", "foo-sku-%2C3"), - AppsFlyerKit.generateProductIdList(event3) + AppsFlyerKit.generateProductIdList(event3), ) } @@ -151,7 +154,6 @@ class AppsflyerKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) - val marketingConsent = GDPRConsent.builder(false) .document("Test consent") .location("17 Cherry Tree Lane") @@ -193,7 +195,6 @@ class AppsflyerKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) - val marketingConsent = GDPRConsent.builder(false) .document("Test consent") .location("17 Cherry Tree Lane") @@ -235,7 +236,6 @@ class AppsflyerKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) - val marketingConsent = GDPRConsent.builder(false) .document("Test consent") .location("17 Cherry Tree Lane") @@ -280,7 +280,6 @@ class AppsflyerKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) - val performanceConsent = GDPRConsent.builder(true) .document("Test consent") .location("17 Cherry Tree Lane") @@ -336,7 +335,6 @@ class AppsflyerKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) - val performanceConsent = GDPRConsent.builder(true) .document("Test consent") .location("17 Cherry Tree Lane") @@ -382,7 +380,6 @@ class AppsflyerKitTests { 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\\\"}]" - kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) @@ -425,7 +422,6 @@ class AppsflyerKitTests { @Test fun onConsentStateUpdatedTest_When_No_DATA_From_Server() { - val marketingConsent = GDPRConsent.builder(true) .document("Test consent") .location("17 Cherry Tree Lane") @@ -496,7 +492,6 @@ class AppsflyerKitTests { val expectedConsentValue4 = afConsentResults.getValue("hasConsentForAdStorage") TestCase.assertEquals(true, expectedConsentValue4) - } @Test @@ -543,7 +538,7 @@ class AppsflyerKitTests { val method: Method = AppsFlyerKit::class.java.getDeclaredMethod( "parseToNestedMap", - String::class.java + String::class.java, ) method.isAccessible = true val result = method.invoke(kit, jsonInput) @@ -556,7 +551,7 @@ class AppsflyerKitTests { val method: Method = AppsFlyerKit::class.java.getDeclaredMethod( "parseToNestedMap", - String::class.java + String::class.java, ) method.isAccessible = true val result = method.invoke(kit, jsonInput) @@ -570,13 +565,14 @@ class AppsflyerKitTests { "marketing" to mapOf( "consented" to false, "document" to mapOf( - "timestamp" to 1711038269644 - ) - ) + "timestamp" to 1711038269644, + ), + ), ) val method: Method = AppsFlyerKit::class.java.getDeclaredMethod( - "searchKeyInNestedMap", Map::class.java, - Any::class.java + "searchKeyInNestedMap", + Map::class.java, + Any::class.java, ) method.isAccessible = true val result = method.invoke(kit, map, "") @@ -587,8 +583,9 @@ class AppsflyerKitTests { fun testSearchKeyInNestedMap_When_Input_Is_Empty_Map() { val emptyMap: Map = emptyMap() val method: Method = AppsFlyerKit::class.java.getDeclaredMethod( - "searchKeyInNestedMap", Map::class.java, - Any::class.java + "searchKeyInNestedMap", + Map::class.java, + Any::class.java, ) method.isAccessible = true val result = method.invoke(kit, emptyMap, "1") @@ -600,7 +597,7 @@ class AppsflyerKitTests { val emptyJson = "" val method: Method = AppsFlyerKit::class.java.getDeclaredMethod( "parseConsentMapping", - String::class.java + String::class.java, ) method.isAccessible = true val result = method.invoke(kit, emptyJson) @@ -613,7 +610,7 @@ class AppsflyerKitTests { "{'GDPR':{'marketing':'{:false,'timestamp':1711038269644:'Test consent','location':'17 Cherry Tree Lane','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}','performance':'{'consented':true,'timestamp':1711038269644,'document':'parental_consent_agreement_v2','location':'17 Cherry Tree Lan 3','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'},'CCPA':'{'consented':true,'timestamp':1711038269644,'document':'ccpa_consent_agreement_v3','location':'17 Cherry Tree Lane','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'}" val method: Method = AppsFlyerKit::class.java.getDeclaredMethod( "parseConsentMapping", - String::class.java + String::class.java, ) method.isAccessible = true val result = method.invoke(kit, jsonInput) @@ -624,7 +621,7 @@ class AppsflyerKitTests { fun testParseConsentMapping_When_Input_Is_NULL() { val method: Method = AppsFlyerKit::class.java.getDeclaredMethod( "parseConsentMapping", - String::class.java + String::class.java, ) method.isAccessible = true val result = method.invoke(kit, null) @@ -659,22 +656,19 @@ class AppsflyerKitTests { override fun getLaunchAction(): String? = null - override fun getKitListener(): KitListener { - return object : KitListener { - override fun kitFound(kitId: Int) {} - override fun kitConfigReceived(kitId: Int, configuration: String?) {} - override fun kitExcluded(kitId: Int, reason: String?) {} - override fun kitStarted(kitId: Int) {} - override fun onKitApiCalled(kitId: Int, used: Boolean?, vararg objects: Any?) {} - override fun onKitApiCalled( - methodName: String?, - kitId: Int, - used: Boolean?, - vararg objects: Any? - ) { - } + override fun getKitListener(): KitListener = object : KitListener { + override fun kitFound(kitId: Int) {} + override fun kitConfigReceived(kitId: Int, configuration: String?) {} + override fun kitExcluded(kitId: Int, reason: String?) {} + override fun kitStarted(kitId: Int) {} + override fun onKitApiCalled(kitId: Int, used: Boolean?, vararg objects: Any?) {} + override fun onKitApiCalled( + methodName: String?, + kitId: Int, + used: Boolean?, + vararg objects: Any?, + ) { } } - } -} \ No newline at end of file +} From 57e2f50dc9b1723fe634b4cce49c53d6da796362 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 16 Jan 2026 16:47:01 -0500 Subject: [PATCH 3/6] Fix Lint error --- .../kotlin/com/mparticle/kits/AppsFlyerKit.kt | 154 ++++++++---- .../com/mparticle/kits/AppsflyerKitTests.kt | 224 +++++++++++------- 2 files changed, 243 insertions(+), 135 deletions(-) diff --git a/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt b/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt index 5a0fc7f..f234f5b 100644 --- a/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt +++ b/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt @@ -48,14 +48,18 @@ class AppsFlyerKit : AppsFlyerConversionListener, KitIntegration.ActivityListener, KitIntegration.UserAttributeListener { - override fun getInstance(): AppsFlyerLib = AppsFlyerLib.getInstance() override fun getName() = NAME - public override fun onKitCreate(setting: Map?, context: Context): List { + public override fun onKitCreate( + setting: Map?, + context: Context, + ): List { AppsFlyerLib.getInstance() - .setDebugLog(MParticle.getInstance()?.environment == MParticle.Environment.Development) + .setDebugLog( + MParticle.getInstance()?.environment == MParticle.Environment.Development, + ) settings[DEV_KEY]?.let { AppsFlyerLib.getInstance().init(it, this, context) } val userConsentState = currentUser?.consentState setConsent(userConsentState) @@ -81,9 +85,16 @@ class AppsFlyerKit : override fun leaveBreadcrumb(breadcrumb: String): List = emptyList() - override fun logError(message: String, eventData: Map): List = emptyList() + override fun logError( + message: String, + eventData: Map, + ): List = emptyList() - override fun logException(exception: Exception, eventData: Map, message: String): List = emptyList() + override fun logException( + exception: Exception, + eventData: Map, + message: String, + ): List = emptyList() override fun logLtvIncrease( valueIncreased: BigDecimal, @@ -105,7 +116,10 @@ class AppsFlyerKit : return messages } - private fun logNotSalesEvent(event: CommerceEvent, messages: MutableList) { + private fun logNotSalesEvent( + event: CommerceEvent, + messages: MutableList, + ) { val eventList = CommerceEventUtils.expand(event) if (eventList.isNotEmpty()) { for (e in eventList) { @@ -191,11 +205,12 @@ class AppsFlyerKit : } } - private fun isSalesEvent(event: CommerceEvent) = ( - event.productAction == Product.ADD_TO_CART || - event.productAction == Product.ADD_TO_WISHLIST || - event.productAction == Product.CHECKOUT || - event.productAction == Product.PURCHASE + private fun isSalesEvent(event: CommerceEvent) = + ( + event.productAction == Product.ADD_TO_CART || + event.productAction == Product.ADD_TO_WISHLIST || + event.productAction == Product.CHECKOUT || + event.productAction == Product.PURCHASE ) override fun logEvent(event: MPEvent): List { @@ -209,7 +224,10 @@ class AppsFlyerKit : return messages } - override fun logScreen(screenName: String, eventAttributes: Map): List = emptyList() + override fun logScreen( + screenName: String, + eventAttributes: Map, + ): List = emptyList() override fun setOptOut(optOutStatus: Boolean): List { instance.anonymizeUser(optOutStatus) @@ -226,20 +244,41 @@ class AppsFlyerKit : } override fun setUserAttribute(attributeKey: String, attributeValue: String) {} + override fun setUserAttributeList(s: String, list: List) {} - override fun onIncrementUserAttribute(key: String?, incrementedBy: Number?, value: String?, user: FilteredMParticleUser?) { + + override fun onIncrementUserAttribute( + key: String?, + incrementedBy: Number?, + value: String?, + user: FilteredMParticleUser?, + ) { } - override fun onRemoveUserAttribute(key: String?, user: FilteredMParticleUser?) { + override fun onRemoveUserAttribute( + key: String?, + user: FilteredMParticleUser?, + ) { } - override fun onSetUserAttribute(key: String?, value: Any?, user: FilteredMParticleUser?) { + override fun onSetUserAttribute( + key: String?, + value: Any?, + user: FilteredMParticleUser?, + ) { } - override fun onSetUserTag(key: String?, user: FilteredMParticleUser?) { + override fun onSetUserTag( + key: String?, + user: FilteredMParticleUser?, + ) { } - override fun onSetUserAttributeList(attributeKey: String?, attributeValueList: MutableList?, user: FilteredMParticleUser?) { + override fun onSetUserAttributeList( + attributeKey: String?, + attributeValueList: MutableList?, + user: FilteredMParticleUser?, + ) { } override fun onSetAllUserAttributes( @@ -250,7 +289,12 @@ class AppsFlyerKit : } override fun supportsAttributeLists(): Boolean = true - override fun setAllUserAttributes(map: Map, map1: Map>) {} + + override fun setAllUserAttributes( + map: Map, + map1: Map>, + ) {} + override fun removeUserAttribute(key: String) {} override fun removeUserIdentity(identityType: MParticle.IdentityType) { with(instance) { @@ -262,7 +306,10 @@ class AppsFlyerKit : } } - override fun setUserIdentity(identityType: MParticle.IdentityType, identity: String) { + override fun setUserIdentity( + identityType: MParticle.IdentityType, + identity: String, + ) { with(instance) { if (MParticle.IdentityType.CustomerId == identityType) { setCustomerUserId(identity) @@ -299,7 +346,10 @@ class AppsFlyerKit : return topLevelMap } - private fun searchKeyInNestedMap(map: Map<*, *>, key: Any): Any? { + private fun searchKeyInNestedMap( + map: Map<*, *>, + key: Any, + ): Any? { if (map.isNullOrEmpty()) { return null } @@ -324,7 +374,11 @@ class AppsFlyerKit : return null } - override fun onConsentStateUpdated(consentState: ConsentState, consentState1: ConsentState, filteredMParticleUser: FilteredMParticleUser) { + override fun onConsentStateUpdated( + consentState: ConsentState, + consentState1: ConsentState, + filteredMParticleUser: FilteredMParticleUser, + ) { setConsent(consentState1) } @@ -422,31 +476,35 @@ class AppsFlyerKit : } } - val result = AttributionResult() - .setParameters(jsonResult) - .setServiceProviderId(configuration.kitId) + val result = + AttributionResult() + .setParameters(jsonResult) + .setServiceProviderId(configuration.kitId) kitManager.onResult(result) } override fun onConversionDataFail(conversionFailure: String) { if (!KitUtils.isEmpty(conversionFailure)) { - val error = AttributionError() - .setMessage(conversionFailure) - .setServiceProviderId(configuration.kitId) + val error = + AttributionError() + .setMessage(conversionFailure) + .setServiceProviderId(configuration.kitId) kitManager.onError(error) } } - fun deepLinkListener() = DeepLinkListener { deepLinkResult -> + fun deepLinkListener() = + DeepLinkListener { deepLinkResult -> val deepLinkObj = deepLinkResult.deepLink when (deepLinkResult.status) { DeepLinkResult.Status.FOUND -> { try { deepLinkObj.clickEvent.put(APP_OPEN_ATTRIBUTION_RESULT, true.toString()) - val result = AttributionResult() - .setParameters(deepLinkObj.clickEvent) - .setServiceProviderId(configuration.kitId) + val result = + AttributionResult() + .setParameters(deepLinkObj.clickEvent) + .setServiceProviderId(configuration.kitId) kitManager.onResult(result) } catch (e: Exception) { return@DeepLinkListener @@ -458,9 +516,10 @@ class AppsFlyerKit : else -> { val dlError = deepLinkResult.error if (!KitUtils.isEmpty(dlError.toString())) { - val error = AttributionError() - .setMessage(dlError.toString()) - .setServiceProviderId(configuration.kitId) + val error = + AttributionError() + .setMessage(dlError.toString()) + .setServiceProviderId(configuration.kitId) kitManager.onError(error) } return@DeepLinkListener @@ -487,7 +546,10 @@ class AppsFlyerKit : instance.logLocation(context, location.latitude, location.longitude) } - override fun onActivityCreated(activity: Activity, bundle: Bundle?): List { + override fun onActivityCreated( + activity: Activity, + bundle: Bundle?, + ): List { instance.start(activity) return emptyList() } @@ -500,7 +562,10 @@ class AppsFlyerKit : override fun onActivityStopped(activity: Activity): List = emptyList() - override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle?): List = emptyList() + override fun onActivitySaveInstanceState( + activity: Activity, + bundle: Bundle?, + ): List = emptyList() override fun onActivityDestroyed(activity: Activity): List = emptyList() @@ -521,18 +586,21 @@ class AppsFlyerKit : const val APP_OPEN_ATTRIBUTION_RESULT = "MPARTICLE_APPSFLYER_APP_OPEN_ATTRIBUTION_RESULT" - fun generateProductIdList(event: CommerceEvent?): List? = event?.products?.filter { !KitUtils.isEmpty(it.sku) }?.let { - if (it.isNotEmpty()) { - it.map { it.sku.replace(COMMA, "%2C") } - } else { - null + fun generateProductIdList(event: CommerceEvent?): List? = + event?.products?.filter { !KitUtils.isEmpty(it.sku) }?.let { + if (it.isNotEmpty()) { + it.map { it.sku.replace(COMMA, "%2C") } + } else { + null + } } - } private const val CONSENT_MAPPING = "consentMapping" @Suppress("ktlint:standard:property-naming") - enum class AppsFlyerConsentValues(val consentValue: String) { + enum class AppsFlyerConsentValues( + val consentValue: String, + ) { GRANTED("Granted"), DENIED("Denied"), } diff --git a/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt b/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt index 76ec915..df265ee 100644 --- a/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt +++ b/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt @@ -31,7 +31,6 @@ import java.lang.ref.WeakReference import java.lang.reflect.Method class AppsflyerKitTests { - private var kit = AppsFlyerKit() private var appsflyer = AppsFlyerLib() @@ -48,19 +47,21 @@ class AppsflyerKitTests { kit = AppsFlyerKit() MockitoAnnotations.initMocks(this) MParticle.setInstance(mock(MParticle::class.java)) - Mockito.`when`(MParticle.getInstance()?.Identity()).thenReturn( - mock( - IdentityApi::class.java, - ), - ) - val kitManager = KitManagerImpl( - mock( - Context::class.java, - ), - null, - emptyCoreCallbacks, - mock(MParticleOptions::class.java), - ) + Mockito.`when`(MParticle.getInstance()?.Identity()) + .thenReturn( + mock( + IdentityApi::class.java, + ), + ) + val kitManager = + KitManagerImpl( + mock( + Context::class.java, + ), + null, + emptyCoreCallbacks, + mock(MParticleOptions::class.java), + ) kit.kitManager = kitManager kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("id", "-1")) @@ -115,25 +116,28 @@ class AppsflyerKitTests { .thenReturn(MParticle.Environment.Production) Assert.assertNull(AppsFlyerKit.generateProductIdList(null)) val product = Product.Builder("foo-name", "foo-sku", 50.0).build() - val event = CommerceEvent.Builder(Product.PURCHASE, product) - .transactionAttributes(TransactionAttributes("foo")) - .build() + val event = + CommerceEvent.Builder(Product.PURCHASE, product) + .transactionAttributes(TransactionAttributes("foo")) + .build() assertEquals(mutableListOf("foo-sku"), AppsFlyerKit.generateProductIdList(event)) val product2 = Product.Builder("foo-name-2", "foo-sku-2", 50.0).build() - val event2 = CommerceEvent.Builder(Product.PURCHASE, product) - .addProduct(product2) - .transactionAttributes(TransactionAttributes("foo")) - .build() + val event2 = + CommerceEvent.Builder(Product.PURCHASE, product) + .addProduct(product2) + .transactionAttributes(TransactionAttributes("foo")) + .build() assertEquals( mutableListOf("foo-sku", "foo-sku-2"), AppsFlyerKit.generateProductIdList(event2), ) val product3 = Product.Builder("foo-name-3", "foo-sku-,3", 50.0).build() - val event3 = CommerceEvent.Builder(Product.PURCHASE, product) - .addProduct(product2) - .addProduct(product3) - .transactionAttributes(TransactionAttributes("foo")) - .build() + val event3 = + CommerceEvent.Builder(Product.PURCHASE, product) + .addProduct(product2) + .addProduct(product3) + .transactionAttributes(TransactionAttributes("foo")) + .build() assertEquals( mutableListOf("foo-sku", "foo-sku-2", "foo-sku-%2C3"), AppsFlyerKit.generateProductIdList(event3), @@ -168,16 +172,20 @@ class AppsflyerKitTests { val afConsentResults = appsflyer.getConsentState() val expectedConsentValue = - afConsentResults.getValue("isUserSubjectToGDPR") + afConsentResults + .getValue("isUserSubjectToGDPR") TestCase.assertEquals(false, expectedConsentValue) - val notExpectedConsentKey = afConsentResults.containsKey("hasConsentForDataUsage") + val notExpectedConsentKey = + afConsentResults.containsKey("hasConsentForDataUsage") TestCase.assertEquals(false, notExpectedConsentKey) - val notExpectedConsentKey2 = afConsentResults.containsKey("hasConsentForAdsPersonalization") + val notExpectedConsentKey2 = + afConsentResults.containsKey("hasConsentForAdsPersonalization") TestCase.assertEquals(false, notExpectedConsentKey2) - val notExpectedConsentKey3 = afConsentResults.containsKey("hasConsentForAdStorage") + val notExpectedConsentKey3 = + afConsentResults.containsKey("hasConsentForAdStorage") TestCase.assertEquals(false, notExpectedConsentKey3) } @@ -209,16 +217,20 @@ class AppsflyerKitTests { val afConsentResults = appsflyer.getConsentState() val expectedConsentValue = - afConsentResults.getValue("isUserSubjectToGDPR") + afConsentResults + .getValue("isUserSubjectToGDPR") TestCase.assertEquals(true, expectedConsentValue) - val notExpectedConsentKey = afConsentResults.containsKey("hasConsentForDataUsage") + val notExpectedConsentKey = + afConsentResults.containsKey("hasConsentForDataUsage") TestCase.assertEquals(false, notExpectedConsentKey) - val notExpectedConsentKey2 = afConsentResults.containsKey("hasConsentForAdsPersonalization") + val notExpectedConsentKey2 = + afConsentResults.containsKey("hasConsentForAdsPersonalization") TestCase.assertEquals(false, notExpectedConsentKey2) - val notExpectedConsentKey3 = afConsentResults.containsKey("hasConsentForAdStorage") + val notExpectedConsentKey3 = + afConsentResults.containsKey("hasConsentForAdStorage") TestCase.assertEquals(false, notExpectedConsentKey3) } @@ -250,19 +262,23 @@ class AppsflyerKitTests { val afConsentResults = appsflyer.getConsentState() val expectedConsentValue = - afConsentResults.getValue("isUserSubjectToGDPR") + afConsentResults + .getValue("isUserSubjectToGDPR") TestCase.assertEquals(true, expectedConsentValue) val expectedConsentValue2 = - afConsentResults.getValue("hasConsentForDataUsage") + afConsentResults + .getValue("hasConsentForDataUsage") TestCase.assertEquals(false, expectedConsentValue2) val expectedConsentValue3 = - afConsentResults.getValue("hasConsentForAdsPersonalization") + afConsentResults + .getValue("hasConsentForAdsPersonalization") TestCase.assertEquals(true, expectedConsentValue3) val expectedConsentValue4 = - afConsentResults.getValue("hasConsentForAdStorage") + afConsentResults + .getValue("hasConsentForAdStorage") TestCase.assertEquals(true, expectedConsentValue4) } @@ -306,19 +322,23 @@ class AppsflyerKitTests { val afConsentResults = appsflyer.getConsentState() val expectedConsentValue = - afConsentResults.getValue("isUserSubjectToGDPR") + afConsentResults + .getValue("isUserSubjectToGDPR") TestCase.assertEquals(true, expectedConsentValue) val expectedConsentValue2 = - afConsentResults.getValue("hasConsentForDataUsage") + afConsentResults + .getValue("hasConsentForDataUsage") TestCase.assertEquals(true, expectedConsentValue2) val expectedConsentValue3 = - afConsentResults.getValue("hasConsentForAdsPersonalization") + afConsentResults + .getValue("hasConsentForAdsPersonalization") TestCase.assertEquals(false, expectedConsentValue3) val expectedConsentValue4 = - afConsentResults.getValue("hasConsentForAdStorage") + afConsentResults + .getValue("hasConsentForAdStorage") TestCase.assertEquals(false, expectedConsentValue4) } @@ -357,19 +377,23 @@ class AppsflyerKitTests { val afConsentResults = appsflyer.getConsentState() val expectedConsentValue = - afConsentResults.getValue("isUserSubjectToGDPR") + afConsentResults + .getValue("isUserSubjectToGDPR") TestCase.assertEquals(true, expectedConsentValue) val expectedConsentValue2 = - afConsentResults.getValue("hasConsentForDataUsage") + afConsentResults + .getValue("hasConsentForDataUsage") TestCase.assertEquals(true, expectedConsentValue2) val expectedConsentValue3 = - afConsentResults.getValue("hasConsentForAdsPersonalization") + afConsentResults + .getValue("hasConsentForAdsPersonalization") TestCase.assertEquals(true, expectedConsentValue3) val expectedConsentValue4 = - afConsentResults.getValue("hasConsentForAdStorage") + afConsentResults + .getValue("hasConsentForAdStorage") TestCase.assertEquals(true, expectedConsentValue4) } @@ -404,15 +428,18 @@ class AppsflyerKitTests { kit.onConsentStateUpdated(state, state, filteredMParticleUser) val afConsentResults = appsflyer.getConsentState() val expectedConsentValue = - afConsentResults.getValue("isUserSubjectToGDPR") + afConsentResults + .getValue("isUserSubjectToGDPR") TestCase.assertEquals(true, expectedConsentValue) val expectedConsentValue2 = - afConsentResults.getValue("hasConsentForDataUsage") + afConsentResults + .getValue("hasConsentForDataUsage") TestCase.assertEquals(true, expectedConsentValue2) val expectedConsentValue3 = - afConsentResults.getValue("hasConsentForAdsPersonalization") + afConsentResults + .getValue("hasConsentForAdsPersonalization") TestCase.assertEquals(true, expectedConsentValue3) val notExpectedConsentKey = @@ -478,19 +505,23 @@ class AppsflyerKitTests { val afConsentResults = appsflyer.getConsentState() val expectedConsentValue = - afConsentResults.getValue("isUserSubjectToGDPR") + afConsentResults + .getValue("isUserSubjectToGDPR") TestCase.assertEquals(true, expectedConsentValue) val expectedConsentValue2 = - afConsentResults.getValue("hasConsentForDataUsage") + afConsentResults + .getValue("hasConsentForDataUsage") TestCase.assertEquals(false, expectedConsentValue2) val expectedConsentValue3 = - afConsentResults.getValue("hasConsentForAdsPersonalization") + afConsentResults + .getValue("hasConsentForAdsPersonalization") TestCase.assertEquals(false, expectedConsentValue3) val expectedConsentValue4 = - afConsentResults.getValue("hasConsentForAdStorage") + afConsentResults + .getValue("hasConsentForAdStorage") TestCase.assertEquals(true, expectedConsentValue4) } @@ -527,7 +558,8 @@ class AppsflyerKitTests { TestCase.assertEquals(1, appsflyer.getConsentState().size) val afConsentResults = appsflyer.getConsentState() val expectedConsentValue = - afConsentResults.getValue("isUserSubjectToGDPR") + afConsentResults + .getValue("isUserSubjectToGDPR") TestCase.assertEquals(false, expectedConsentValue) } @@ -536,10 +568,11 @@ class AppsflyerKitTests { var jsonInput = "{'GDPR':{'marketing':'{:false,'timestamp':1711038269644:'Test consent','location':'17 Cherry Tree Lane','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}','performance':'{'consented':true,'timestamp':1711038269644,'document':'parental_consent_agreement_v2','location':'17 Cherry Tree Lan 3','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'},'CCPA':'{'consented':true,'timestamp':1711038269644,'document':'ccpa_consent_agreement_v3','location':'17 Cherry Tree Lane','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'}" - val method: Method = AppsFlyerKit::class.java.getDeclaredMethod( - "parseToNestedMap", - String::class.java, - ) + val method: Method = + AppsFlyerKit::class.java.getDeclaredMethod( + "parseToNestedMap", + String::class.java, + ) method.isAccessible = true val result = method.invoke(kit, jsonInput) Assert.assertEquals(mutableMapOf(), result) @@ -549,10 +582,11 @@ class AppsflyerKitTests { fun testParseToNestedMap_When_JSON_Is_Empty() { var jsonInput = "" - val method: Method = AppsFlyerKit::class.java.getDeclaredMethod( - "parseToNestedMap", - String::class.java, - ) + val method: Method = + AppsFlyerKit::class.java.getDeclaredMethod( + "parseToNestedMap", + String::class.java, + ) method.isAccessible = true val result = method.invoke(kit, jsonInput) Assert.assertEquals(mutableMapOf(), result) @@ -560,20 +594,22 @@ class AppsflyerKitTests { @Test fun testSearchKeyInNestedMap_When_Input_Key_Is_Empty_String() { - val map = mapOf( - "GDPR" to true, - "marketing" to mapOf( - "consented" to false, - "document" to mapOf( - "timestamp" to 1711038269644, + val map = + mapOf( + "GDPR" to true, + "marketing" to mapOf( + "consented" to false, + "document" to mapOf( + "timestamp" to 1711038269644, + ), ), - ), - ) - val method: Method = AppsFlyerKit::class.java.getDeclaredMethod( - "searchKeyInNestedMap", - Map::class.java, - Any::class.java, - ) + ) + val method: Method = + AppsFlyerKit::class.java.getDeclaredMethod( + "searchKeyInNestedMap", + Map::class.java, + Any::class.java, + ) method.isAccessible = true val result = method.invoke(kit, map, "") Assert.assertEquals(null, result) @@ -582,11 +618,12 @@ class AppsflyerKitTests { @Test fun testSearchKeyInNestedMap_When_Input_Is_Empty_Map() { val emptyMap: Map = emptyMap() - val method: Method = AppsFlyerKit::class.java.getDeclaredMethod( - "searchKeyInNestedMap", - Map::class.java, - Any::class.java, - ) + val method: Method = + AppsFlyerKit::class.java.getDeclaredMethod( + "searchKeyInNestedMap", + Map::class.java, + Any::class.java, + ) method.isAccessible = true val result = method.invoke(kit, emptyMap, "1") Assert.assertEquals(null, result) @@ -595,10 +632,11 @@ class AppsflyerKitTests { @Test fun testParseConsentMapping_When_Input_Is_Empty_Json() { val emptyJson = "" - val method: Method = AppsFlyerKit::class.java.getDeclaredMethod( - "parseConsentMapping", - String::class.java, - ) + val method: Method = + AppsFlyerKit::class.java.getDeclaredMethod( + "parseConsentMapping", + String::class.java, + ) method.isAccessible = true val result = method.invoke(kit, emptyJson) Assert.assertEquals(emptyMap(), result) @@ -608,10 +646,11 @@ class AppsflyerKitTests { fun testParseConsentMapping_When_Input_Is_Invalid_Json() { var jsonInput = "{'GDPR':{'marketing':'{:false,'timestamp':1711038269644:'Test consent','location':'17 Cherry Tree Lane','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}','performance':'{'consented':true,'timestamp':1711038269644,'document':'parental_consent_agreement_v2','location':'17 Cherry Tree Lan 3','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'},'CCPA':'{'consented':true,'timestamp':1711038269644,'document':'ccpa_consent_agreement_v3','location':'17 Cherry Tree Lane','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'}" - val method: Method = AppsFlyerKit::class.java.getDeclaredMethod( - "parseConsentMapping", - String::class.java, - ) + val method: Method = + AppsFlyerKit::class.java.getDeclaredMethod( + "parseConsentMapping", + String::class.java, + ) method.isAccessible = true val result = method.invoke(kit, jsonInput) Assert.assertEquals(emptyMap(), result) @@ -619,10 +658,11 @@ class AppsflyerKitTests { @Test fun testParseConsentMapping_When_Input_Is_NULL() { - val method: Method = AppsFlyerKit::class.java.getDeclaredMethod( - "parseConsentMapping", - String::class.java, - ) + val method: Method = + AppsFlyerKit::class.java.getDeclaredMethod( + "parseConsentMapping", + String::class.java, + ) method.isAccessible = true val result = method.invoke(kit, null) Assert.assertEquals(emptyMap(), result) From 8ec5671f8aa756bb753ba75779a60dd5fdc877e5 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 16 Jan 2026 16:56:45 -0500 Subject: [PATCH 4/6] Fix lint issue --- .../kotlin/com/mparticle/kits/AppsFlyerKit.kt | 117 +++++------------- 1 file changed, 28 insertions(+), 89 deletions(-) diff --git a/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt b/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt index f234f5b..09b8e43 100644 --- a/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt +++ b/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt @@ -52,10 +52,7 @@ class AppsFlyerKit : override fun getName() = NAME - public override fun onKitCreate( - setting: Map?, - context: Context, - ): List { + public override fun onKitCreate(setting: Map?, context: Context): List { AppsFlyerLib.getInstance() .setDebugLog( MParticle.getInstance()?.environment == MParticle.Environment.Development, @@ -85,16 +82,9 @@ class AppsFlyerKit : override fun leaveBreadcrumb(breadcrumb: String): List = emptyList() - override fun logError( - message: String, - eventData: Map, - ): List = emptyList() + override fun logError(message: String, eventData: Map): List = emptyList() - override fun logException( - exception: Exception, - eventData: Map, - message: String, - ): List = emptyList() + override fun logException(exception: Exception, eventData: Map, message: String): List = emptyList() override fun logLtvIncrease( valueIncreased: BigDecimal, @@ -116,10 +106,7 @@ class AppsFlyerKit : return messages } - private fun logNotSalesEvent( - event: CommerceEvent, - messages: MutableList, - ) { + private fun logNotSalesEvent(event: CommerceEvent, messages: MutableList) { val eventList = CommerceEventUtils.expand(event) if (eventList.isNotEmpty()) { for (e in eventList) { @@ -205,13 +192,10 @@ class AppsFlyerKit : } } - private fun isSalesEvent(event: CommerceEvent) = - ( - event.productAction == Product.ADD_TO_CART || - event.productAction == Product.ADD_TO_WISHLIST || - event.productAction == Product.CHECKOUT || - event.productAction == Product.PURCHASE - ) + private fun isSalesEvent(event: CommerceEvent) = event.productAction == Product.ADD_TO_CART || + event.productAction == Product.ADD_TO_WISHLIST || + event.productAction == Product.CHECKOUT || + event.productAction == Product.PURCHASE override fun logEvent(event: MPEvent): List { var hashMap: HashMap? = hashMapOf() @@ -224,10 +208,7 @@ class AppsFlyerKit : return messages } - override fun logScreen( - screenName: String, - eventAttributes: Map, - ): List = emptyList() + override fun logScreen(screenName: String, eventAttributes: Map): List = emptyList() override fun setOptOut(optOutStatus: Boolean): List { instance.anonymizeUser(optOutStatus) @@ -247,38 +228,19 @@ class AppsFlyerKit : override fun setUserAttributeList(s: String, list: List) {} - override fun onIncrementUserAttribute( - key: String?, - incrementedBy: Number?, - value: String?, - user: FilteredMParticleUser?, - ) { + override fun onIncrementUserAttribute(key: String?, incrementedBy: Number?, value: String?, user: FilteredMParticleUser?) { } - override fun onRemoveUserAttribute( - key: String?, - user: FilteredMParticleUser?, - ) { + override fun onRemoveUserAttribute(key: String?, user: FilteredMParticleUser?) { } - override fun onSetUserAttribute( - key: String?, - value: Any?, - user: FilteredMParticleUser?, - ) { + override fun onSetUserAttribute(key: String?, value: Any?, user: FilteredMParticleUser?) { } - override fun onSetUserTag( - key: String?, - user: FilteredMParticleUser?, - ) { + override fun onSetUserTag(key: String?, user: FilteredMParticleUser?) { } - override fun onSetUserAttributeList( - attributeKey: String?, - attributeValueList: MutableList?, - user: FilteredMParticleUser?, - ) { + override fun onSetUserAttributeList(attributeKey: String?, attributeValueList: MutableList?, user: FilteredMParticleUser?) { } override fun onSetAllUserAttributes( @@ -290,10 +252,7 @@ class AppsFlyerKit : override fun supportsAttributeLists(): Boolean = true - override fun setAllUserAttributes( - map: Map, - map1: Map>, - ) {} + override fun setAllUserAttributes(map: Map, map1: Map>) {} override fun removeUserAttribute(key: String) {} override fun removeUserIdentity(identityType: MParticle.IdentityType) { @@ -306,10 +265,7 @@ class AppsFlyerKit : } } - override fun setUserIdentity( - identityType: MParticle.IdentityType, - identity: String, - ) { + override fun setUserIdentity(identityType: MParticle.IdentityType, identity: String) { with(instance) { if (MParticle.IdentityType.CustomerId == identityType) { setCustomerUserId(identity) @@ -346,10 +302,7 @@ class AppsFlyerKit : return topLevelMap } - private fun searchKeyInNestedMap( - map: Map<*, *>, - key: Any, - ): Any? { + private fun searchKeyInNestedMap(map: Map<*, *>, key: Any): Any? { if (map.isNullOrEmpty()) { return null } @@ -374,11 +327,7 @@ class AppsFlyerKit : return null } - override fun onConsentStateUpdated( - consentState: ConsentState, - consentState1: ConsentState, - filteredMParticleUser: FilteredMParticleUser, - ) { + override fun onConsentStateUpdated(consentState: ConsentState, consentState1: ConsentState, filteredMParticleUser: FilteredMParticleUser) { setConsent(consentState1) } @@ -493,8 +442,7 @@ class AppsFlyerKit : } } - fun deepLinkListener() = - DeepLinkListener { deepLinkResult -> + fun deepLinkListener() = DeepLinkListener { deepLinkResult -> val deepLinkObj = deepLinkResult.deepLink when (deepLinkResult.status) { @@ -546,10 +494,7 @@ class AppsFlyerKit : instance.logLocation(context, location.latitude, location.longitude) } - override fun onActivityCreated( - activity: Activity, - bundle: Bundle?, - ): List { + override fun onActivityCreated(activity: Activity, bundle: Bundle?): List { instance.start(activity) return emptyList() } @@ -562,10 +507,7 @@ class AppsFlyerKit : override fun onActivityStopped(activity: Activity): List = emptyList() - override fun onActivitySaveInstanceState( - activity: Activity, - bundle: Bundle?, - ): List = emptyList() + override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle?): List = emptyList() override fun onActivityDestroyed(activity: Activity): List = emptyList() @@ -586,21 +528,18 @@ class AppsFlyerKit : const val APP_OPEN_ATTRIBUTION_RESULT = "MPARTICLE_APPSFLYER_APP_OPEN_ATTRIBUTION_RESULT" - fun generateProductIdList(event: CommerceEvent?): List? = - event?.products?.filter { !KitUtils.isEmpty(it.sku) }?.let { - if (it.isNotEmpty()) { - it.map { it.sku.replace(COMMA, "%2C") } - } else { - null - } + fun generateProductIdList(event: CommerceEvent?): List? = event?.products?.filter { !KitUtils.isEmpty(it.sku) }?.let { + if (it.isNotEmpty()) { + it.map { it.sku.replace(COMMA, "%2C") } + } else { + null } + } private const val CONSENT_MAPPING = "consentMapping" @Suppress("ktlint:standard:property-naming") - enum class AppsFlyerConsentValues( - val consentValue: String, - ) { + enum class AppsFlyerConsentValues(val consentValue: String) { GRANTED("Granted"), DENIED("Denied"), } From 672fe6f6fec9c6dba4da213ecda7acc573a77bdf Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Tue, 20 Jan 2026 15:12:10 -0500 Subject: [PATCH 5/6] Fix Lint error --- build.gradle | 4 + .../kotlin/com/mparticle/kits/AppsFlyerKit.kt | 181 +++++--- .../com/mparticle/kits/AppsflyerKitTests.kt | 402 +++++++++++------- 3 files changed, 368 insertions(+), 219 deletions(-) diff --git a/build.gradle b/build.gradle index b8a0efc..3a55604 100644 --- a/build.gradle +++ b/build.gradle @@ -61,6 +61,10 @@ android { } } +ktlint { + android.set(true) +} + dependencies { api 'com.appsflyer:af-android-sdk:6.17.3' testImplementation files('libs/java-json.jar') diff --git a/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt b/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt index 09b8e43..e49bba7 100644 --- a/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt +++ b/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt @@ -52,8 +52,12 @@ class AppsFlyerKit : override fun getName() = NAME - public override fun onKitCreate(setting: Map?, context: Context): List { - AppsFlyerLib.getInstance() + public override fun onKitCreate( + setting: Map?, + context: Context, + ): List { + AppsFlyerLib + .getInstance() .setDebugLog( MParticle.getInstance()?.environment == MParticle.Environment.Development, ) @@ -82,9 +86,16 @@ class AppsFlyerKit : override fun leaveBreadcrumb(breadcrumb: String): List = emptyList() - override fun logError(message: String, eventData: Map): List = emptyList() + override fun logError( + message: String, + eventData: Map, + ): List = emptyList() - override fun logException(exception: Exception, eventData: Map, message: String): List = emptyList() + override fun logException( + exception: Exception, + eventData: Map, + message: String, + ): List = emptyList() override fun logLtvIncrease( valueIncreased: BigDecimal, @@ -106,7 +117,10 @@ class AppsFlyerKit : return messages } - private fun logNotSalesEvent(event: CommerceEvent, messages: MutableList) { + private fun logNotSalesEvent( + event: CommerceEvent, + messages: MutableList, + ) { val eventList = CommerceEventUtils.expand(event) if (eventList.isNotEmpty()) { for (e in eventList) { @@ -192,10 +206,11 @@ class AppsFlyerKit : } } - private fun isSalesEvent(event: CommerceEvent) = event.productAction == Product.ADD_TO_CART || - event.productAction == Product.ADD_TO_WISHLIST || - event.productAction == Product.CHECKOUT || - event.productAction == Product.PURCHASE + private fun isSalesEvent(event: CommerceEvent) = + event.productAction == Product.ADD_TO_CART || + event.productAction == Product.ADD_TO_WISHLIST || + event.productAction == Product.CHECKOUT || + event.productAction == Product.PURCHASE override fun logEvent(event: MPEvent): List { var hashMap: HashMap? = hashMapOf() @@ -208,7 +223,10 @@ class AppsFlyerKit : return messages } - override fun logScreen(screenName: String, eventAttributes: Map): List = emptyList() + override fun logScreen( + screenName: String, + eventAttributes: Map, + ): List = emptyList() override fun setOptOut(optOutStatus: Boolean): List { instance.anonymizeUser(optOutStatus) @@ -224,23 +242,48 @@ class AppsFlyerKit : return messageList } - override fun setUserAttribute(attributeKey: String, attributeValue: String) {} + override fun setUserAttribute( + attributeKey: String, + attributeValue: String, + ) {} - override fun setUserAttributeList(s: String, list: List) {} + override fun setUserAttributeList( + s: String, + list: List, + ) {} - override fun onIncrementUserAttribute(key: String?, incrementedBy: Number?, value: String?, user: FilteredMParticleUser?) { + override fun onIncrementUserAttribute( + key: String?, + incrementedBy: Number?, + value: String?, + user: FilteredMParticleUser?, + ) { } - override fun onRemoveUserAttribute(key: String?, user: FilteredMParticleUser?) { + override fun onRemoveUserAttribute( + key: String?, + user: FilteredMParticleUser?, + ) { } - override fun onSetUserAttribute(key: String?, value: Any?, user: FilteredMParticleUser?) { + override fun onSetUserAttribute( + key: String?, + value: Any?, + user: FilteredMParticleUser?, + ) { } - override fun onSetUserTag(key: String?, user: FilteredMParticleUser?) { + override fun onSetUserTag( + key: String?, + user: FilteredMParticleUser?, + ) { } - override fun onSetUserAttributeList(attributeKey: String?, attributeValueList: MutableList?, user: FilteredMParticleUser?) { + override fun onSetUserAttributeList( + attributeKey: String?, + attributeValueList: MutableList?, + user: FilteredMParticleUser?, + ) { } override fun onSetAllUserAttributes( @@ -252,9 +295,13 @@ class AppsFlyerKit : override fun supportsAttributeLists(): Boolean = true - override fun setAllUserAttributes(map: Map, map1: Map>) {} + override fun setAllUserAttributes( + map: Map, + map1: Map>, + ) {} override fun removeUserAttribute(key: String) {} + override fun removeUserIdentity(identityType: MParticle.IdentityType) { with(instance) { if (MParticle.IdentityType.CustomerId == identityType) { @@ -265,7 +312,10 @@ class AppsFlyerKit : } } - override fun setUserIdentity(identityType: MParticle.IdentityType, identity: String) { + override fun setUserIdentity( + identityType: MParticle.IdentityType, + identity: String, + ) { with(instance) { if (MParticle.IdentityType.CustomerId == identityType) { setCustomerUserId(identity) @@ -302,7 +352,10 @@ class AppsFlyerKit : return topLevelMap } - private fun searchKeyInNestedMap(map: Map<*, *>, key: Any): Any? { + private fun searchKeyInNestedMap( + map: Map<*, *>, + key: Any, + ): Any? { if (map.isNullOrEmpty()) { return null } @@ -327,7 +380,11 @@ class AppsFlyerKit : return null } - override fun onConsentStateUpdated(consentState: ConsentState, consentState1: ConsentState, filteredMParticleUser: FilteredMParticleUser) { + override fun onConsentStateUpdated( + consentState: ConsentState, + consentState1: ConsentState, + filteredMParticleUser: FilteredMParticleUser, + ) { setConsent(consentState1) } @@ -442,38 +499,39 @@ class AppsFlyerKit : } } - fun deepLinkListener() = DeepLinkListener { deepLinkResult -> - val deepLinkObj = deepLinkResult.deepLink - - when (deepLinkResult.status) { - DeepLinkResult.Status.FOUND -> { - try { - deepLinkObj.clickEvent.put(APP_OPEN_ATTRIBUTION_RESULT, true.toString()) - val result = - AttributionResult() - .setParameters(deepLinkObj.clickEvent) - .setServiceProviderId(configuration.kitId) - kitManager.onResult(result) - } catch (e: Exception) { + fun deepLinkListener() = + DeepLinkListener { deepLinkResult -> + val deepLinkObj = deepLinkResult.deepLink + + when (deepLinkResult.status) { + DeepLinkResult.Status.FOUND -> { + try { + deepLinkObj.clickEvent.put(APP_OPEN_ATTRIBUTION_RESULT, true.toString()) + val result = + AttributionResult() + .setParameters(deepLinkObj.clickEvent) + .setServiceProviderId(configuration.kitId) + kitManager.onResult(result) + } catch (e: Exception) { + return@DeepLinkListener + } + } + DeepLinkResult.Status.NOT_FOUND -> { return@DeepLinkListener } - } - DeepLinkResult.Status.NOT_FOUND -> { - return@DeepLinkListener - } - else -> { - val dlError = deepLinkResult.error - if (!KitUtils.isEmpty(dlError.toString())) { - val error = - AttributionError() - .setMessage(dlError.toString()) - .setServiceProviderId(configuration.kitId) - kitManager.onError(error) + else -> { + val dlError = deepLinkResult.error + if (!KitUtils.isEmpty(dlError.toString())) { + val error = + AttributionError() + .setMessage(dlError.toString()) + .setServiceProviderId(configuration.kitId) + kitManager.onError(error) + } + return@DeepLinkListener } - return@DeepLinkListener } } - } override fun onAppOpenAttribution(attributionDataN: MutableMap?) { // do nothing, Appsflyer new UDL implementation will use new deep linking method with both @@ -494,7 +552,10 @@ class AppsFlyerKit : instance.logLocation(context, location.latitude, location.longitude) } - override fun onActivityCreated(activity: Activity, bundle: Bundle?): List { + override fun onActivityCreated( + activity: Activity, + bundle: Bundle?, + ): List { instance.start(activity) return emptyList() } @@ -507,7 +568,10 @@ class AppsFlyerKit : override fun onActivityStopped(activity: Activity): List = emptyList() - override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle?): List = emptyList() + override fun onActivitySaveInstanceState( + activity: Activity, + bundle: Bundle?, + ): List = emptyList() override fun onActivityDestroyed(activity: Activity): List = emptyList() @@ -528,18 +592,21 @@ class AppsFlyerKit : const val APP_OPEN_ATTRIBUTION_RESULT = "MPARTICLE_APPSFLYER_APP_OPEN_ATTRIBUTION_RESULT" - fun generateProductIdList(event: CommerceEvent?): List? = event?.products?.filter { !KitUtils.isEmpty(it.sku) }?.let { - if (it.isNotEmpty()) { - it.map { it.sku.replace(COMMA, "%2C") } - } else { - null + fun generateProductIdList(event: CommerceEvent?): List? = + event?.products?.filter { !KitUtils.isEmpty(it.sku) }?.let { + if (it.isNotEmpty()) { + it.map { it.sku.replace(COMMA, "%2C") } + } else { + null + } } - } private const val CONSENT_MAPPING = "consentMapping" @Suppress("ktlint:standard:property-naming") - enum class AppsFlyerConsentValues(val consentValue: String) { + enum class AppsFlyerConsentValues( + val consentValue: String, + ) { GRANTED("Granted"), DENIED("Denied"), } diff --git a/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt b/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt index df265ee..6c7201f 100644 --- a/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt +++ b/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt @@ -47,7 +47,8 @@ class AppsflyerKitTests { kit = AppsFlyerKit() MockitoAnnotations.initMocks(this) MParticle.setInstance(mock(MParticle::class.java)) - Mockito.`when`(MParticle.getInstance()?.Identity()) + Mockito + .`when`(MParticle.getInstance()?.Identity()) .thenReturn( mock( IdentityApi::class.java, @@ -112,18 +113,21 @@ class AppsflyerKitTests { @Throws(Exception::class) fun testGenerateSkuString() { MParticle.setInstance(mock(MParticle::class.java)) - Mockito.`when`(MParticle.getInstance()?.environment) + Mockito + .`when`(MParticle.getInstance()?.environment) .thenReturn(MParticle.Environment.Production) Assert.assertNull(AppsFlyerKit.generateProductIdList(null)) val product = Product.Builder("foo-name", "foo-sku", 50.0).build() val event = - CommerceEvent.Builder(Product.PURCHASE, product) + CommerceEvent + .Builder(Product.PURCHASE, product) .transactionAttributes(TransactionAttributes("foo")) .build() assertEquals(mutableListOf("foo-sku"), AppsFlyerKit.generateProductIdList(event)) val product2 = Product.Builder("foo-name-2", "foo-sku-2", 50.0).build() val event2 = - CommerceEvent.Builder(Product.PURCHASE, product) + CommerceEvent + .Builder(Product.PURCHASE, product) .addProduct(product2) .transactionAttributes(TransactionAttributes("foo")) .build() @@ -133,7 +137,8 @@ class AppsflyerKitTests { ) val product3 = Product.Builder("foo-name-3", "foo-sku-,3", 50.0).build() val event3 = - CommerceEvent.Builder(Product.PURCHASE, product) + CommerceEvent + .Builder(Product.PURCHASE, product) .addProduct(product2) .addProduct(product3) .transactionAttributes(TransactionAttributes("foo")) @@ -158,14 +163,18 @@ class AppsflyerKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) - val marketingConsent = GDPRConsent.builder(false) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - val state = ConsentState.builder() - .addGDPRConsentState("Marketing", marketingConsent) - .build() + val marketingConsent = + GDPRConsent + .builder(false) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + val state = + ConsentState + .builder() + .addGDPRConsentState("Marketing", marketingConsent) + .build() filteredMParticleUser = FilteredMParticleUser.getInstance(user, kit) kit.onConsentStateUpdated(state, state, filteredMParticleUser) @@ -203,14 +212,18 @@ class AppsflyerKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) - val marketingConsent = GDPRConsent.builder(false) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - val state = ConsentState.builder() - .addGDPRConsentState("test1", marketingConsent) - .build() + val marketingConsent = + GDPRConsent + .builder(false) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + val state = + ConsentState + .builder() + .addGDPRConsentState("test1", marketingConsent) + .build() filteredMParticleUser = FilteredMParticleUser.getInstance(user, kit) kit.onConsentStateUpdated(state, state, filteredMParticleUser) @@ -248,14 +261,18 @@ class AppsflyerKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) - val marketingConsent = GDPRConsent.builder(false) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - val state = ConsentState.builder() - .addGDPRConsentState("test1", marketingConsent) - .build() + val marketingConsent = + GDPRConsent + .builder(false) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + val state = + ConsentState + .builder() + .addGDPRConsentState("test1", marketingConsent) + .build() filteredMParticleUser = FilteredMParticleUser.getInstance(user, kit) kit.onConsentStateUpdated(state, state, filteredMParticleUser) @@ -296,26 +313,34 @@ class AppsflyerKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) - val performanceConsent = GDPRConsent.builder(true) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - val marketingConsent = GDPRConsent.builder(false) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - val testConsent = GDPRConsent.builder(false) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - val state = ConsentState.builder() - .addGDPRConsentState("Performance", performanceConsent) - .addGDPRConsentState("Marketing", marketingConsent) - .addGDPRConsentState("testconsent", testConsent) - .build() + val performanceConsent = + GDPRConsent + .builder(true) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + val marketingConsent = + GDPRConsent + .builder(false) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + val testConsent = + GDPRConsent + .builder(false) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + val state = + ConsentState + .builder() + .addGDPRConsentState("Performance", performanceConsent) + .addGDPRConsentState("Marketing", marketingConsent) + .addGDPRConsentState("testconsent", testConsent) + .build() filteredMParticleUser = FilteredMParticleUser.getInstance(user, kit) kit.onConsentStateUpdated(state, state, filteredMParticleUser) @@ -355,22 +380,28 @@ class AppsflyerKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) - val performanceConsent = GDPRConsent.builder(true) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - - val marketingConsent = GDPRConsent.builder(true) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - - val state = ConsentState.builder() - .addGDPRConsentState("Performance", performanceConsent) - .addGDPRConsentState("Marketing", marketingConsent) - .build() + val performanceConsent = + GDPRConsent + .builder(true) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + + val marketingConsent = + GDPRConsent + .builder(true) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + + val state = + ConsentState + .builder() + .addGDPRConsentState("Performance", performanceConsent) + .addGDPRConsentState("Marketing", marketingConsent) + .build() filteredMParticleUser = FilteredMParticleUser.getInstance(user, kit) kit.onConsentStateUpdated(state, state, filteredMParticleUser) @@ -407,22 +438,28 @@ class AppsflyerKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) - val marketingConsent = GDPRConsent.builder(true) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - - val performanceConsent = GDPRConsent.builder(true) - .document("parental_consent_agreement_v2") - .location("17 Cherry Tree Lan 3") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - - val state = ConsentState.builder() - .addGDPRConsentState("Marketing", marketingConsent) - .addGDPRConsentState("Performance", performanceConsent) - .build() + val marketingConsent = + GDPRConsent + .builder(true) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + + val performanceConsent = + GDPRConsent + .builder(true) + .document("parental_consent_agreement_v2") + .location("17 Cherry Tree Lan 3") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + + val state = + ConsentState + .builder() + .addGDPRConsentState("Marketing", marketingConsent) + .addGDPRConsentState("Performance", performanceConsent) + .build() filteredMParticleUser = FilteredMParticleUser.getInstance(user, kit) kit.onConsentStateUpdated(state, state, filteredMParticleUser) @@ -449,22 +486,28 @@ class AppsflyerKitTests { @Test fun onConsentStateUpdatedTest_When_No_DATA_From_Server() { - val marketingConsent = GDPRConsent.builder(true) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - - val performanceConsent = GDPRConsent.builder(true) - .document("parental_consent_agreement_v2") - .location("17 Cherry Tree Lan 3") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - - val state = ConsentState.builder() - .addGDPRConsentState("Marketing", marketingConsent) - .addGDPRConsentState("Performance", performanceConsent) - .build() + val marketingConsent = + GDPRConsent + .builder(true) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + + val performanceConsent = + GDPRConsent + .builder(true) + .document("parental_consent_agreement_v2") + .location("17 Cherry Tree Lan 3") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + + val state = + ConsentState + .builder() + .addGDPRConsentState("Marketing", marketingConsent) + .addGDPRConsentState("Performance", performanceConsent) + .build() filteredMParticleUser = FilteredMParticleUser.getInstance(user, kit) kit.onConsentStateUpdated(state, state, filteredMParticleUser) @@ -483,22 +526,28 @@ class AppsflyerKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) - val marketingConsent = GDPRConsent.builder(true) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - - val performanceConsent = GDPRConsent.builder(true) - .document("parental_consent_agreement_v2") - .location("17 Cherry Tree Lan 3") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - - val state = ConsentState.builder() - .addGDPRConsentState("Marketing", marketingConsent) - .addGDPRConsentState("Performance", performanceConsent) - .build() + val marketingConsent = + GDPRConsent + .builder(true) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + + val performanceConsent = + GDPRConsent + .builder(true) + .document("parental_consent_agreement_v2") + .location("17 Cherry Tree Lan 3") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + + val state = + ConsentState + .builder() + .addGDPRConsentState("Marketing", marketingConsent) + .addGDPRConsentState("Performance", performanceConsent) + .build() filteredMParticleUser = FilteredMParticleUser.getInstance(user, kit) kit.onConsentStateUpdated(state, state, filteredMParticleUser) @@ -536,21 +585,27 @@ class AppsflyerKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) - val marketingConsent = GDPRConsent.builder(true) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - - val performanceConsent = GDPRConsent.builder(true) - .document("parental_consent_agreement_v2") - .location("17 Cherry Tree Lan 3") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - val state = ConsentState.builder() - .addGDPRConsentState("Marketing", marketingConsent) - .addGDPRConsentState("Performance", performanceConsent) - .build() + val marketingConsent = + GDPRConsent + .builder(true) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + + val performanceConsent = + GDPRConsent + .builder(true) + .document("parental_consent_agreement_v2") + .location("17 Cherry Tree Lan 3") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + val state = + ConsentState + .builder() + .addGDPRConsentState("Marketing", marketingConsent) + .addGDPRConsentState("Performance", performanceConsent) + .build() filteredMParticleUser = FilteredMParticleUser.getInstance(user, kit) kit.onConsentStateUpdated(state, state, filteredMParticleUser) @@ -597,12 +652,14 @@ class AppsflyerKitTests { val map = mapOf( "GDPR" to true, - "marketing" to mapOf( - "consented" to false, - "document" to mapOf( - "timestamp" to 1711038269644, + "marketing" to + mapOf( + "consented" to false, + "document" to + mapOf( + "timestamp" to 1711038269644, + ), ), - ), ) val method: Method = AppsFlyerKit::class.java.getDeclaredMethod( @@ -668,47 +725,68 @@ class AppsflyerKitTests { Assert.assertEquals(emptyMap(), result) } - private var emptyCoreCallbacks: CoreCallbacks = object : CoreCallbacks { - var activity = Activity() - override fun isBackgrounded(): Boolean = false + private var emptyCoreCallbacks: CoreCallbacks = + object : CoreCallbacks { + var activity = Activity() - override fun getUserBucket(): Int = 0 + override fun isBackgrounded(): Boolean = false - override fun isEnabled(): Boolean = false + override fun getUserBucket(): Int = 0 - override fun setIntegrationAttributes(i: Int, map: Map) {} + override fun isEnabled(): Boolean = false - override fun getIntegrationAttributes(i: Int): Map? = null + override fun setIntegrationAttributes( + i: Int, + map: Map, + ) {} - override fun getCurrentActivity(): WeakReference = WeakReference(activity) + override fun getIntegrationAttributes(i: Int): Map? = null - override fun getLatestKitConfiguration(): JSONArray? = null + override fun getCurrentActivity(): WeakReference = WeakReference(activity) - override fun getDataplanOptions(): MParticleOptions.DataplanOptions? = null + override fun getLatestKitConfiguration(): JSONArray? = null - override fun isPushEnabled(): Boolean = false + override fun getDataplanOptions(): MParticleOptions.DataplanOptions? = null - override fun getPushSenderId(): String? = null + override fun isPushEnabled(): Boolean = false - override fun getPushInstanceId(): String? = null + override fun getPushSenderId(): String? = null - override fun getLaunchUri(): Uri? = null + override fun getPushInstanceId(): String? = null - override fun getLaunchAction(): String? = null + override fun getLaunchUri(): Uri? = null - override fun getKitListener(): KitListener = object : KitListener { - override fun kitFound(kitId: Int) {} - override fun kitConfigReceived(kitId: Int, configuration: String?) {} - override fun kitExcluded(kitId: Int, reason: String?) {} - override fun kitStarted(kitId: Int) {} - override fun onKitApiCalled(kitId: Int, used: Boolean?, vararg objects: Any?) {} - override fun onKitApiCalled( - methodName: String?, - kitId: Int, - used: Boolean?, - vararg objects: Any?, - ) { - } + override fun getLaunchAction(): String? = null + + override fun getKitListener(): KitListener = + object : KitListener { + override fun kitFound(kitId: Int) {} + + override fun kitConfigReceived( + kitId: Int, + configuration: String?, + ) {} + + override fun kitExcluded( + kitId: Int, + reason: String?, + ) {} + + override fun kitStarted(kitId: Int) {} + + override fun onKitApiCalled( + kitId: Int, + used: Boolean?, + vararg objects: Any?, + ) {} + + override fun onKitApiCalled( + methodName: String?, + kitId: Int, + used: Boolean?, + vararg objects: Any?, + ) { + } + } } - } } From d910e38ff97b343507a15a99a4480240601c4894 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Tue, 20 Jan 2026 15:24:30 -0500 Subject: [PATCH 6/6] Fix Unit test case --- build.gradle | 6 ------ 1 file changed, 6 deletions(-) diff --git a/build.gradle b/build.gradle index 3a55604..4829dd8 100644 --- a/build.gradle +++ b/build.gradle @@ -48,12 +48,6 @@ android { kotlinOptions { jvmTarget = '17' } - lint { - abortOnError = false - checkReleaseBuilds = false - ignoreWarnings = true - baseline = file("lint-baseline.xml") - } testOptions { unitTests.all { jvmArgs += ['--add-opens', 'java.base/java.lang=ALL-UNNAMED']