Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace truetime with networktime #62

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eventproducer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies {
implementation(libs.tickaroo.annotation)
implementation(libs.tickaroo.core)
implementation(libs.tickaroo.retrofitConverter)
implementation(libs.truetime)
implementation(libs.tidal.networktime.singletons)

ksp(libs.dagger.compiler)
kapt(libs.room.compiler)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tidal.sdk.eventproducer

import android.content.Context
import com.tidal.networktime.SNTPClient
import com.tidal.sdk.auth.CredentialsProvider
import com.tidal.sdk.eventproducer.di.DaggerEventsComponent
import com.tidal.sdk.eventproducer.model.EventsConfig
Expand Down Expand Up @@ -43,6 +44,9 @@ class EventProducer private constructor(coroutineScope: CoroutineScope) {
@Inject
internal lateinit var monitoringScheduler: MonitoringScheduler

@Inject
internal lateinit var sntpClient: SNTPClient

internal fun startOutage() {
_outageState.value = OutageState.Outage()
}
Expand Down Expand Up @@ -91,6 +95,7 @@ class EventProducer private constructor(coroutineScope: CoroutineScope) {
)
EventProducer(coroutineScope).also {
eventsComponent.inject(it)
it.sntpClient.enableSynchronization()
coroutineScope.launch(Dispatchers.IO) { it.scheduler.scheduleBatchAndSend() }
coroutineScope.launch(Dispatchers.IO) {
it.monitoringScheduler.scheduleSendMonitoringInfo()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.tidal.sdk.eventproducer.di

import com.tidal.networktime.NTPServer
import com.tidal.networktime.SNTPClient
import com.tidal.networktime.singletons.singleton
import com.tidal.sdk.auth.CredentialsProvider
import com.tidal.sdk.eventproducer.model.EventsConfigProvider
import com.tidal.sdk.eventproducer.utils.HeadersUtils
import com.tidal.sdk.eventproducer.utils.TrueTimeWrapper
import dagger.Module
import dagger.Provides
import dagger.Reusable
Expand All @@ -15,10 +17,10 @@ internal class UtilsModule {
fun provideHeadersUtils(
configProvider: EventsConfigProvider,
credentialsProvider: CredentialsProvider,
trueTimeWrapper: TrueTimeWrapper,
) = HeadersUtils(configProvider.config.appVersion, credentialsProvider, trueTimeWrapper)
sntpClient: SNTPClient,
) = HeadersUtils(configProvider.config.appVersion, credentialsProvider, sntpClient)

@Provides
@Reusable
fun provideTrueTimeWrapper() = TrueTimeWrapper()
fun provideSNTPClient() = SNTPClient(NTPServer("time.google.com")).singleton
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tidal.sdk.eventproducer.utils

import android.os.Build
import com.tidal.networktime.SNTPClient
import com.tidal.sdk.auth.CredentialsProvider
import com.tidal.sdk.eventproducer.model.ConsentCategory
import javax.inject.Inject
Expand All @@ -19,7 +20,7 @@ internal const val DEVICE_VENDOR_KEY = "device-vendor"
internal class HeadersUtils @Inject constructor(
private val appVersion: String,
private val credentialsProvider: CredentialsProvider,
private val trueTimeWrapper: TrueTimeWrapper,
private val sntpClient: SNTPClient,
) {
fun getEventHeaders(
defaultHeaders: Map<String, String>,
Expand All @@ -32,7 +33,7 @@ internal class HeadersUtils @Inject constructor(
): Map<String, String> {
val deviceModel = Build.MODEL
val deviceVendor = Build.MANUFACTURER
val sentTimestamp = trueTimeWrapper.currentTimeMillis.toString()
val sentTimestamp = sntpClient.ntpOrLocalClockTime.inWholeMilliseconds.toString()
val osName = "Android"
val osVersion = Build.VERSION.SDK_INT.toString()
val headers = mutableMapOf<String, String>()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.tidal.sdk.eventproducer.utils

import com.tidal.networktime.SNTPClient
import com.tidal.sdk.eventproducer.model.Result
import com.tidal.sdk.eventproducer.model.failure
import com.tidal.sdk.eventproducer.model.success
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds

@Suppress("TooGenericExceptionCaught", "SwallowedException")
internal suspend fun <T> safeRequest(block: suspend () -> T): Result<T> {
Expand All @@ -12,3 +15,6 @@ internal suspend fun <T> safeRequest(block: suspend () -> T): Result<T> {
failure()
}
}

internal val SNTPClient.ntpOrLocalClockTime: Duration
get() = epochTime ?: System.currentTimeMillis().milliseconds
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package com.tidal.eventproducer.utils
import assertk.assertThat
import assertk.assertions.containsAll
import com.tidal.eventproducer.fakes.FakeCredentialsProvider
import com.tidal.networktime.SNTPClient
import com.tidal.sdk.eventproducer.utils.APP_VERSION_KEY
import com.tidal.sdk.eventproducer.utils.CLIENT_ID_KEY
import com.tidal.sdk.eventproducer.utils.HeadersUtils
import com.tidal.sdk.eventproducer.utils.OS_NAME_KEY
import com.tidal.sdk.eventproducer.utils.TrueTimeWrapper
import io.mockk.mockk
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
Expand All @@ -17,7 +17,7 @@ class HeadersUtilsTest {
private val headerUtils = HeadersUtils(
"",
FakeCredentialsProvider(),
mockk<TrueTimeWrapper>(),
mockk<SNTPClient>(),
)

@Test
Expand Down
5 changes: 4 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ slf4j-api = "2.0.12"
tickaroo = "0.8.13"
tidal-androidx-media = "1.1.1.2"
plugins-tidal = "unspecified"
tidal-networktime = "1.1.2"

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

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

tidal-networktime = { module = "com.tidal.networktime:networktime", version.ref = "tidal-networktime" }
tidal-networktime-singletons = { module = "com.tidal.networktime:networktime-singletons", version.ref = "tidal-networktime" }

# Security
androidx-security-crypto = { module = "androidx.security:security-crypto", version = "1.0.0" }

Expand Down
8 changes: 4 additions & 4 deletions player/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ The Player module encapsulates the playback functionality of TIDAL media product

### Installation

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:
1. Add the dependency to your `build.gradle.kts` file.
```kotlin
maven {
url = uri("https://jitpack.io")
repositories {
mavenCentral()
}
```

2. Add the dependency to your `build.gradle.kts` file.
```kotlin
dependencies {
implementation("com.tidal.sdk:player:<VERSION>")
}
```

### Playing a TIDAL track
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.

Expand Down
1 change: 0 additions & 1 deletion player/apps/demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ dependencies {
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.compose.material3)
implementation(libs.truetime)
}
1 change: 0 additions & 1 deletion player/apps/demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package="com.tidal.sdk.player">

<application
android:name=".MyApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="Player"
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions player/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {
implementation(libs.okhttp.loggingInterceptor)
implementation(libs.gson)
implementation(project(":player:streaming-privileges"))
implementation(libs.tidal.networktime.singletons)

testImplementation(libs.test.assertk)
testImplementation(libs.test.junit5Api)
Expand Down
1 change: 0 additions & 1 deletion player/common-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ android {

dependencies {
implementation(libs.kotlinx.serialization.json)
implementation(libs.truetime)

testImplementation(libs.test.junit5Api)
testRuntimeOnly(libs.test.junit5Engine)
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions player/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies {

implementation(libs.gson)
implementation(libs.okhttp.okhttp)
implementation(libs.tidal.networktime)

testImplementation(libs.test.junit5Api)
testRuntimeOnly(libs.test.junit5Engine)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.tidal.sdk.player.common

import com.tidal.networktime.SNTPClient
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds

val SNTPClient.ntpOrLocalClockTime: Duration
get() = epochTime ?: System.currentTimeMillis().milliseconds
1 change: 1 addition & 0 deletions player/events/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
implementation(libs.tidal.sdk.auth)
implementation(libs.tidal.sdk.eventproducer)
implementation(libs.kotlinxCoroutinesCore)
implementation(libs.tidal.networktime)

testImplementation(libs.test.assertk)
testImplementation(libs.test.junit5Api)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.tidal.sdk.player.events.playlogtest
import android.content.Context
import android.net.ConnectivityManager
import com.google.gson.Gson
import com.tidal.networktime.SNTPClient
import com.tidal.sdk.eventproducer.EventSender
import com.tidal.sdk.player.common.UUIDWrapper
import com.tidal.sdk.player.commonandroid.TrueTimeWrapper
import com.tidal.sdk.player.events.ClientSupplier
import com.tidal.sdk.player.events.UserSupplier
import com.tidal.sdk.player.events.di.DaggerDefaultEventReporterComponent
Expand All @@ -24,7 +24,7 @@ class PlayLogTestDefaultEventReporterComponentFactory(
okHttpClient: OkHttpClient,
gson: Gson,
uuidWrapper: UUIDWrapper,
trueTimeWrapper: TrueTimeWrapper,
sntpClient: SNTPClient,
eventSender: EventSender,
coroutineScope: CoroutineScope,
) = DaggerDefaultEventReporterComponent.factory()
Expand All @@ -36,7 +36,7 @@ class PlayLogTestDefaultEventReporterComponentFactory(
okHttpClient,
gson,
uuidWrapper,
trueTimeWrapper,
sntpClient,
eventSender,
coroutineScopeOverride,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.tidal.sdk.player.events
import android.content.Context
import android.net.ConnectivityManager
import com.google.gson.Gson
import com.tidal.networktime.SNTPClient
import com.tidal.sdk.eventproducer.EventSender
import com.tidal.sdk.player.common.UUIDWrapper
import com.tidal.sdk.player.commonandroid.TrueTimeWrapper
import com.tidal.sdk.player.events.di.DaggerDefaultEventReporterComponent
import kotlinx.coroutines.CoroutineScope
import okhttp3.OkHttpClient
Expand All @@ -19,7 +19,7 @@ class EventReporterModuleRoot(
okHttpClient: OkHttpClient,
gson: Gson,
uuidWrapper: UUIDWrapper,
trueTimeWrapper: TrueTimeWrapper,
sntpClient: SNTPClient,
eventSender: EventSender,
coroutineScope: CoroutineScope,
) {
Expand All @@ -33,7 +33,7 @@ class EventReporterModuleRoot(
okHttpClient,
gson,
uuidWrapper,
trueTimeWrapper,
sntpClient,
eventSender,
coroutineScope,
).eventReporter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.tidal.sdk.player.events.converter

import com.tidal.networktime.SNTPClient
import com.tidal.sdk.player.common.UUIDWrapper
import com.tidal.sdk.player.commonandroid.TrueTimeWrapper
import com.tidal.sdk.player.common.ntpOrLocalClockTime
import com.tidal.sdk.player.events.ClientSupplier
import com.tidal.sdk.player.events.UserSupplier
import com.tidal.sdk.player.events.model.AudioDownloadStatistics

internal class AudioDownloadStatisticsEventFactory(
private val trueTimeWrapper: TrueTimeWrapper,
private val sntpClient: SNTPClient,
private val uuidWrapper: UUIDWrapper,
private val userSupplier: UserSupplier,
private val clientSupplier: ClientSupplier,
Expand All @@ -17,7 +18,7 @@ internal class AudioDownloadStatisticsEventFactory(
override suspend fun invoke(payload: AudioDownloadStatistics.Payload) =
audioDownloadStatisticsFactory
.create(
trueTimeWrapper.currentTimeMillis,
sntpClient.ntpOrLocalClockTime.inWholeMilliseconds,
uuidWrapper.randomUUID,
userSupplier(),
clientSupplier(),
Expand Down
Loading
Loading