From 22cae9bb858534eab20cb8bc49db9edaf5752395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Muller?= Date: Thu, 1 Feb 2024 10:51:17 +0100 Subject: [PATCH] Revert `LruCache` change and version name fallback --- gradle/libs.versions.toml | 2 -- pillarbox-analytics/build.gradle.kts | 1 + .../pillarbox/analytics/comscore/ComScoreSrg.kt | 8 +++++--- .../analytics/SRGAnalyticsSingletonTest.kt | 13 +++++++++---- .../pillarbox/analytics/comscore/ComScoreSrgTest.kt | 12 +++++++++--- pillarbox-player/build.gradle.kts | 1 - .../PillarboxMediaDescriptionAdapter.kt | 2 +- 7 files changed, 25 insertions(+), 14 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2381aa546..7c3b6b7f7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,6 @@ accompanist = "0.32.0" android-gradle-plugin = "8.2.1" androidx-activity = "1.8.2" androidx-annotation = "1.7.1" -androidx-collection = "1.4.0" androidx-compose = "2023.10.01" androidx-core = "1.12.0" androidx-fragment = "1.6.2" @@ -45,7 +44,6 @@ androidx-activity = { module = "androidx.activity:activity", version.ref = "andr androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" } androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version.ref = "androidx-activity" } androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "androidx-annotation" } -androidx-collection = { module = "androidx.collection:collection", version.ref = "androidx-collection" } androidx-core = { module = "androidx.core:core", version.ref = "androidx-core" } androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx-core" } androidx-fragment = { module = "androidx.fragment:fragment", version.ref = "androidx-fragment" } diff --git a/pillarbox-analytics/build.gradle.kts b/pillarbox-analytics/build.gradle.kts index 94e4207a5..de9e73091 100644 --- a/pillarbox-analytics/build.gradle.kts +++ b/pillarbox-analytics/build.gradle.kts @@ -73,6 +73,7 @@ dependencies { testImplementation(libs.mockk.dsl) testRuntimeOnly(libs.robolectric) testImplementation(libs.robolectric.annotations) + testImplementation(libs.robolectric.shadows.framework) } kover { diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreSrg.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreSrg.kt index 3c215cc0e..71e5ea2c7 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreSrg.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreSrg.kt @@ -48,8 +48,10 @@ internal object ComScoreSrg : ComScore { val userConsentLabel = getUserConsentPair(config.userConsent.comScore) persistentLabels[userConsentLabel.first] = userConsentLabel.second - val versionName: String = context.applicationContext.packageManager.getPackageInfo(context.applicationContext.packageName, 0).versionName - ?: BuildConfig.VERSION_NAME + val applicationContext = context.applicationContext + val versionName: String = applicationContext.packageManager + .getPackageInfo(applicationContext.packageName, 0) + .versionName persistentLabels[ComScoreLabel.MP_V.label] = versionName persistentLabels[ComScoreLabel.MP_BRAND.label] = config.vendor.toString() val publisher = PublisherConfiguration.Builder() @@ -69,7 +71,7 @@ internal object ComScoreSrg : ComScore { if (BuildConfig.DEBUG) { Analytics.getConfiguration().enableImplementationValidationMode() } - start(context.applicationContext) + start(applicationContext) return this } diff --git a/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/SRGAnalyticsSingletonTest.kt b/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/SRGAnalyticsSingletonTest.kt index 517cef651..ce216978f 100644 --- a/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/SRGAnalyticsSingletonTest.kt +++ b/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/SRGAnalyticsSingletonTest.kt @@ -12,21 +12,26 @@ import com.comscore.Analytics import io.mockk.mockkStatic import io.mockk.unmockkAll import org.junit.runner.RunWith +import org.robolectric.Shadows.shadowOf import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test @RunWith(AndroidJUnit4::class) class SRGAnalyticsSingletonTest { - private val config = AnalyticsConfig( vendor = AnalyticsConfig.Vendor.SRG, appSiteName = "pillarbox-test-android", sourceKey = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG ) + private lateinit var context: Context + @BeforeTest fun setup() { + context = ApplicationProvider.getApplicationContext() + shadowOf(context.packageManager).getInternalMutablePackageInfo(context.packageName).versionName = "1.2.3" + mockkStatic(Analytics::class) } @@ -37,8 +42,8 @@ class SRGAnalyticsSingletonTest { @Test(expected = IllegalArgumentException::class) fun testInitTwice() { - val appContext: Context = ApplicationProvider.getApplicationContext() - SRGAnalytics.init(appContext as Application, config) - SRGAnalytics.init(appContext, config.copy(vendor = AnalyticsConfig.Vendor.RSI)) + val application = context as Application + SRGAnalytics.init(application, config) + SRGAnalytics.init(application, config.copy(vendor = AnalyticsConfig.Vendor.RSI)) } } diff --git a/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreSrgTest.kt b/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreSrgTest.kt index d5386024f..5cdde4467 100644 --- a/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreSrgTest.kt +++ b/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreSrgTest.kt @@ -4,6 +4,7 @@ */ package ch.srgssr.pillarbox.analytics.comscore +import android.content.Context import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import ch.srgssr.pillarbox.analytics.AnalyticsConfig @@ -16,23 +17,28 @@ import io.mockk.mockkStatic import io.mockk.unmockkAll import io.mockk.verify import org.junit.runner.RunWith +import org.robolectric.Shadows.shadowOf import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test @RunWith(AndroidJUnit4::class) class ComScoreSrgTest { - private val config = AnalyticsConfig( vendor = AnalyticsConfig.Vendor.SRG, appSiteName = "pillarbox-test-android", sourceKey = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG ) + private lateinit var context: Context + @BeforeTest fun setup() { + context = ApplicationProvider.getApplicationContext() + shadowOf(context.packageManager).getInternalMutablePackageInfo(context.packageName).versionName = "1.2.3" + mockkStatic(Analytics::class) - ComScoreSrg.init(config = config, context = ApplicationProvider.getApplicationContext()) + ComScoreSrg.init(config = config, context = context) } @AfterTest @@ -42,7 +48,7 @@ class ComScoreSrgTest { @Test(expected = IllegalArgumentException::class) fun `init a second time with other config should throw exception`() { - ComScoreSrg.init(config = config.copy(vendor = AnalyticsConfig.Vendor.RTS), context = ApplicationProvider.getApplicationContext()) + ComScoreSrg.init(config = config.copy(vendor = AnalyticsConfig.Vendor.RTS), context = context) } @Test diff --git a/pillarbox-player/build.gradle.kts b/pillarbox-player/build.gradle.kts index fe8a374c8..b2a1062e2 100644 --- a/pillarbox-player/build.gradle.kts +++ b/pillarbox-player/build.gradle.kts @@ -66,7 +66,6 @@ android { dependencies { implementation(libs.androidx.annotation) - implementation(libs.androidx.collection) implementation(libs.androidx.core) implementation(libs.androidx.media) api(libs.androidx.media3.common) diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/notification/PillarboxMediaDescriptionAdapter.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/notification/PillarboxMediaDescriptionAdapter.kt index 801c3cee3..dea6b65cf 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/notification/PillarboxMediaDescriptionAdapter.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/notification/PillarboxMediaDescriptionAdapter.kt @@ -9,7 +9,7 @@ import android.content.Context import android.graphics.Bitmap import android.graphics.BitmapFactory import android.net.Uri -import androidx.collection.LruCache +import android.util.LruCache import androidx.media3.common.Player import androidx.media3.ui.PlayerNotificationManager import androidx.media3.ui.PlayerNotificationManager.MediaDescriptionAdapter