diff --git a/dd-sdk-android-core/api/apiSurface b/dd-sdk-android-core/api/apiSurface index 905f1421d8..93edb304a5 100644 --- a/dd-sdk-android-core/api/apiSurface +++ b/dd-sdk-android-core/api/apiSurface @@ -292,7 +292,7 @@ interface com.datadog.android.core.persistence.datastore.DataStoreCallback - constructor(Long, Int, T?) + constructor(Int, T?) interface com.datadog.android.core.persistence.datastore.DataStoreHandler fun setValue(String, T, Int = 0, com.datadog.android.core.persistence.Serializer) fun value(String, Int = 0, DataStoreCallback, com.datadog.android.core.internal.persistence.Deserializer) diff --git a/dd-sdk-android-core/api/dd-sdk-android-core.api b/dd-sdk-android-core/api/dd-sdk-android-core.api index d7e8d9e022..b518b7aca1 100644 --- a/dd-sdk-android-core/api/dd-sdk-android-core.api +++ b/dd-sdk-android-core/api/dd-sdk-android-core.api @@ -790,15 +790,13 @@ public abstract interface class com/datadog/android/core/persistence/datastore/D } public final class com/datadog/android/core/persistence/datastore/DataStoreContent { - public fun (JILjava/lang/Object;)V - public final fun component1 ()J - public final fun component2 ()I - public final fun component3 ()Ljava/lang/Object; - public final fun copy (JILjava/lang/Object;)Lcom/datadog/android/core/persistence/datastore/DataStoreContent; - public static synthetic fun copy$default (Lcom/datadog/android/core/persistence/datastore/DataStoreContent;JILjava/lang/Object;ILjava/lang/Object;)Lcom/datadog/android/core/persistence/datastore/DataStoreContent; + public fun (ILjava/lang/Object;)V + public final fun component1 ()I + public final fun component2 ()Ljava/lang/Object; + public final fun copy (ILjava/lang/Object;)Lcom/datadog/android/core/persistence/datastore/DataStoreContent; + public static synthetic fun copy$default (Lcom/datadog/android/core/persistence/datastore/DataStoreContent;ILjava/lang/Object;ILjava/lang/Object;)Lcom/datadog/android/core/persistence/datastore/DataStoreContent; public fun equals (Ljava/lang/Object;)Z public final fun getData ()Ljava/lang/Object; - public final fun getLastUpdateDate ()J public final fun getVersionCode ()I public fun hashCode ()I public fun toString ()Ljava/lang/String; diff --git a/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/persistence/datastore/DatastoreFileReader.kt b/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/persistence/datastore/DatastoreFileReader.kt index 710c54554d..ab6d87aa12 100644 --- a/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/persistence/datastore/DatastoreFileReader.kt +++ b/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/persistence/datastore/DatastoreFileReader.kt @@ -10,7 +10,6 @@ import androidx.annotation.WorkerThread import com.datadog.android.api.InternalLogger import com.datadog.android.core.internal.persistence.Deserializer import com.datadog.android.core.internal.persistence.datastore.ext.toInt -import com.datadog.android.core.internal.persistence.datastore.ext.toLong import com.datadog.android.core.internal.persistence.file.existsSafe import com.datadog.android.core.internal.persistence.tlvformat.TLVBlock import com.datadog.android.core.internal.persistence.tlvformat.TLVBlockFileReader @@ -89,19 +88,17 @@ internal class DatastoreFileReader( deserializer: Deserializer, tlvBlocks: List ): DataStoreContent? { - if (tlvBlocks[0].type != TLVBlockType.LAST_UPDATE_DATE && - tlvBlocks[1].type != TLVBlockType.VERSION_CODE + if (tlvBlocks[0].type != TLVBlockType.VERSION_CODE && + tlvBlocks[1].type != TLVBlockType.DATA ) { logBlocksInUnexpectedBlocksOrderError() return null } - val lastUpdateBlock = tlvBlocks[0] - val versionCodeBlock = tlvBlocks[1] - val dataBlock = tlvBlocks[2] + val versionCodeBlock = tlvBlocks[0] + val dataBlock = tlvBlocks[1] return DataStoreContent( - lastUpdateDate = lastUpdateBlock.data.toLong(), versionCode = versionCodeBlock.data.toInt(), data = deserializer.deserialize(String(dataBlock.data)) ) diff --git a/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/persistence/datastore/DatastoreFileWriter.kt b/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/persistence/datastore/DatastoreFileWriter.kt index ad729fd826..834feab400 100644 --- a/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/persistence/datastore/DatastoreFileWriter.kt +++ b/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/persistence/datastore/DatastoreFileWriter.kt @@ -43,16 +43,15 @@ internal class DatastoreFileWriter( key = key ) - val lastUpdateBlock = getLastUpdateDateBlock() val versionCodeBlock = getVersionCodeBlock(version) val dataBlock = getDataBlock(data, serializer) // failed to serialize one or more blocks - if (lastUpdateBlock == null || versionCodeBlock == null || dataBlock == null) { + if (versionCodeBlock == null || dataBlock == null) { return } - val dataToWrite = listOf(lastUpdateBlock, versionCodeBlock, dataBlock).join( + val dataToWrite = listOf(versionCodeBlock, dataBlock).join( separator = byteArrayOf(), internalLogger = internalLogger ) @@ -102,18 +101,6 @@ internal class DatastoreFileWriter( return dataBlock.serialize() } - private fun getLastUpdateDateBlock(): ByteArray? { - val now = System.currentTimeMillis() - val lastUpdateDateByteArray = now.toByteArray() - val lastUpdateDateBlock = TLVBlock( - type = TLVBlockType.LAST_UPDATE_DATE, - data = lastUpdateDateByteArray, - internalLogger = internalLogger - ) - - return lastUpdateDateBlock.serialize() - } - private fun getVersionCodeBlock(version: Int): ByteArray? { val versionCodeByteArray = version.toByteArray() val versionBlock = TLVBlock( diff --git a/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/persistence/tlvformat/TLVBlockType.kt b/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/persistence/tlvformat/TLVBlockType.kt index 55bd06c725..163df94f1a 100644 --- a/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/persistence/tlvformat/TLVBlockType.kt +++ b/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/persistence/tlvformat/TLVBlockType.kt @@ -7,9 +7,8 @@ package com.datadog.android.core.internal.persistence.tlvformat internal enum class TLVBlockType(val rawValue: UShort) { - LAST_UPDATE_DATE(0x00u), - VERSION_CODE(0x01u), - DATA(0x02u); + VERSION_CODE(0x00u), + DATA(0x01u); companion object { private val map = values().associateBy { it.rawValue } diff --git a/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/persistence/datastore/DataStoreCallback.kt b/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/persistence/datastore/DataStoreCallback.kt index 02c1feb1bf..c174861d3f 100644 --- a/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/persistence/datastore/DataStoreCallback.kt +++ b/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/persistence/datastore/DataStoreCallback.kt @@ -14,7 +14,7 @@ interface DataStoreCallback { /** * Called on successfully fetching data from the datastore. * - * @param dataStoreContent contains the datastore data, version and lastUpdateDate. + * @param dataStoreContent contains the datastore data and version. */ fun onSuccess(dataStoreContent: DataStoreContent) diff --git a/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/persistence/datastore/DataStoreContent.kt b/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/persistence/datastore/DataStoreContent.kt index 25945bc0cf..e6e8c2590e 100644 --- a/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/persistence/datastore/DataStoreContent.kt +++ b/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/persistence/datastore/DataStoreContent.kt @@ -10,12 +10,10 @@ package com.datadog.android.core.persistence.datastore * Datastore entry contents and metadata. * * @param T type of data used by this entry in the datastore. - * @property lastUpdateDate date when the entry was written. * @property versionCode version used by the entry. * @property data content of the entry. */ data class DataStoreContent( - val lastUpdateDate: Long, val versionCode: Int, val data: T? ) diff --git a/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/persistence/file/datastore/DataStoreFileReaderTest.kt b/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/persistence/file/datastore/DataStoreFileReaderTest.kt index 38b0f2bf87..9aa2225923 100644 --- a/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/persistence/file/datastore/DataStoreFileReaderTest.kt +++ b/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/persistence/file/datastore/DataStoreFileReaderTest.kt @@ -82,7 +82,6 @@ internal class DataStoreFileReaderTest { private lateinit var fakeDataBytes: ByteArray private lateinit var versionBlock: TLVBlock - private lateinit var lastUpdateDateBlock: TLVBlock private lateinit var dataBlock: TLVBlock private lateinit var blocksReturned: ArrayList @@ -102,10 +101,9 @@ internal class DataStoreFileReaderTest { whenever(mockDataStoreFile.existsSafe(mockInternalLogger)).thenReturn(true) whenever(mockDeserializer.deserialize(fakeDataString)).thenReturn(fakeDataBytes) - lastUpdateDateBlock = createLastUpdateDateBlock() versionBlock = createVersionBlock(true) dataBlock = createDataBlock() - blocksReturned = arrayListOf(lastUpdateDateBlock, versionBlock, dataBlock) + blocksReturned = arrayListOf(versionBlock, dataBlock) whenever(mockTLVBlockFileReader.read(mockDataStoreFile)).thenReturn(blocksReturned) testedDatastoreFileReader = DatastoreFileReader( @@ -218,7 +216,6 @@ internal class DataStoreFileReaderTest { fun `M return deserialized data W read()`() { // Given blocksReturned.clear() - blocksReturned.add(createLastUpdateDateBlock()) blocksReturned.add(createVersionBlock(true)) blocksReturned.add(createDataBlock()) @@ -281,7 +278,7 @@ internal class DataStoreFileReaderTest { @Test fun `M log unexpectedBlocksOrder error W read() { unexpected block order }`() { // Given - blocksReturned = arrayListOf(versionBlock, lastUpdateDateBlock, dataBlock) + blocksReturned = arrayListOf(dataBlock, versionBlock) whenever(mockTLVBlockFileReader.read(mockDataStoreFile)).thenReturn(blocksReturned) // When @@ -347,15 +344,6 @@ internal class DataStoreFileReaderTest { } } - private fun createLastUpdateDateBlock(): TLVBlock = - TLVBlock( - type = TLVBlockType.LAST_UPDATE_DATE, - data = ByteBuffer.allocate(Long.SIZE_BYTES) - .putLong(System.currentTimeMillis()) - .array(), - internalLogger = mockInternalLogger - ) - private fun createDataBlock(dataBytes: ByteArray = fakeDataBytes): TLVBlock = TLVBlock( type = TLVBlockType.DATA, diff --git a/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/persistence/tlvformat/TLVBlockFileReaderTest.kt b/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/persistence/tlvformat/TLVBlockFileReaderTest.kt index e5747cd411..0d7e87023d 100644 --- a/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/persistence/tlvformat/TLVBlockFileReaderTest.kt +++ b/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/persistence/tlvformat/TLVBlockFileReaderTest.kt @@ -7,7 +7,6 @@ package com.datadog.android.core.internal.persistence.tlvformat import com.datadog.android.api.InternalLogger -import com.datadog.android.core.internal.persistence.datastore.ext.toByteArray import com.datadog.android.core.internal.persistence.file.FileReaderWriter import com.datadog.android.core.internal.persistence.tlvformat.TLVBlockFileReader.Companion.FAILED_TO_DESERIALIZE_ERROR import com.datadog.android.utils.forge.Configurator @@ -54,17 +53,15 @@ internal class TLVBlockFileReaderTest { @StringForgery(regex = "^(\\w{3})\$") // a minimal number of chars to avoid flakiness private lateinit var fakeDataString: String - private lateinit var fakeUpdateBytes: ByteArray private lateinit var fakeVersionBytes: ByteArray private lateinit var fakeDataBytes: ByteArray private lateinit var fakeBufferBytes: ByteArray @BeforeEach fun setup(@IntForgery(min = 0, max = 10) fakeVersion: Int) { - val lastUpdateBytes = createLastUpdateBytes() val versionBytes = createVersionBytes(fakeVersion) val dataBytes = createDataBytes() - val dataToWrite = lastUpdateBytes + versionBytes + dataBytes + val dataToWrite = versionBytes + dataBytes whenever(mockFileReaderWriter.readData(mockFile)).thenReturn(dataToWrite) @@ -118,13 +115,10 @@ internal class TLVBlockFileReaderTest { val tlvArray = testedReader.read(file = mockFile) // Then - assertThat(tlvArray.size).isEqualTo(3) - val lastUpdateObject = tlvArray[0] - val versionObject = tlvArray[1] - val dataObject = tlvArray[2] + assertThat(tlvArray.size).isEqualTo(2) + val versionObject = tlvArray[0] + val dataObject = tlvArray[1] - assertThat(lastUpdateObject.type).isEqualTo(TLVBlockType.LAST_UPDATE_DATE) - assertThat(lastUpdateObject.data).isEqualTo(fakeUpdateBytes) assertThat(versionObject.type).isEqualTo(TLVBlockType.VERSION_CODE) assertThat(versionObject.data).isEqualTo(fakeVersionBytes) assertThat(dataObject.type).isEqualTo(TLVBlockType.DATA) @@ -168,19 +162,6 @@ internal class TLVBlockFileReaderTest { ) } - private fun createLastUpdateBytes(): ByteArray { - val now = System.currentTimeMillis() - fakeUpdateBytes = now.toByteArray() - val lastUpdateType = TLVBlockType.LAST_UPDATE_DATE.rawValue.toShort() - - return ByteBuffer - .allocate(fakeUpdateBytes.size + Int.SIZE_BYTES + Short.SIZE_BYTES) - .putShort(lastUpdateType) - .putInt(fakeUpdateBytes.size) - .put(fakeUpdateBytes) - .array() - } - private fun createVersionBytes(fakeVersion: Int): ByteArray { val versionType = TLVBlockType.VERSION_CODE.rawValue.toShort() fakeVersionBytes = ByteBuffer.allocate(Int.SIZE_BYTES).putInt(fakeVersion).array() diff --git a/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/persistence/tlvformat/TLVBlockTypeTest.kt b/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/persistence/tlvformat/TLVBlockTypeTest.kt index e475bc30be..804c551a7b 100644 --- a/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/persistence/tlvformat/TLVBlockTypeTest.kt +++ b/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/persistence/tlvformat/TLVBlockTypeTest.kt @@ -27,10 +27,10 @@ internal class TLVBlockTypeTest { @Test fun `M return type value W fromValue() { existing value }`() { // When - val shortValue = TLVBlockType.fromValue(TLVBlockType.LAST_UPDATE_DATE.rawValue) + val shortValue = TLVBlockType.fromValue(TLVBlockType.VERSION_CODE.rawValue) // Then - assertThat(shortValue).isEqualTo(TLVBlockType.LAST_UPDATE_DATE) + assertThat(shortValue).isEqualTo(TLVBlockType.VERSION_CODE) } @Test