From bbf3205c9669a69500d3aa622eed4c3643ece8b7 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 21 Nov 2025 17:36:55 -0500 Subject: [PATCH 1/2] feat: Update Android Gradle plugin to 8.0.2 --- build.gradle | 24 ++++++++++++++++++++---- gradle/wrapper/gradle-wrapper.properties | 2 +- src/main/AndroidManifest.xml | 3 +-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index c1618af..87473d9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,22 +1,25 @@ buildscript { + ext.kotlin_version = '2.0.20' if (!project.hasProperty('version') || project.version.equals('unspecified') || project.version.toString().contains('beta')) { project.version = '+' } + repositories { google() mavenLocal() 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:1.8.10" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } 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 { @@ -28,13 +31,26 @@ 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.iterable' defaultConfig { minSdkVersion 21 } + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + kotlinOptions { + jvmTarget = '17' + } + testOptions { + unitTests.all { + jvmArgs += ['--add-opens', 'java.base/java.lang=ALL-UNNAMED'] + } + } } dependencies { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae04661..e1bef7e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +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 bbf471f..e3ecde4 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - Date: Mon, 19 Jan 2026 18:02:57 -0500 Subject: [PATCH 2/2] Fix lint error --- build.gradle | 3 + .../mparticle/kits/IterableDeviceIdHelper.kt | 26 ++-- .../kotlin/com/mparticle/kits/IterableKit.kt | 113 ++++++++++-------- .../com/mparticle/kits/iterable/Future.kt | 11 +- .../com/mparticle/kits/IterableKitTests.kt | 2 +- 5 files changed, 91 insertions(+), 64 deletions(-) diff --git a/build.gradle b/build.gradle index 87473d9..0b2da89 100644 --- a/build.gradle +++ b/build.gradle @@ -36,6 +36,9 @@ apply plugin: 'com.mparticle.kit' android { namespace 'com.mparticle.kits.iterable' + buildFeatures { + buildConfig = true + } defaultConfig { minSdkVersion 21 } diff --git a/src/main/kotlin/com/mparticle/kits/IterableDeviceIdHelper.kt b/src/main/kotlin/com/mparticle/kits/IterableDeviceIdHelper.kt index 18ca39d..9eadf0c 100644 --- a/src/main/kotlin/com/mparticle/kits/IterableDeviceIdHelper.kt +++ b/src/main/kotlin/com/mparticle/kits/IterableDeviceIdHelper.kt @@ -7,18 +7,22 @@ internal object IterableDeviceIdHelper { @WorkerThread fun getGoogleAdId(context: Context?): String? { try { - val advertisingIdClient = Class - .forName("com.google.android.gms.ads.identifier.AdvertisingIdClient") - val getAdvertisingInfo = advertisingIdClient.getMethod( - "getAdvertisingIdInfo", - Context::class.java - ) + val advertisingIdClient = + Class + .forName("com.google.android.gms.ads.identifier.AdvertisingIdClient") + val getAdvertisingInfo = + advertisingIdClient.getMethod( + "getAdvertisingIdInfo", + Context::class.java, + ) val advertisingInfo = getAdvertisingInfo.invoke(null, context) - val isLimitAdTrackingEnabled = advertisingInfo.javaClass.getMethod( - "isLimitAdTrackingEnabled" - ) - val limitAdTrackingEnabled = isLimitAdTrackingEnabled - .invoke(advertisingInfo) as Boolean + val isLimitAdTrackingEnabled = + advertisingInfo.javaClass.getMethod( + "isLimitAdTrackingEnabled", + ) + val limitAdTrackingEnabled = + isLimitAdTrackingEnabled + .invoke(advertisingInfo) as Boolean val getId = advertisingInfo.javaClass.getMethod("getId") val advertisingId = getId.invoke(advertisingInfo) as String if (!limitAdTrackingEnabled) { diff --git a/src/main/kotlin/com/mparticle/kits/IterableKit.kt b/src/main/kotlin/com/mparticle/kits/IterableKit.kt index 5f0b890..693f202 100644 --- a/src/main/kotlin/com/mparticle/kits/IterableKit.kt +++ b/src/main/kotlin/com/mparticle/kits/IterableKit.kt @@ -23,21 +23,26 @@ import com.mparticle.kits.KitIntegration.IdentityListener import com.mparticle.kits.KitIntegration.PushListener import com.mparticle.kits.iterable.Future -class IterableKit : KitIntegration(), ActivityListener, ApplicationStateListener, IdentityListener, +class IterableKit : + KitIntegration(), + ActivityListener, + ApplicationStateListener, + IdentityListener, PushListener { private val previousLinks: MutableSet = HashSet() private var mpidEnabled = false override fun onKitCreate( settings: Map, - context: Context + context: Context, ): List { checkForAttribution() val userIdField = settings[SETTING_USER_ID_FIELD] mpidEnabled = userIdField != null && userIdField == IDENTITY_MPID - val configBuilder = IterableConfigHelper.createConfigBuilderFromIterableConfig( - customConfig - ) + val configBuilder = + IterableConfigHelper.createConfigBuilderFromIterableConfig( + customConfig, + ) settings[SETTING_GCM_INTEGRATION_NAME]?.let { configBuilder.setPushIntegrationName(it) } settings[SETTING_API_KEY]?.let { IterableApi.initialize(context, it, configBuilder.build()) @@ -50,7 +55,6 @@ class IterableKit : KitIntegration(), ActivityListener, ApplicationStateListener override fun setOptOut(optedOut: Boolean): List = emptyList() - private fun initIntegrationAttributes() { val integrationAttributes = HashMap() integrationAttributes[INTEGRATION_ATTRIBUTE_SDK_VERSION] = @@ -67,21 +71,24 @@ class IterableKit : KitIntegration(), ActivityListener, ApplicationStateListener if (!currentLink.isNullOrEmpty() && !previousLinks.contains(currentLink) ) { previousLinks.add(currentLink) - val clickCallback = IterableActionHandler { result -> - if (!KitUtils.isEmpty(result)) { - val attributionResult = AttributionResult().setLink(result) - attributionResult.serviceProviderId = configuration.kitId - kitManager.onResult(attributionResult) + val clickCallback = + IterableActionHandler { result -> + if (!KitUtils.isEmpty(result)) { + val attributionResult = AttributionResult().setLink(result) + attributionResult.serviceProviderId = configuration.kitId + kitManager.onResult(attributionResult) + } } - } IterableApi.getInstance().getAndTrackDeepLink(currentLink, clickCallback) } } } } - override fun onActivityCreated(activity: Activity, bundle: Bundle?): List = - emptyList() + override fun onActivityCreated( + activity: Activity, + bundle: Bundle?, + ): List = emptyList() override fun onActivityStarted(activity: Activity): List = emptyList() @@ -93,42 +100,41 @@ class IterableKit : KitIntegration(), ActivityListener, ApplicationStateListener override fun onActivitySaveInstanceState( activity: Activity, - bundle: Bundle? + bundle: Bundle?, ): List = emptyList() - override fun onActivityDestroyed(activity: Activity): List = emptyList() - override fun onApplicationForeground() { checkForAttribution() } override fun onApplicationBackground() {} + override fun onIdentifyCompleted( mParticleUser: MParticleUser, - filteredIdentityApiRequest: FilteredIdentityApiRequest + filteredIdentityApiRequest: FilteredIdentityApiRequest, ) { updateIdentity(mParticleUser) } override fun onLoginCompleted( mParticleUser: MParticleUser, - filteredIdentityApiRequest: FilteredIdentityApiRequest + filteredIdentityApiRequest: FilteredIdentityApiRequest, ) { updateIdentity(mParticleUser) } override fun onLogoutCompleted( mParticleUser: MParticleUser, - filteredIdentityApiRequest: FilteredIdentityApiRequest + filteredIdentityApiRequest: FilteredIdentityApiRequest, ) { updateIdentity(mParticleUser) } override fun onModifyCompleted( mParticleUser: MParticleUser, - filteredIdentityApiRequest: FilteredIdentityApiRequest + filteredIdentityApiRequest: FilteredIdentityApiRequest, ) { } @@ -136,12 +142,10 @@ class IterableKit : KitIntegration(), ActivityListener, ApplicationStateListener updateIdentity(mParticleUser) } - private fun isEmpty(string: String?): Boolean { - return string == null || "" == string - } + private fun isEmpty(string: String?): Boolean = string == null || "" == string - private fun getUserId(mParticleUser: MParticleUser): Future { - return Future.runAsync { + private fun getUserId(mParticleUser: MParticleUser): Future = + Future.runAsync { var id: String? = null if (mpidEnabled) { if (mParticleUser.id != 0L) { @@ -162,11 +166,13 @@ class IterableKit : KitIntegration(), ActivityListener, ApplicationStateListener } id } - } private fun String?.getPlaceholderEmail(): String? = this?.let { "$it@placeholder.email" } - private fun handleOnSuccess(userId: String?, mParticleUser: MParticleUser) { + private fun handleOnSuccess( + userId: String?, + mParticleUser: MParticleUser, + ) { if (prefersUserId) { IterableApi.getInstance().setUserId(userId) } else { @@ -174,11 +180,14 @@ class IterableKit : KitIntegration(), ActivityListener, ApplicationStateListener val mpEmail = userIdentities[IdentityType.Email] val placeholderEmail = userId.getPlaceholderEmail() - val email = if (!mpEmail.isNullOrEmpty()) { - mpEmail - } else if (!isEmpty(placeholderEmail)) { - placeholderEmail - } else null + val email = + if (!mpEmail.isNullOrEmpty()) { + mpEmail + } else if (!isEmpty(placeholderEmail)) { + placeholderEmail + } else { + null + } IterableApi.getInstance().setEmail(email) } @@ -187,16 +196,21 @@ class IterableKit : KitIntegration(), ActivityListener, ApplicationStateListener private fun updateIdentity(mParticleUser: MParticleUser) { val userId = getUserId(mParticleUser) - userId.onSuccess(object : Future.SuccessCallback { - override fun onSuccess(userId: String?) { - handleOnSuccess(userId, mParticleUser) - return - } - }).onFailure(object : Future.FailureCallback { - override fun onFailure(throwable: Throwable?) { - Log.e(ITERABLE_KIT_ERROR_TAG, ITERABLE_KIT_ERROR_MESSAGE, throwable) - } - }) + userId + .onSuccess( + object : Future.SuccessCallback { + override fun onSuccess(userId: String?) { + handleOnSuccess(userId, mParticleUser) + return + } + }, + ).onFailure( + object : Future.FailureCallback { + override fun onFailure(throwable: Throwable?) { + Log.e(ITERABLE_KIT_ERROR_TAG, ITERABLE_KIT_ERROR_MESSAGE, throwable) + } + }, + ) } override fun willHandlePushMessage(intent: Intent): Boolean { @@ -204,14 +218,20 @@ class IterableKit : KitIntegration(), ActivityListener, ApplicationStateListener return extras != null && extras.containsKey(IterableConstants.ITERABLE_DATA_KEY) } - override fun onPushMessageReceived(context: Context, intent: Intent) { + override fun onPushMessageReceived( + context: Context, + intent: Intent, + ) { IterableFirebaseMessagingService.handleMessageReceived( context, - RemoteMessage(intent.extras) + RemoteMessage(intent.extras), ) } - override fun onPushRegistration(instanceId: String, senderId: String): Boolean { + override fun onPushRegistration( + instanceId: String, + senderId: String, + ): Boolean { IterableApi.getInstance().registerForPush() return true } @@ -230,7 +250,6 @@ class IterableKit : KitIntegration(), ActivityListener, ApplicationStateListener private const val ITERABLE_KIT_ERROR_TAG = "IterableKit" private const val ITERABLE_KIT_ERROR_MESSAGE = "Error while getting the placeholder email" - /** * Set a custom config to be used when initializing Iterable SDK * @param config `IterableConfig` instance with configuration data for Iterable SDK diff --git a/src/main/kotlin/com/mparticle/kits/iterable/Future.kt b/src/main/kotlin/com/mparticle/kits/iterable/Future.kt index 4611039..8c533e4 100644 --- a/src/main/kotlin/com/mparticle/kits/iterable/Future.kt +++ b/src/main/kotlin/com/mparticle/kits/iterable/Future.kt @@ -5,10 +5,13 @@ import android.os.Looper import java.util.concurrent.Callable import java.util.concurrent.Executors -class Future private constructor(callable: Callable) { +class Future private constructor( + callable: Callable, +) { private lateinit var callbackHandler: Handler private val successCallbacks: MutableList> = ArrayList() private val failureCallbacks: MutableList = ArrayList() + private fun handleSuccess(result: T) { callbackHandler.post { var callbacks: List> @@ -49,9 +52,8 @@ class Future private constructor(callable: Callable) { companion object { private val EXECUTOR = Executors.newCachedThreadPool() - fun runAsync(callable: Callable): Future { - return Future(callable) - } + + fun runAsync(callable: Callable): Future = Future(callable) } init { @@ -67,7 +69,6 @@ class Future private constructor(callable: Callable) { handleFailure(e) } } ?: { looper = Looper.getMainLooper() } - } } } diff --git a/src/test/kotlin/com/mparticle/kits/IterableKitTests.kt b/src/test/kotlin/com/mparticle/kits/IterableKitTests.kt index d168a7a..ed49eca 100644 --- a/src/test/kotlin/com/mparticle/kits/IterableKitTests.kt +++ b/src/test/kotlin/com/mparticle/kits/IterableKitTests.kt @@ -7,7 +7,7 @@ import org.mockito.Mockito class IterableKitTests { private val kit: KitIntegration - get() = IterableKit() + get() = IterableKit() @Test @Throws(Exception::class)