Skip to content

Commit

Permalink
feat: Custom user agent (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisCAD authored Dec 17, 2024
2 parents 16334c2 + d629aa0 commit 80c19c0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
31 changes: 31 additions & 0 deletions Core2/src/main/java/com/infomaniak/core2/UserAgentUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Infomaniak SwissTransfer - Android
* Copyright (C) 2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.core2

import android.os.Build

fun buildUserAgent(
appId: String,
appVersionCode: Int,
appVersionName: String,
): String {
val androidVersion = "Android ${Build.VERSION.RELEASE}"
val arch = System.getProperty("os.arch")
return "$appId/$appVersionName-$appVersionCode (${Build.MODEL}; $androidVersion; $arch)"
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ package com.infomaniak.swisstransfer.di

import android.app.Application
import com.infomaniak.core2.appintegrity.AppIntegrityManager
import com.infomaniak.core2.buildUserAgent
import com.infomaniak.multiplatform_swisstransfer.SwissTransferInjection
import com.infomaniak.multiplatform_swisstransfer.common.utils.ApiEnvironment
import com.infomaniak.swisstransfer.BuildConfig
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -34,7 +36,12 @@ object SwissTransferInjectionModule {
@Provides
@Singleton
fun providesSwissTransferInjection(): SwissTransferInjection {
return SwissTransferInjection(environment = ApiEnvironment.Prod, userAgent = "Ktor client")
val userAgent = buildUserAgent(
appId = BuildConfig.APPLICATION_ID,
appVersionCode = BuildConfig.VERSION_CODE,
appVersionName = BuildConfig.VERSION_NAME,
)
return SwissTransferInjection(environment = ApiEnvironment.Prod, userAgent = userAgent)
}

@Provides
Expand Down

0 comments on commit 80c19c0

Please sign in to comment.