Code review fixes.

This commit is contained in:
Onuray Sahin 2022-09-29 12:20:01 +03:00
parent 33eeb721bf
commit 0f0ec54ed1
4 changed files with 10 additions and 11 deletions

View File

@ -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

View File

@ -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)
}
}

View File

@ -42,7 +42,7 @@ class ComputeUserAgentUseCaseTest {
private val applicationInfo = mockk<ApplicationInfo>()
private val packageInfo = mockk<PackageInfo>()
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)