From 716c0ba78b774ceb284218989837d12ea6edf570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Zag=C3=B3rski?= Date: Tue, 8 Oct 2024 16:56:16 +0200 Subject: [PATCH 1/2] chore: Update app version name #WPB-11429 --- .../ui/settings/about/AboutThisAppScreen.kt | 4 +-- .../ui/settings/about/AboutThisAppState.kt | 3 +- .../settings/about/AboutThisAppViewModel.kt | 28 ++++++++++++++++++- .../AndroidApplicationConventionPlugin.kt | 2 +- .../src/main/kotlin/AndroidCoordinates.kt | 19 ------------- .../src/main/kotlin/AppVersionPlugin.kt | 2 +- .../main/kotlin/scripts/variants.gradle.kts | 1 - 7 files changed, 33 insertions(+), 26 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppScreen.kt b/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppScreen.kt index ab76ad9d666..cc43dba8bcd 100644 --- a/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppScreen.kt +++ b/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppScreen.kt @@ -159,7 +159,7 @@ private fun AboutThisAppContent( ) SettingsItem( title = stringResource(R.string.app_version), - text = BuildConfig.VERSION_NAME, + text = state.appName, trailingIcon = R.drawable.ic_copy, onIconPressed = Clickable( enabled = true, @@ -210,7 +210,7 @@ data class AboutThisAppContentState( @Composable private fun PreviewAboutThisAppScreen() = WireTheme { AboutThisAppContent( - state = AboutThisAppState(commitish = "abcd-1234"), + state = AboutThisAppState(commitish = "abcd-1234", appName = "4.1.9-1234-beta"), onBackPressed = { }, onItemClicked = { } ) diff --git a/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppState.kt b/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppState.kt index 0743f21380a..2e3b45916ee 100644 --- a/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppState.kt +++ b/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppState.kt @@ -18,5 +18,6 @@ package com.wire.android.ui.settings.about data class AboutThisAppState( - val commitish: String = "null" + val commitish: String = "null", + val appName: String ) diff --git a/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppViewModel.kt index 9377b8d4731..95a2378ce15 100644 --- a/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppViewModel.kt @@ -23,6 +23,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.wire.android.BuildConfig import com.wire.android.util.getGitBuildId import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext @@ -35,7 +36,9 @@ class AboutThisAppViewModel @Inject constructor( ) : ViewModel() { var state by mutableStateOf( - AboutThisAppState() + AboutThisAppState( + appName = createAppName() + ) ) init { @@ -50,4 +53,27 @@ class AboutThisAppViewModel @Inject constructor( ) } } + + private fun createAppName(): String { + return "${BuildConfig.VERSION_NAME}-${leastSignificantVersionCode()}-${BuildConfig.FLAVOR}" + } + + /** + * The last 5 digits of the VersionCode. From 0 to 99_999. + * It's an [Int], so it can be less than 5 digits when doing [toString], of course. + * Considering versionCode bumps every 5min, these are + * 288 per day + * 8640 per month + * 51840 per semester + * 103_680 per year. ~99_999 + * + * So it takes almost a whole year until it rotates back. + * It's very unlikely that two APKs with the same version (_e.g._ 4.8.0) + * will have the same [leastSignificantVersionCode], + * unless they are build almost one year apart. + */ + @Suppress("MagicNumber") + private fun leastSignificantVersionCode(): Int { + return BuildConfig.VERSION_CODE % 100_000 + } } diff --git a/build-logic/plugins/src/main/kotlin/AndroidApplicationConventionPlugin.kt b/build-logic/plugins/src/main/kotlin/AndroidApplicationConventionPlugin.kt index f4cea6ec10a..fac758e9078 100644 --- a/build-logic/plugins/src/main/kotlin/AndroidApplicationConventionPlugin.kt +++ b/build-logic/plugins/src/main/kotlin/AndroidApplicationConventionPlugin.kt @@ -40,7 +40,7 @@ class AndroidApplicationConventionPlugin : Plugin { applicationId = AndroidApp.id defaultConfig.targetSdk = AndroidSdk.target versionCode = AndroidApp.versionCode - versionName = "${AndroidApp.versionName}-${AndroidApp.leastSignificantVersionCode}" + versionName = AndroidApp.versionName setProperty("archivesBaseName", "$applicationId-v$versionName") } diff --git a/build-logic/plugins/src/main/kotlin/AndroidCoordinates.kt b/build-logic/plugins/src/main/kotlin/AndroidCoordinates.kt index a93b618ee19..0309d16ccd2 100644 --- a/build-logic/plugins/src/main/kotlin/AndroidCoordinates.kt +++ b/build-logic/plugins/src/main/kotlin/AndroidCoordinates.kt @@ -35,23 +35,4 @@ object AndroidApp { fun setRootDir(rootDir: File) { this._rootDir = rootDir } - - /** - * The last 5 digits of the VersionCode. From 0 to 99_999. - * It's an [Int], so it can be less than 5 digits when doing [toString], of course. - * Considering versionCode bumps every 5min, these are - * 288 per day - * 8640 per month - * 51840 per semester - * 103_680 per year. ~99_999 - * - * So it takes almost a whole year until it rotates back. - * It's very unlikely that two APKs with the same version (_e.g._ 4.8.0) - * will have the same [leastSignificantVersionCode], - * unless they are build almost one year apart. - */ - @Suppress("MagicNumber") - val leastSignificantVersionCode by lazy { - versionCode % 100_000 - } } diff --git a/build-logic/plugins/src/main/kotlin/AppVersionPlugin.kt b/build-logic/plugins/src/main/kotlin/AppVersionPlugin.kt index 3a711f2d616..bf5e3f1fc72 100644 --- a/build-logic/plugins/src/main/kotlin/AppVersionPlugin.kt +++ b/build-logic/plugins/src/main/kotlin/AppVersionPlugin.kt @@ -35,7 +35,7 @@ class AppVersionPlugin : Plugin { val currentTime = LocalDateTime.now() val versnisor = Versionizer(projectDir, currentTime) val versionCode = versnisor.versionCode - val versionName = "${AndroidApp.versionName}-${AndroidApp.leastSignificantVersionCode}-fdroid" + val versionName = AndroidApp.versionName val buildTime = currentTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) ?: error("Failed to get build time") val appName = "com.wire" // git commit hash code diff --git a/buildSrc/src/main/kotlin/scripts/variants.gradle.kts b/buildSrc/src/main/kotlin/scripts/variants.gradle.kts index 39c22e4e103..2628eccfaa7 100644 --- a/buildSrc/src/main/kotlin/scripts/variants.gradle.kts +++ b/buildSrc/src/main/kotlin/scripts/variants.gradle.kts @@ -62,7 +62,6 @@ fun NamedDomainObjectContainer.createAppFlavour( create(flavour.buildName) { dimension = flavour.dimensions applicationId = flavorApplicationId - versionNameSuffix = "-${flavour.buildName}" resValue("string", "app_name", flavour.appName) manifestPlaceholders["sharedUserId"] = sharedUserId manifestPlaceholders["appAuthRedirectScheme"] = flavorApplicationId From 8239643c71f515cea5be165c6530e46e20f83b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Zag=C3=B3rski?= Date: Wed, 9 Oct 2024 18:08:33 +0200 Subject: [PATCH 2/2] fix: Code review --- .../com/wire/android/WireApplication.kt | 3 +- .../wire/android/migration/UpdateReceiver.kt | 4 +- .../com/wire/android/ui/debug/DebugScreen.kt | 3 +- .../ui/settings/about/AboutThisAppScreen.kt | 3 +- .../settings/about/AboutThisAppViewModel.kt | 27 +---------- .../com/wire/android/util/AppNameUtil.kt | 46 +++++++++++++++++++ .../com/wire/android/util/EmailComposer.kt | 3 +- .../wire/android/util/UserAgentProvider.kt | 3 +- 8 files changed, 57 insertions(+), 35 deletions(-) create mode 100644 app/src/main/kotlin/com/wire/android/util/AppNameUtil.kt diff --git a/app/src/main/kotlin/com/wire/android/WireApplication.kt b/app/src/main/kotlin/com/wire/android/WireApplication.kt index 764acbd3c4f..0b3e9f223aa 100644 --- a/app/src/main/kotlin/com/wire/android/WireApplication.kt +++ b/app/src/main/kotlin/com/wire/android/WireApplication.kt @@ -36,6 +36,7 @@ import com.wire.android.feature.analytics.AnonymousAnalyticsRecorderImpl import com.wire.android.feature.analytics.globalAnalyticsManager import com.wire.android.feature.analytics.model.AnalyticsEvent import com.wire.android.feature.analytics.model.AnalyticsSettings +import com.wire.android.util.AppNameUtil import com.wire.android.util.CurrentScreenManager import com.wire.android.util.DataDogLogger import com.wire.android.util.LogFileWriter @@ -240,7 +241,7 @@ class WireApplication : BaseApp() { appLogger.d( """ > Device info: - App version=${BuildConfig.VERSION_NAME} + App version=${AppNameUtil.createAppName()} OS version=${Build.VERSION.SDK_INT} Phone model=${Build.BRAND}/${Build.MODEL} Commit hash=${applicationContext.getGitBuildId()} diff --git a/app/src/main/kotlin/com/wire/android/migration/UpdateReceiver.kt b/app/src/main/kotlin/com/wire/android/migration/UpdateReceiver.kt index 4d3387e5ef8..6bcb55155c7 100644 --- a/app/src/main/kotlin/com/wire/android/migration/UpdateReceiver.kt +++ b/app/src/main/kotlin/com/wire/android/migration/UpdateReceiver.kt @@ -21,8 +21,8 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import androidx.work.WorkManager -import com.wire.android.BuildConfig import com.wire.android.appLogger +import com.wire.android.util.AppNameUtil import com.wire.android.util.dispatchers.DispatcherProvider import com.wire.android.workmanager.worker.enqueueMigrationWorker import dagger.hilt.android.AndroidEntryPoint @@ -46,7 +46,7 @@ class UpdateReceiver : BroadcastReceiver() { } override fun onReceive(context: Context, intent: Intent?) { - appLogger.i("App updated to ${BuildConfig.VERSION_NAME}") + appLogger.i("App updated to ${AppNameUtil.createAppName()}") scope.launch { if (migrationManager.shouldMigrate()) { appLogger.i("Migration worker enqueued") diff --git a/app/src/main/kotlin/com/wire/android/ui/debug/DebugScreen.kt b/app/src/main/kotlin/com/wire/android/ui/debug/DebugScreen.kt index 5fa57d82b8a..97d6e55cbd9 100644 --- a/app/src/main/kotlin/com/wire/android/ui/debug/DebugScreen.kt +++ b/app/src/main/kotlin/com/wire/android/ui/debug/DebugScreen.kt @@ -48,6 +48,7 @@ import com.wire.android.navigation.WireDestination import com.wire.android.ui.common.topappbar.NavigationIconType import com.wire.android.ui.common.topappbar.WireCenterAlignedTopAppBar import com.wire.android.ui.destinations.MigrationScreenDestination +import com.wire.android.util.AppNameUtil import com.wire.android.util.getMimeType import com.wire.android.util.getUrisOfFilesInDirectory import com.wire.android.util.multipleFileSharingIntent @@ -103,7 +104,7 @@ internal fun UserDebugContent( onShareLogs = debugContentState::shareLogs, ) DebugDataOptions( - appVersion = BuildConfig.VERSION_NAME, + appVersion = AppNameUtil.createAppName(), buildVariant = "${BuildConfig.FLAVOR}${BuildConfig.BUILD_TYPE.replaceFirstChar { it.uppercase() }}", onCopyText = debugContentState::copyToClipboard, onManualMigrationPressed = onManualMigrationPressed diff --git a/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppScreen.kt b/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppScreen.kt index cc43dba8bcd..cd24240be1c 100644 --- a/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppScreen.kt +++ b/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppScreen.kt @@ -35,7 +35,6 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.AnnotatedString import androidx.hilt.navigation.compose.hiltViewModel import com.ramcosta.composedestinations.annotation.RootNavGraph -import com.wire.android.BuildConfig import com.wire.android.R import com.wire.android.model.Clickable import com.wire.android.navigation.NavigationCommand @@ -164,7 +163,7 @@ private fun AboutThisAppContent( onIconPressed = Clickable( enabled = true, onClick = { - aboutThisAppContentState.copyToClipboard(BuildConfig.VERSION_NAME) + aboutThisAppContentState.copyToClipboard(state.appName) } ) ) diff --git a/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppViewModel.kt index 95a2378ce15..523c2e69765 100644 --- a/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/settings/about/AboutThisAppViewModel.kt @@ -23,7 +23,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.wire.android.BuildConfig +import com.wire.android.util.AppNameUtil import com.wire.android.util.getGitBuildId import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext @@ -37,7 +37,7 @@ class AboutThisAppViewModel @Inject constructor( var state by mutableStateOf( AboutThisAppState( - appName = createAppName() + appName = AppNameUtil.createAppName() ) ) @@ -53,27 +53,4 @@ class AboutThisAppViewModel @Inject constructor( ) } } - - private fun createAppName(): String { - return "${BuildConfig.VERSION_NAME}-${leastSignificantVersionCode()}-${BuildConfig.FLAVOR}" - } - - /** - * The last 5 digits of the VersionCode. From 0 to 99_999. - * It's an [Int], so it can be less than 5 digits when doing [toString], of course. - * Considering versionCode bumps every 5min, these are - * 288 per day - * 8640 per month - * 51840 per semester - * 103_680 per year. ~99_999 - * - * So it takes almost a whole year until it rotates back. - * It's very unlikely that two APKs with the same version (_e.g._ 4.8.0) - * will have the same [leastSignificantVersionCode], - * unless they are build almost one year apart. - */ - @Suppress("MagicNumber") - private fun leastSignificantVersionCode(): Int { - return BuildConfig.VERSION_CODE % 100_000 - } } diff --git a/app/src/main/kotlin/com/wire/android/util/AppNameUtil.kt b/app/src/main/kotlin/com/wire/android/util/AppNameUtil.kt new file mode 100644 index 00000000000..1007a450184 --- /dev/null +++ b/app/src/main/kotlin/com/wire/android/util/AppNameUtil.kt @@ -0,0 +1,46 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * 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.wire.android.util + +import com.wire.android.BuildConfig + +internal object AppNameUtil { + + fun createAppName(): String { + return "${BuildConfig.VERSION_NAME}-${leastSignificantVersionCode()}-${BuildConfig.FLAVOR}" + } + + /** + * The last 5 digits of the VersionCode. From 0 to 99_999. + * It's an [Int], so it can be less than 5 digits when doing [toString], of course. + * Considering versionCode bumps every 5min, these are + * 288 per day + * 8640 per month + * 51840 per semester + * 103_680 per year. ~99_999 + * + * So it takes almost a whole year until it rotates back. + * It's very unlikely that two APKs with the same version (_e.g._ 4.8.0) + * will have the same [leastSignificantVersionCode], + * unless they are build almost one year apart. + */ + @Suppress("MagicNumber") + private fun leastSignificantVersionCode(): Int { + return BuildConfig.VERSION_CODE % 100_000 + } +} diff --git a/app/src/main/kotlin/com/wire/android/util/EmailComposer.kt b/app/src/main/kotlin/com/wire/android/util/EmailComposer.kt index 3f21a0ba1e8..3d3f41d01e9 100644 --- a/app/src/main/kotlin/com/wire/android/util/EmailComposer.kt +++ b/app/src/main/kotlin/com/wire/android/util/EmailComposer.kt @@ -19,7 +19,6 @@ package com.wire.android.util import android.os.Build -import com.wire.android.BuildConfig import java.util.Date sealed interface EmailComposer { @@ -52,7 +51,7 @@ sealed interface EmailComposer { private fun emailDebugHeader(deviceHash: String?, commitHash: String? = "unavailable"): String = """ --- DO NOT EDIT--- - App Version: ${BuildConfig.VERSION_NAME} + App Version: ${AppNameUtil.createAppName()} Device Hash: $deviceHash Device: ${Build.MANUFACTURER} - ${Build.MODEL} SDK: ${Build.VERSION.RELEASE} diff --git a/app/src/main/kotlin/com/wire/android/util/UserAgentProvider.kt b/app/src/main/kotlin/com/wire/android/util/UserAgentProvider.kt index 47589459a83..93d4d7f5243 100644 --- a/app/src/main/kotlin/com/wire/android/util/UserAgentProvider.kt +++ b/app/src/main/kotlin/com/wire/android/util/UserAgentProvider.kt @@ -19,7 +19,6 @@ package com.wire.android.util import android.content.Context import android.os.Build -import com.wire.android.BuildConfig import dagger.hilt.android.qualifiers.ApplicationContext import javax.inject.Inject import javax.inject.Singleton @@ -28,7 +27,7 @@ import javax.inject.Singleton class UserAgentProvider @Inject constructor(@ApplicationContext private val context: Context) { val defaultUserAgent = - "Wire/${BuildConfig.VERSION_NAME}/${context.getGitBuildId()}/${getAndroidVersion()}" + "Wire/${AppNameUtil.createAppName()}/${context.getGitBuildId()}/${getAndroidVersion()}" private fun getAndroidVersion(): String { val sdkVersion: Int = Build.VERSION.SDK_INT