diff --git a/Core2/src/main/java/com/infomaniak/core2/UserAgentUtils.kt b/Core2/src/main/java/com/infomaniak/core2/UserAgentUtils.kt new file mode 100644 index 000000000..b0b1d49aa --- /dev/null +++ b/Core2/src/main/java/com/infomaniak/core2/UserAgentUtils.kt @@ -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 . + */ +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)" +} + diff --git a/app/src/main/java/com/infomaniak/swisstransfer/di/SwissTransferInjectionModule.kt b/app/src/main/java/com/infomaniak/swisstransfer/di/SwissTransferInjectionModule.kt index c031732a8..4b97f730e 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/di/SwissTransferInjectionModule.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/di/SwissTransferInjectionModule.kt @@ -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 @@ -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