From a347210038147bff2ca18f8da25facfeb38bc2c2 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Mon, 17 Mar 2025 08:15:15 +0100 Subject: [PATCH] Update UA dynamically --- .gitlab-ci.yml | 1 + app/build.gradle | 9 +++++++++ .../foundation/e/apps/di/network/InterceptorModule.kt | 6 ++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e87882958..1412420da 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,6 +18,7 @@ stages: before_script: - export GRADLE_USER_HOME=$(pwd)/.gradle - chmod +x ./gradlew + - echo user_agent=$USER_AGENT > local.properties cache: key: ${CI_PROJECT_ID} diff --git a/app/build.gradle b/app/build.gradle index d33029fdb..0395991f7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -111,6 +111,7 @@ android { buildConfigField "String", "BUILD_ID", "\"${getGitHash() + "." + getDate()}\"" buildConfigField("String", "SENTRY_DSN", "\"${getSentryDsn()}\"") + buildConfigField "String", "USER_AGENT", "\"${retrieveKey("user_agent", "Dalvik/2.1.0 (Linux; U; Android %s)")}\"" def parentalControlPkgName = "foundation.e.parentalcontrol" @@ -331,3 +332,11 @@ dependencies { // JSoup implementation(libs.jsoup) } + +def retrieveKey(String keyName, String defaultValue) { + Properties properties = new Properties() + properties.load(project.rootProject.file('local.properties').newDataInputStream()) + + return properties.getProperty(keyName, defaultValue) +} + diff --git a/app/src/main/java/foundation/e/apps/di/network/InterceptorModule.kt b/app/src/main/java/foundation/e/apps/di/network/InterceptorModule.kt index b01b87c55..e5ba08cf7 100644 --- a/app/src/main/java/foundation/e/apps/di/network/InterceptorModule.kt +++ b/app/src/main/java/foundation/e/apps/di/network/InterceptorModule.kt @@ -18,6 +18,7 @@ package foundation.e.apps.di.network +import android.annotation.SuppressLint import android.os.Build import dagger.Module import dagger.Provides @@ -36,8 +37,9 @@ class InterceptorModule { companion object { private const val HEADER_USER_AGENT = "User-Agent" private const val HEADER_ACCEPT_LANGUAGE = "Accept-Language" - val HEADER_USER_AGENT_VALUE = - "Dalvik/2.1.0 (Linux; U; Android ${Build.VERSION.RELEASE};)" + + @SuppressLint("StringFormatTrivial") + val HEADER_USER_AGENT_VALUE = String.format(BuildConfig.USER_AGENT, Build.VERSION.RELEASE) } @Singleton -- GitLab