Skip to content

Commit 61da2e6

Browse files
committed
Replace truetime with networktime
1 parent 62e045b commit 61da2e6

File tree

83 files changed

+577
-499
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+577
-499
lines changed

eventproducer/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ dependencies {
2727
implementation(libs.tickaroo.annotation)
2828
implementation(libs.tickaroo.core)
2929
implementation(libs.tickaroo.retrofitConverter)
30-
implementation(libs.truetime)
30+
implementation(libs.tidal.networktime.singletons)
3131

3232
ksp(libs.dagger.compiler)
3333
kapt(libs.room.compiler)

eventproducer/src/main/kotlin/com/tidal/sdk/eventproducer/EventProducer.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.tidal.sdk.eventproducer
22

33
import android.content.Context
4+
import com.tidal.networktime.SNTPClient
45
import com.tidal.sdk.auth.CredentialsProvider
56
import com.tidal.sdk.eventproducer.di.DaggerEventsComponent
67
import com.tidal.sdk.eventproducer.model.EventsConfig
@@ -43,6 +44,9 @@ class EventProducer private constructor(coroutineScope: CoroutineScope) {
4344
@Inject
4445
internal lateinit var monitoringScheduler: MonitoringScheduler
4546

47+
@Inject
48+
internal lateinit var sntpClient: SNTPClient
49+
4650
internal fun startOutage() {
4751
_outageState.value = OutageState.Outage()
4852
}
@@ -91,6 +95,7 @@ class EventProducer private constructor(coroutineScope: CoroutineScope) {
9195
)
9296
EventProducer(coroutineScope).also {
9397
eventsComponent.inject(it)
98+
it.sntpClient.enableSynchronization()
9499
coroutineScope.launch(Dispatchers.IO) { it.scheduler.scheduleBatchAndSend() }
95100
coroutineScope.launch(Dispatchers.IO) {
96101
it.monitoringScheduler.scheduleSendMonitoringInfo()
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.tidal.sdk.eventproducer.di
22

3+
import com.tidal.networktime.NTPServer
4+
import com.tidal.networktime.SNTPClient
5+
import com.tidal.networktime.singletons.singleton
36
import com.tidal.sdk.auth.CredentialsProvider
47
import com.tidal.sdk.eventproducer.model.EventsConfigProvider
58
import com.tidal.sdk.eventproducer.utils.HeadersUtils
6-
import com.tidal.sdk.eventproducer.utils.TrueTimeWrapper
79
import dagger.Module
810
import dagger.Provides
911
import dagger.Reusable
@@ -15,10 +17,10 @@ internal class UtilsModule {
1517
fun provideHeadersUtils(
1618
configProvider: EventsConfigProvider,
1719
credentialsProvider: CredentialsProvider,
18-
trueTimeWrapper: TrueTimeWrapper,
19-
) = HeadersUtils(configProvider.config.appVersion, credentialsProvider, trueTimeWrapper)
20+
sntpClient: SNTPClient,
21+
) = HeadersUtils(configProvider.config.appVersion, credentialsProvider, sntpClient)
2022

2123
@Provides
2224
@Reusable
23-
fun provideTrueTimeWrapper() = TrueTimeWrapper()
25+
fun provideSNTPClient() = SNTPClient(NTPServer("time.google.com")).singleton
2426
}

eventproducer/src/main/kotlin/com/tidal/sdk/eventproducer/utils/HeadersUtils.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.tidal.sdk.eventproducer.utils
22

33
import android.os.Build
4+
import com.tidal.networktime.SNTPClient
45
import com.tidal.sdk.auth.CredentialsProvider
56
import com.tidal.sdk.eventproducer.model.ConsentCategory
67
import javax.inject.Inject
@@ -19,7 +20,7 @@ internal const val DEVICE_VENDOR_KEY = "device-vendor"
1920
internal class HeadersUtils @Inject constructor(
2021
private val appVersion: String,
2122
private val credentialsProvider: CredentialsProvider,
22-
private val trueTimeWrapper: TrueTimeWrapper,
23+
private val sntpClient: SNTPClient,
2324
) {
2425
fun getEventHeaders(
2526
defaultHeaders: Map<String, String>,
@@ -32,7 +33,7 @@ internal class HeadersUtils @Inject constructor(
3233
): Map<String, String> {
3334
val deviceModel = Build.MODEL
3435
val deviceVendor = Build.MANUFACTURER
35-
val sentTimestamp = trueTimeWrapper.currentTimeMillis.toString()
36+
val sentTimestamp = sntpClient.ntpOrLocalClockTime.inWholeMilliseconds.toString()
3637
val osName = "Android"
3738
val osVersion = Build.VERSION.SDK_INT.toString()
3839
val headers = mutableMapOf<String, String>()

eventproducer/src/main/kotlin/com/tidal/sdk/eventproducer/utils/TrueTimeWrapper.kt

Lines changed: 0 additions & 13 deletions
This file was deleted.

eventproducer/src/main/kotlin/com/tidal/sdk/eventproducer/utils/Utils.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.tidal.sdk.eventproducer.utils
22

3+
import com.tidal.networktime.SNTPClient
34
import com.tidal.sdk.eventproducer.model.Result
45
import com.tidal.sdk.eventproducer.model.failure
56
import com.tidal.sdk.eventproducer.model.success
7+
import kotlin.time.Duration
8+
import kotlin.time.Duration.Companion.milliseconds
69

710
@Suppress("TooGenericExceptionCaught", "SwallowedException")
811
internal suspend fun <T> safeRequest(block: suspend () -> T): Result<T> {
@@ -12,3 +15,6 @@ internal suspend fun <T> safeRequest(block: suspend () -> T): Result<T> {
1215
failure()
1316
}
1417
}
18+
19+
internal val SNTPClient.ntpOrLocalClockTime: Duration
20+
get() = epochTime ?: System.currentTimeMillis().milliseconds

eventproducer/src/test/kotlin/com/tidal/eventproducer/utils/HeadersUtilsTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package com.tidal.eventproducer.utils
33
import assertk.assertThat
44
import assertk.assertions.containsAll
55
import com.tidal.eventproducer.fakes.FakeCredentialsProvider
6+
import com.tidal.networktime.SNTPClient
67
import com.tidal.sdk.eventproducer.utils.APP_VERSION_KEY
78
import com.tidal.sdk.eventproducer.utils.CLIENT_ID_KEY
89
import com.tidal.sdk.eventproducer.utils.HeadersUtils
910
import com.tidal.sdk.eventproducer.utils.OS_NAME_KEY
10-
import com.tidal.sdk.eventproducer.utils.TrueTimeWrapper
1111
import io.mockk.mockk
1212
import org.junit.jupiter.api.Assertions.assertEquals
1313
import org.junit.jupiter.api.Test
@@ -17,7 +17,7 @@ class HeadersUtilsTest {
1717
private val headerUtils = HeadersUtils(
1818
"",
1919
FakeCredentialsProvider(),
20-
mockk<TrueTimeWrapper>(),
20+
mockk<SNTPClient>(),
2121
)
2222

2323
@Test

gradle/libs.versions.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ slf4j-api = "2.0.12"
2121
tickaroo = "0.8.13"
2222
tidal-androidx-media = "1.1.1.2"
2323
plugins-tidal = "unspecified"
24+
tidal-networktime = "1.1.1"
2425

2526
[libraries]
2627
plugin-kotlin-android = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
@@ -55,7 +56,6 @@ gson = "com.google.code.gson:gson:2.9.0"
5556
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
5657
kotlin-logging = { module = "io.github.oshai:kotlin-logging-jvm", version.ref = "kotlin-logging" }
5758
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j-api" }
58-
truetime = "com.github.instacart.truetime-android:library-extension-rx:3.5"
5959

6060
# Moshi
6161
moshi = { module = "com.squareup.moshi:moshi", version.ref ="moshi"}
@@ -112,6 +112,9 @@ tidal-exoPlayer-hls = { module = "com.tidal.androidx.media3:media3-exoplayer-hls
112112
tidal-exoPlayer-extension-flac = { module = "com.tidal.androidx.media3:media3-flac", version.ref = "tidal-androidx-media" }
113113
tidal-exoPlayer-extension-okhttp = { module = "com.tidal.androidx.media3:media3-datasource-okhttp", version.ref = "tidal-androidx-media" }
114114

115+
tidal-networktime = { module = "com.tidal.networktime:networktime", version.ref = "tidal-networktime" }
116+
tidal-networktime-singletons = { module = "com.tidal.networktime:networktime-singletons", version.ref = "tidal-networktime" }
117+
115118
# Security
116119
androidx-security-crypto = { module = "androidx.security:security-crypto", version = "1.0.0" }
117120

player/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ The Player module encapsulates the playback functionality of TIDAL media product
1919

2020
### Installation
2121

22-
1. We are using the [TrueTime library](https://github.com/instacart/truetime-android) internally, so you need to add the following to your repositories list:
22+
1. Add the dependency to your `build.gradle.kts` file.
2323
```kotlin
24-
maven {
25-
url = uri("https://jitpack.io")
24+
repositories {
25+
mavenCentral()
2626
}
2727
```
2828

29-
2. Add the dependency to your `build.gradle.kts` file.
3029
```kotlin
3130
dependencies {
3231
implementation("com.tidal.sdk:player:<VERSION>")
3332
}
3433
```
34+
3535
### Playing a TIDAL track
3636
The Player depends on the [Auth](https://github.com/tidal-music/tidal-sdk-android/blob/main/auth/README.md) and [EventProducer](https://github.com/tidal-music/tidal-sdk-android/tree/main/eventproducer) modules for authentication and event reporting handling. For detailed instructions on how to set them up, please refer to their guide.
3737

player/apps/demo/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,4 @@ dependencies {
3535
implementation(platform(libs.androidx.compose.bom))
3636
implementation(libs.androidx.activity.compose)
3737
implementation(libs.androidx.compose.material3)
38-
implementation(libs.truetime)
3938
}

0 commit comments

Comments
 (0)