@@ -6,7 +6,9 @@ import com.segment.analytics.kotlin.android.utilities.AndroidKVS
66import com.segment.analytics.kotlin.core.Analytics
77import com.segment.analytics.kotlin.core.Storage
88import com.segment.analytics.kotlin.core.StorageProvider
9+ import com.segment.analytics.kotlin.core.utilities.EventStream
910import com.segment.analytics.kotlin.core.utilities.FileEventStream
11+ import com.segment.analytics.kotlin.core.utilities.KVS
1012import com.segment.analytics.kotlin.core.utilities.StorageImpl
1113import kotlinx.coroutines.CoroutineDispatcher
1214import sovran.kotlin.Store
@@ -19,7 +21,7 @@ class AndroidStorage(
1921 private val ioDispatcher : CoroutineDispatcher ,
2022 directory : String? = null ,
2123 subject : String? = null
22- ) : StorageImpl (
24+ ) : AndroidStorageImpl (
2325 propertiesFile = AndroidKVS (context.getSharedPreferences("analytics-android-$writeKey", Context .MODE_PRIVATE )),
2426 eventStream = FileEventStream (context.getDir(directory ? : "segment-disk-queue", Context .MODE_PRIVATE )),
2527 store = store,
@@ -28,6 +30,38 @@ class AndroidStorage(
2830 ioDispatcher = ioDispatcher
2931)
3032
33+ open class AndroidStorageImpl (
34+ propertiesFile : KVS ,
35+ eventStream : EventStream ,
36+ store : Store ,
37+ writeKey : String ,
38+ fileIndexKey : String ,
39+ ioDispatcher : CoroutineDispatcher
40+ ) : StorageImpl(
41+ propertiesFile = propertiesFile,
42+ eventStream = eventStream,
43+ store = store,
44+ writeKey = writeKey,
45+ fileIndexKey = fileIndexKey,
46+ ioDispatcher = ioDispatcher
47+ ) {
48+ override fun read (key : Storage .Constants ): String? {
49+ return if (key == Storage .Constants .LegacyAppBuild ) {
50+ // The legacy app build number was stored as an integer so we have to get it
51+ // as an integer and convert it to a String.
52+ val noBuild = - 1
53+ val build = propertiesFile.get(key.rawVal, noBuild)
54+ if (build != noBuild) {
55+ build.toString()
56+ } else {
57+ null
58+ }
59+ } else {
60+ super .read(key)
61+ }
62+ }
63+ }
64+
3165object AndroidStorageProvider : StorageProvider {
3266 override fun createStorage (vararg params : Any ): Storage {
3367
@@ -51,6 +85,6 @@ object AndroidStorageProvider : StorageProvider {
5185
5286 val propertiesFile = AndroidKVS (sharedPreferences)
5387 val eventStream = FileEventStream (eventDirectory)
54- return StorageImpl (propertiesFile, eventStream, analytics.store, config.writeKey, fileIndexKey, analytics.fileIODispatcher)
88+ return AndroidStorageImpl (propertiesFile, eventStream, analytics.store, config.writeKey, fileIndexKey, analytics.fileIODispatcher)
5589 }
5690}
0 commit comments