From 339f5b0eb2f8dd1077255bf4b78382db3481b5f8 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey <64667840+1abhishekpandey@users.noreply.github.com> Date: Fri, 19 Jul 2024 23:06:57 +0530 Subject: [PATCH 1/6] fix: use custom getter for all fields in Storage --- .../android/storage/AndroidStorageImpl.kt | 65 ++++++++++++------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/android/src/main/java/com/rudderstack/android/storage/AndroidStorageImpl.kt b/android/src/main/java/com/rudderstack/android/storage/AndroidStorageImpl.kt index 1043dedb..231a9f42 100644 --- a/android/src/main/java/com/rudderstack/android/storage/AndroidStorageImpl.kt +++ b/android/src/main/java/com/rudderstack/android/storage/AndroidStorageImpl.kt @@ -298,30 +298,51 @@ class AndroidStorageImpl( } } - override val startupQueue: List = startupQ - override val optOutTime: Long = _optOutTime.get() - override val optInTime: Long = _optInTime.get() - override val anonymousId: String = rudderPrefsRepo.getString(RUDDER_ANONYMOUS_ID_KEY) - override val userId: String = rudderPrefsRepo.getString(RUDDER_USER_ID_KEY) - override val sessionId: Long = rudderPrefsRepo.getLong(RUDDER_SESSION_ID_KEY) - override val lastActiveTimestamp: Long = rudderPrefsRepo.getLong(RUDDER_SESSION_LAST_ACTIVE_TIMESTAMP_KEY) - override val advertisingId: String = rudderPrefsRepo.getString(RUDDER_ADVERTISING_ID_KEY) - override val trackAutoSession: Boolean = rudderPrefsRepo.getBoolean(RUDDER_TRACK_AUTO_SESSION_KEY) - override val build: Int = rudderPrefsRepo.getInt(RUDDER_APPLICATION_BUILD_KEY) - override val versionName: String = rudderPrefsRepo.getString(RUDDER_APPLICATION_VERSION_KEY) - override val isOptedOut: Boolean = rudderPrefsRepo.getBoolean(RUDDER_OPT_STATUS_KEY) - - override val v1AnonymousId: String = oldRudderPrefs.getString(RUDDER_ANONYMOUS_ID_KEY) - override val v1SessionId: Long = oldRudderPrefs.getLong(RUDDER_SESSION_ID_KEY) - override val v1LastActiveTimestamp: Long = oldRudderPrefs.getLong(RUDDER_SESSION_LAST_ACTIVE_TIMESTAMP_KEY) - override val v1AdvertisingId: String = oldRudderPrefs.getString(RUDDER_ADVERTISING_ID_KEY) - override val v1Build: Int = oldRudderPrefs.getInt(RUDDER_APPLICATION_BUILD_KEY) - override val v1VersionName: String = oldRudderPrefs.getString(RUDDER_APPLICATION_VERSION_KEY) - override val v1OptOut: Boolean = oldRudderPrefs.getBoolean(RUDDER_OPT_STATUS_KEY) - override val v1Traits: Map? = oldRudderPrefs.getString(RUDDER_TRAITS_KEY).let { + override val startupQueue: List + get() = startupQ + override val optOutTime: Long + get() = _optOutTime.get() + override val optInTime: Long + get() = _optInTime.get() + override val anonymousId: String + get() = rudderPrefsRepo.getString(RUDDER_ANONYMOUS_ID_KEY) + override val userId: String + get() = rudderPrefsRepo.getString(RUDDER_USER_ID_KEY) + override val sessionId: Long + get() = rudderPrefsRepo.getLong(RUDDER_SESSION_ID_KEY) + override val lastActiveTimestamp: Long + get() = rudderPrefsRepo.getLong(RUDDER_SESSION_LAST_ACTIVE_TIMESTAMP_KEY) + override val advertisingId: String + get() = rudderPrefsRepo.getString(RUDDER_ADVERTISING_ID_KEY) + override val trackAutoSession: Boolean + get() = rudderPrefsRepo.getBoolean(RUDDER_TRACK_AUTO_SESSION_KEY) + override val build: Int + get() = rudderPrefsRepo.getInt(RUDDER_APPLICATION_BUILD_KEY) + override val versionName: String + get() = rudderPrefsRepo.getString(RUDDER_APPLICATION_VERSION_KEY) + override val isOptedOut: Boolean + get() = rudderPrefsRepo.getBoolean(RUDDER_OPT_STATUS_KEY) + + override val v1AnonymousId: String + get() = oldRudderPrefs.getString(RUDDER_ANONYMOUS_ID_KEY) + override val v1SessionId: Long + get() = oldRudderPrefs.getLong(RUDDER_SESSION_ID_KEY) + override val v1LastActiveTimestamp: Long + get() = oldRudderPrefs.getLong(RUDDER_SESSION_LAST_ACTIVE_TIMESTAMP_KEY) + override val v1AdvertisingId: String + get() = oldRudderPrefs.getString(RUDDER_ADVERTISING_ID_KEY) + override val v1Build: Int + get() = oldRudderPrefs.getInt(RUDDER_APPLICATION_BUILD_KEY) + override val v1VersionName: String + get() = oldRudderPrefs.getString(RUDDER_APPLICATION_VERSION_KEY) + override val v1OptOut: Boolean + get() = oldRudderPrefs.getBoolean(RUDDER_OPT_STATUS_KEY) + override val v1Traits: Map? + get() = oldRudderPrefs.getString(RUDDER_TRAITS_KEY).let { jsonAdapter?.readJson(it, object : RudderTypeAdapter>() {}) } - override val v1ExternalIds: List>? = oldRudderPrefs.getString(RUDDER_EXTERNAL_ID_KEY).let { + override val v1ExternalIds: List>? + get() = oldRudderPrefs.getString(RUDDER_EXTERNAL_ID_KEY).let { jsonAdapter?.readJson(it, object : RudderTypeAdapter>>() {}) } From 1cb20579e113e0e035eee4093cd5bf9124155051 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey <64667840+1abhishekpandey@users.noreply.github.com> Date: Fri, 19 Jul 2024 23:07:33 +0530 Subject: [PATCH 2/6] fix: correct the logic to set the previousVersionName --- .../internal/infrastructure/AppInstallUpdateTrackerPlugin.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/android/src/main/java/com/rudderstack/android/internal/infrastructure/AppInstallUpdateTrackerPlugin.kt b/android/src/main/java/com/rudderstack/android/internal/infrastructure/AppInstallUpdateTrackerPlugin.kt index df047afd..197511ce 100644 --- a/android/src/main/java/com/rudderstack/android/internal/infrastructure/AppInstallUpdateTrackerPlugin.kt +++ b/android/src/main/java/com/rudderstack/android/internal/infrastructure/AppInstallUpdateTrackerPlugin.kt @@ -53,9 +53,7 @@ class AppInstallUpdateTrackerPlugin : Plugin { } else { DEFAULT_BUILD } - val previousVersionName: String = if (analytics.androidStorage.versionName.isEmpty()) { - analytics.androidStorage.versionName - } else { + val previousVersionName: String = analytics.androidStorage.versionName.ifEmpty { DEFAULT_VERSION_NAME } var currentBuild: Int? = null From 077df39fe1f7e03ca0189febdd4fcb7a00047065 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey <64667840+1abhishekpandey@users.noreply.github.com> Date: Fri, 19 Jul 2024 23:08:26 +0530 Subject: [PATCH 3/6] fix: import the `utilities.empty` in SharedPrefsStore --- .../com/rudderstack/android/internal/prefs/SharedPrefsStore.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/java/com/rudderstack/android/internal/prefs/SharedPrefsStore.kt b/android/src/main/java/com/rudderstack/android/internal/prefs/SharedPrefsStore.kt index 88d8ebfe..4282dd9c 100644 --- a/android/src/main/java/com/rudderstack/android/internal/prefs/SharedPrefsStore.kt +++ b/android/src/main/java/com/rudderstack/android/internal/prefs/SharedPrefsStore.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.SharedPreferences import android.os.Build import androidx.core.content.edit +import com.rudderstack.android.utilities.empty import java.io.File class SharedPrefsStore( From eaf82d5a7d7c0efad4731b315d8c396871071444 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey <64667840+1abhishekpandey@users.noreply.github.com> Date: Fri, 19 Jul 2024 23:09:02 +0530 Subject: [PATCH 4/6] chore: remove redundant field in LifecycleObserverPlugin --- .../android/internal/infrastructure/LifecycleObserverPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/com/rudderstack/android/internal/infrastructure/LifecycleObserverPlugin.kt b/android/src/main/java/com/rudderstack/android/internal/infrastructure/LifecycleObserverPlugin.kt index 7e75e6d2..cf1d5341 100644 --- a/android/src/main/java/com/rudderstack/android/internal/infrastructure/LifecycleObserverPlugin.kt +++ b/android/src/main/java/com/rudderstack/android/internal/infrastructure/LifecycleObserverPlugin.kt @@ -59,7 +59,7 @@ internal class LifecycleObserverPlugin( _isFirstLaunch.getAndSet(false).also { isFirstLaunch -> add("from_background" to !isFirstLaunch) }.takeIf { it }?.let { - add("version" to (analytics.androidStorage.versionName ?: "")) + add("version" to (analytics.androidStorage.versionName)) } } } From a2ef853c82cf73078bc1c36bca777e11686c6c06 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey <64667840+1abhishekpandey@users.noreply.github.com> Date: Fri, 19 Jul 2024 23:09:58 +0530 Subject: [PATCH 5/6] fix: pass userId as null if it's empty It is needed, otherwise userId will be sent in the payload even if it is not set. --- .../rudderstack/android/internal/plugins/FillDefaultsPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/com/rudderstack/android/internal/plugins/FillDefaultsPlugin.kt b/android/src/main/java/com/rudderstack/android/internal/plugins/FillDefaultsPlugin.kt index 64675cdb..56793406 100644 --- a/android/src/main/java/com/rudderstack/android/internal/plugins/FillDefaultsPlugin.kt +++ b/android/src/main/java/com/rudderstack/android/internal/plugins/FillDefaultsPlugin.kt @@ -61,7 +61,7 @@ internal class FillDefaultsPlugin : Plugin { return (this.copy( context = newContext, anonymousId = anonId, - userId = userId + userId = userId.ifEmpty { null } ) as T) } From 684b47033e2d65895c12829e0e9192e81f6e4181 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey <64667840+1abhishekpandey@users.noreply.github.com> Date: Fri, 19 Jul 2024 23:10:46 +0530 Subject: [PATCH 6/6] fix: return -1 as default value for getInt in SharedPrefsStore --- .../com/rudderstack/android/internal/prefs/SharedPrefsStore.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/com/rudderstack/android/internal/prefs/SharedPrefsStore.kt b/android/src/main/java/com/rudderstack/android/internal/prefs/SharedPrefsStore.kt index 4282dd9c..95d11897 100644 --- a/android/src/main/java/com/rudderstack/android/internal/prefs/SharedPrefsStore.kt +++ b/android/src/main/java/com/rudderstack/android/internal/prefs/SharedPrefsStore.kt @@ -15,7 +15,7 @@ class SharedPrefsStore( private val preferences: SharedPreferences = applicationContext.getSharedPreferences(prefsName, Context.MODE_PRIVATE) override fun getInt(key: String): Int { - return preferences.getInt(key, 0) + return preferences.getInt(key, -1) } override fun getBoolean(key: String): Boolean {