From ccc98665852e3bdc7c7ea377234a2340ae1539ee Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Tue, 17 Dec 2024 17:23:17 +0100 Subject: [PATCH 1/2] feat: Add UserAgentUtils --- .../com/infomaniak/core2/UserAgentUtils.kt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Core2/src/main/java/com/infomaniak/core2/UserAgentUtils.kt 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)" +} + From d629aa09944113b0d67d6d0cb59598c7d0d777cf Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Tue, 17 Dec 2024 17:23:46 +0100 Subject: [PATCH 2/2] feat: Use the official userAgent --- .../swisstransfer/di/SwissTransferInjectionModule.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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