From 13bee875b493ac09b97fdbc0f14c849a2166dc24 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Mon, 24 Nov 2025 10:59:11 -0500 Subject: [PATCH 1/2] feat: Update Android Gradle plugin to 8.0.2 --- build.gradle | 28 ++++++++++++++++++++---- gradle/wrapper/gradle-wrapper.properties | 2 +- src/main/AndroidManifest.xml | 3 +-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 692d8e3..6698f05 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 = '+' } @@ -9,8 +9,9 @@ buildscript { 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:$kotlin_version" } @@ -18,7 +19,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,8 +31,27 @@ 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.skyhook' + 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 { api fileTree(dir: 'libs', include: ['*.jar']) 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 c858ebc..67cbf76 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - - + From 94cf7a3178c24b01a781127bca475033f1f77e06 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Tue, 20 Jan 2026 13:53:34 -0500 Subject: [PATCH 2/2] Fix Lint error --- build.gradle | 3 + .../com/mparticle/kits/SkyhookBootReceiver.kt | 25 ++++-- .../mparticle/kits/SkyhookIntentService.kt | 17 ++-- .../kotlin/com/mparticle/kits/SkyhookKit.kt | 83 +++++++++++-------- .../kotlin/com/mparticle/kits/SkyhookLog.kt | 3 +- .../com/mparticle/kits/SkyhookPreferences.kt | 14 ++-- .../com/mparticle/kits/SkyhookKitTests.kt | 2 +- 7 files changed, 88 insertions(+), 59 deletions(-) diff --git a/build.gradle b/build.gradle index 6698f05..b94bdaa 100644 --- a/build.gradle +++ b/build.gradle @@ -36,6 +36,9 @@ apply plugin: 'com.mparticle.kit' android { namespace 'com.mparticle.kits.skyhook' + buildFeatures { + buildConfig = true + } defaultConfig { minSdkVersion 21 } diff --git a/src/main/kotlin/com/mparticle/kits/SkyhookBootReceiver.kt b/src/main/kotlin/com/mparticle/kits/SkyhookBootReceiver.kt index 2ad3aa8..9c99144 100644 --- a/src/main/kotlin/com/mparticle/kits/SkyhookBootReceiver.kt +++ b/src/main/kotlin/com/mparticle/kits/SkyhookBootReceiver.kt @@ -7,12 +7,20 @@ import android.content.Intent import com.mparticle.kits.SkyhookLog.e import com.mparticle.kits.SkyhookLog.i import com.skyhookwireless.accelerator.AcceleratorClient -import com.skyhookwireless.accelerator.AcceleratorClient.* +import com.skyhookwireless.accelerator.AcceleratorClient.ConnectionCallbacks +import com.skyhookwireless.accelerator.AcceleratorClient.OnConnectionFailedListener +import com.skyhookwireless.accelerator.AcceleratorClient.OnRegisterForCampaignMonitoringResultListener import com.skyhookwireless.accelerator.AcceleratorStatusCodes -class SkyhookBootReceiver : BroadcastReceiver(), ConnectionCallbacks, OnConnectionFailedListener, +class SkyhookBootReceiver : + BroadcastReceiver(), + ConnectionCallbacks, + OnConnectionFailedListener, OnRegisterForCampaignMonitoringResultListener { - override fun onReceive(context: Context, intent: Intent) { + override fun onReceive( + context: Context, + intent: Intent, + ) { val apiKey = SkyhookPreferences(context).apiKey if (apiKey == null || apiKey == "") { e("not resuming monitoring after reboot") @@ -26,14 +34,14 @@ class SkyhookBootReceiver : BroadcastReceiver(), ConnectionCallbacks, OnConnecti context, 0, serviceIntent, - PendingIntent.FLAG_MUTABLE + PendingIntent.FLAG_MUTABLE, ) } else { PendingIntent.getService( context, 0, serviceIntent, - PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_UPDATE_CURRENT, ) } i("resuming monitoring after reboot") @@ -42,11 +50,14 @@ class SkyhookBootReceiver : BroadcastReceiver(), ConnectionCallbacks, OnConnecti } override fun onConnected() {} + override fun onDisconnected() {} + override fun onConnectionFailed(errorCode: Int) {} + override fun onRegisterForCampaignMonitoringResult( statusCode: Int, - pendingIntent: PendingIntent + pendingIntent: PendingIntent, ) { if (statusCode == AcceleratorStatusCodes.SUCCESS) { i("resumed monitoring after reboot") @@ -54,4 +65,4 @@ class SkyhookBootReceiver : BroadcastReceiver(), ConnectionCallbacks, OnConnecti e("failed to resume monitoring after reboot: $statusCode") } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/mparticle/kits/SkyhookIntentService.kt b/src/main/kotlin/com/mparticle/kits/SkyhookIntentService.kt index 1e335c4..e7d1a59 100644 --- a/src/main/kotlin/com/mparticle/kits/SkyhookIntentService.kt +++ b/src/main/kotlin/com/mparticle/kits/SkyhookIntentService.kt @@ -1,21 +1,22 @@ package com.mparticle.kits -import com.mparticle.kits.SkyhookLog.i -import com.mparticle.kits.SkyhookLog.e import android.app.IntentService import android.content.Intent -import com.skyhookwireless.accelerator.CampaignVenue -import com.skyhookwireless.accelerator.AcceleratorClient import com.mparticle.kits.SkyhookLog +import com.mparticle.kits.SkyhookLog.e +import com.mparticle.kits.SkyhookLog.i +import com.skyhookwireless.accelerator.AcceleratorClient +import com.skyhookwireless.accelerator.CampaignVenue class SkyhookIntentService : IntentService("com.mparticle.kits.SkyhookIntentService") { override fun onHandleIntent(intent: Intent?) { val campaignVenue = AcceleratorClient.getTriggeringCampaignVenue(intent) if (campaignVenue != null) { when (AcceleratorClient.getCampaignVenueTransition(intent)) { - CampaignVenue.CAMPAIGN_VENUE_TRANSITION_ENTER -> i( - "entered: $campaignVenue" - ) + CampaignVenue.CAMPAIGN_VENUE_TRANSITION_ENTER -> + i( + "entered: $campaignVenue", + ) CampaignVenue.CAMPAIGN_VENUE_TRANSITION_EXIT -> i("exited: $campaignVenue") else -> e("unknown trigger type: $campaignVenue") } @@ -25,4 +26,4 @@ class SkyhookIntentService : IntentService("com.mparticle.kits.SkyhookIntentServ e("unknown intent type: $intent") } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/mparticle/kits/SkyhookKit.kt b/src/main/kotlin/com/mparticle/kits/SkyhookKit.kt index bb13281..6c30a09 100644 --- a/src/main/kotlin/com/mparticle/kits/SkyhookKit.kt +++ b/src/main/kotlin/com/mparticle/kits/SkyhookKit.kt @@ -9,29 +9,38 @@ import android.os.Bundle import com.mparticle.internal.MPUtility import com.mparticle.kits.KitIntegration.ActivityListener import com.skyhookwireless.accelerator.AcceleratorClient -import com.skyhookwireless.accelerator.AcceleratorClient.* +import com.skyhookwireless.accelerator.AcceleratorClient.ConnectionCallbacks +import com.skyhookwireless.accelerator.AcceleratorClient.OnConnectionFailedListener +import com.skyhookwireless.accelerator.AcceleratorClient.OnRegisterForCampaignMonitoringResultListener +import com.skyhookwireless.accelerator.AcceleratorClient.OnStartCampaignMonitoringResultListener +import com.skyhookwireless.accelerator.AcceleratorClient.OnStopCampaignMonitoringResultListener import com.skyhookwireless.accelerator.AcceleratorStatusCodes -class SkyhookKit : KitIntegration(), ActivityListener, ConnectionCallbacks, - OnConnectionFailedListener, OnRegisterForCampaignMonitoringResultListener, - OnStartCampaignMonitoringResultListener, OnStopCampaignMonitoringResultListener { - private var _client: AcceleratorClient? = null - private var _isInitialized = false - private var _isRegistered = false - private var _preferences: SkyhookPreferences? = null +class SkyhookKit : + KitIntegration(), + ActivityListener, + ConnectionCallbacks, + OnConnectionFailedListener, + OnRegisterForCampaignMonitoringResultListener, + OnStartCampaignMonitoringResultListener, + OnStopCampaignMonitoringResultListener { + private var client: AcceleratorClient? = null + private var isInitialized = false + private var isRegistered = false + private var preferences: SkyhookPreferences? = null override fun getName(): String = KIT_NAME override fun onKitCreate( settings: Map, - context: Context + context: Context, ): List { SkyhookLog.d(ON_KIT_CREATE) val apiKey = settings[API_KEY] - _preferences = SkyhookPreferences(context) - _preferences?.apiKey = apiKey - _client = AcceleratorClient(context, apiKey, this, this) - SkyhookLog.i(ACCELERATOR_SDK_VERSION + _client?.version) + preferences = SkyhookPreferences(context) + preferences?.apiKey = apiKey + client = AcceleratorClient(context, apiKey, this, this) + SkyhookLog.i(ACCELERATOR_SDK_VERSION + client?.version) initialize() return emptyList() } @@ -39,14 +48,14 @@ class SkyhookKit : KitIntegration(), ActivityListener, ConnectionCallbacks, override fun onKitDestroy() { SkyhookLog.d(ON_KIT_DESTROY_MESSAGE) shutdown() - _preferences?.clearApiKey() + preferences?.clearApiKey() SkyhookLog.d(DESTROYED_MESSAGE) } override fun onSettingsUpdated(settings: Map) { SkyhookLog.d(ON_SETTINGS_UPDATED_MESSAGE) val newApiKey = settings[API_KEY] - when (_preferences?.apiKey) { + when (preferences?.apiKey) { null -> { SkyhookLog.i(NOT_RUNNING_MESSAGE) } @@ -56,7 +65,7 @@ class SkyhookKit : KitIntegration(), ActivityListener, ConnectionCallbacks, else -> { SkyhookLog.i(SHUTTING_DOWN_CHANGED_KEY_MESSAGE) shutdown() - _preferences!!.clearApiKey() + preferences!!.clearApiKey() } } } @@ -65,7 +74,7 @@ class SkyhookKit : KitIntegration(), ActivityListener, ConnectionCallbacks, override fun onConnected() { SkyhookLog.d(CONNECTED_MESSAGE) - _client?.registerForCampaignMonitoring(getServiceIntent(context), this) + client?.registerForCampaignMonitoring(getServiceIntent(context), this) } override fun onDisconnected() { @@ -78,11 +87,11 @@ class SkyhookKit : KitIntegration(), ActivityListener, ConnectionCallbacks, override fun onRegisterForCampaignMonitoringResult( statusCode: Int, - pendingIntent: PendingIntent + pendingIntent: PendingIntent, ) { if (statusCode == AcceleratorStatusCodes.SUCCESS) { - _isRegistered = true - _client?.startMonitoringForAllCampaigns(this) + isRegistered = true + client?.startMonitoringForAllCampaigns(this) } else { SkyhookLog.e("failed to register: $statusCode") } @@ -90,7 +99,7 @@ class SkyhookKit : KitIntegration(), ActivityListener, ConnectionCallbacks, override fun onStartCampaignMonitoringResult( statusCode: Int, - campaignName: String + campaignName: String, ) { if (statusCode == AcceleratorStatusCodes.SUCCESS) { SkyhookLog.i("monitoring started") @@ -101,7 +110,7 @@ class SkyhookKit : KitIntegration(), ActivityListener, ConnectionCallbacks, override fun onStopCampaignMonitoringResult( statusCode: Int, - campaignName: String + campaignName: String, ) { if (statusCode == AcceleratorStatusCodes.SUCCESS) { SkyhookLog.i("monitoring stopped") @@ -110,8 +119,10 @@ class SkyhookKit : KitIntegration(), ActivityListener, ConnectionCallbacks, } } - 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() @@ -133,39 +144,39 @@ class SkyhookKit : KitIntegration(), ActivityListener, ConnectionCallbacks, override fun onActivitySaveInstanceState( activity: Activity, - bundle: Bundle? + bundle: Bundle?, ): List = emptyList() override fun onActivityDestroyed(activity: Activity): List = emptyList() private fun initialize() { - if (_client == null || _isInitialized) { + if (client == null || isInitialized) { return } if (MPUtility.checkPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)) { SkyhookLog.i(LOCATION_PERMISSION_GRANTED_MESSAGE) - _client?.connect() - _isInitialized = true + client?.connect() + isInitialized = true } else { SkyhookLog.i(LOCATION_PERMISSION_NOT_GRANTED_MESSAGE) } } private fun shutdown() { - _client?.let { _client -> - if (_client.isConnected) { + client?.let { client -> + if (client.isConnected) { return - } else if (_isRegistered) { - _client.stopMonitoringForAllCampaigns(this) + } else if (isRegistered) { + client.stopMonitoringForAllCampaigns(this) } - _client.disconnect() + client.disconnect() } ?: return } companion object { private const val API_KEY = "apiKey" private const val KIT_NAME = "Skyhook" - private const val NOT_RUNNING_MESSAGE ="not running" + private const val NOT_RUNNING_MESSAGE = "not running" private const val ON_KIT_CREATE = "onKitCreate" private const val ACCELERATOR_SDK_VERSION = "Accelerator SDK v" private const val ON_KIT_DESTROY_MESSAGE = "onKitDestroy" @@ -187,14 +198,14 @@ class SkyhookKit : KitIntegration(), ActivityListener, ConnectionCallbacks, context, 0, serviceIntent, - PendingIntent.FLAG_MUTABLE + PendingIntent.FLAG_MUTABLE, ) } else { PendingIntent.getService( context, 0, serviceIntent, - PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_UPDATE_CURRENT, ) } return pendingIntent diff --git a/src/main/kotlin/com/mparticle/kits/SkyhookLog.kt b/src/main/kotlin/com/mparticle/kits/SkyhookLog.kt index 06cfbde..82ac195 100644 --- a/src/main/kotlin/com/mparticle/kits/SkyhookLog.kt +++ b/src/main/kotlin/com/mparticle/kits/SkyhookLog.kt @@ -5,6 +5,7 @@ import com.mparticle.MParticle internal object SkyhookLog { private const val TAG = "mParticle Skyhook Kit" + fun d(msg: String) { if (isEnabled) { Log.d(TAG, msg) @@ -26,5 +27,5 @@ internal object SkyhookLog { } private val isEnabled: Boolean - get() = MParticle.getInstance()!!.environment == MParticle.Environment.Development + get() = MParticle.getInstance()!!.environment == MParticle.Environment.Development } diff --git a/src/main/kotlin/com/mparticle/kits/SkyhookPreferences.kt b/src/main/kotlin/com/mparticle/kits/SkyhookPreferences.kt index e51683e..94c9409 100644 --- a/src/main/kotlin/com/mparticle/kits/SkyhookPreferences.kt +++ b/src/main/kotlin/com/mparticle/kits/SkyhookPreferences.kt @@ -5,16 +5,18 @@ import android.content.SharedPreferences import com.mparticle.MParticle // Needed to store the API key for the boot receiver -internal class SkyhookPreferences(context: Context) { - private val _prefs: SharedPreferences +internal class SkyhookPreferences( + context: Context, +) { + private val prefs: SharedPreferences var apiKey: String? - get() = _prefs.getString(PREFERENCE_API_KEY, null) + get() = prefs.getString(PREFERENCE_API_KEY, null) set(apiKey) { - _prefs.edit().putString(PREFERENCE_API_KEY, apiKey).apply() + prefs.edit().putString(PREFERENCE_API_KEY, apiKey).apply() } fun clearApiKey() { - _prefs.edit().remove(PREFERENCE_API_KEY).apply() + prefs.edit().remove(PREFERENCE_API_KEY).apply() } companion object { @@ -23,6 +25,6 @@ internal class SkyhookPreferences(context: Context) { } init { - _prefs = context.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE) + prefs = context.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE) } } diff --git a/src/test/kotlin/com/mparticle/kits/SkyhookKitTests.kt b/src/test/kotlin/com/mparticle/kits/SkyhookKitTests.kt index c2ec2b8..e3469fb 100644 --- a/src/test/kotlin/com/mparticle/kits/SkyhookKitTests.kt +++ b/src/test/kotlin/com/mparticle/kits/SkyhookKitTests.kt @@ -8,7 +8,7 @@ import org.mockito.Mockito class SkyhookKitTests { private val kit: KitIntegration - get() = SkyhookKit() + get() = SkyhookKit() @Test @Throws(Exception::class)