From 0f0ec54ed1264eab882e98abc98d38ad71f0d7dc Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Thu, 29 Sep 2022 12:20:01 +0300 Subject: [PATCH] Code review fixes. --- changelog.d/{7209.feature => 7209.sdk} | 0 .../sdk/internal/network/ComputeUserAgentUseCase.kt | 7 ++++--- .../android/sdk/internal/network/UserAgentHolder.kt | 4 +--- .../internal/network/ComputeUserAgentUseCaseTest.kt | 10 +++++----- 4 files changed, 10 insertions(+), 11 deletions(-) rename changelog.d/{7209.feature => 7209.sdk} (100%) diff --git a/changelog.d/7209.feature b/changelog.d/7209.sdk similarity index 100% rename from changelog.d/7209.feature rename to changelog.d/7209.sdk diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCase.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCase.kt index 64696ca298..6eb4d5b104 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCase.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCase.kt @@ -22,16 +22,17 @@ import org.matrix.android.sdk.BuildConfig import org.matrix.android.sdk.api.extensions.tryOrNull import javax.inject.Inject -class ComputeUserAgentUseCase @Inject constructor() { +class ComputeUserAgentUseCase @Inject constructor( + private val context: Context, +) { /** * Create an user agent with the application version. * Ex: Element/1.5.0 (Xiaomi Mi 9T; Android 11; RKQ1.200826.002; Flavour GooglePlay; MatrixAndroidSdk2 1.5.0) * - * @param context the context * @param flavorDescription the flavor description */ - fun execute(context: Context, flavorDescription: String): String { + fun execute(flavorDescription: String): String { val appPackageName = context.applicationContext.packageName val pm = context.packageManager diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/UserAgentHolder.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/UserAgentHolder.kt index 9383932cc7..4e83261277 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/UserAgentHolder.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/UserAgentHolder.kt @@ -16,14 +16,12 @@ package org.matrix.android.sdk.internal.network -import android.content.Context import org.matrix.android.sdk.api.MatrixConfiguration import org.matrix.android.sdk.internal.di.MatrixScope import javax.inject.Inject @MatrixScope internal class UserAgentHolder @Inject constructor( - context: Context, matrixConfiguration: MatrixConfiguration, computeUserAgentUseCase: ComputeUserAgentUseCase, ) { @@ -32,6 +30,6 @@ internal class UserAgentHolder @Inject constructor( private set init { - userAgent = computeUserAgentUseCase.execute(context, matrixConfiguration.applicationFlavor) + userAgent = computeUserAgentUseCase.execute(matrixConfiguration.applicationFlavor) } } diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCaseTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCaseTest.kt index 77f432a70a..9ed6f28d7e 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCaseTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCaseTest.kt @@ -42,7 +42,7 @@ class ComputeUserAgentUseCaseTest { private val applicationInfo = mockk() private val packageInfo = mockk() - private val computeUserAgentUseCase = ComputeUserAgentUseCase() + private val computeUserAgentUseCase = ComputeUserAgentUseCase(context) @Before fun setUp() { @@ -60,7 +60,7 @@ class ComputeUserAgentUseCaseTest { givenAppVersion(AN_APP_VERSION) // When - val result = computeUserAgentUseCase.execute(context, A_FLAVOUR) + val result = computeUserAgentUseCase.execute(A_FLAVOUR) // Then val expectedUserAgent = constructExpectedUserAgent(AN_APP_NAME, AN_APP_VERSION) @@ -74,7 +74,7 @@ class ComputeUserAgentUseCaseTest { givenAppVersion(AN_APP_VERSION) // When - val result = computeUserAgentUseCase.execute(context, A_FLAVOUR) + val result = computeUserAgentUseCase.execute(A_FLAVOUR) // Then val expectedUserAgent = constructExpectedUserAgent(A_PACKAGE_NAME, AN_APP_VERSION) @@ -88,7 +88,7 @@ class ComputeUserAgentUseCaseTest { givenAppVersion(AN_APP_VERSION) // When - val result = computeUserAgentUseCase.execute(context, A_FLAVOUR) + val result = computeUserAgentUseCase.execute(A_FLAVOUR) // Then val expectedUserAgent = constructExpectedUserAgent(A_PACKAGE_NAME, AN_APP_VERSION) @@ -102,7 +102,7 @@ class ComputeUserAgentUseCaseTest { givenAppVersion(null) // When - val result = computeUserAgentUseCase.execute(context, A_FLAVOUR) + val result = computeUserAgentUseCase.execute(A_FLAVOUR) // Then val expectedUserAgent = constructExpectedUserAgent(AN_APP_NAME, ComputeUserAgentUseCase.FALLBACK_APP_VERSION)