Skip to content

Reproducible build #2911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
initializeComponent(TracingInitializer::class.java)
initializeComponent(CacheCleanerInitializer::class.java)
}
logApplicationInfo()
logApplicationInfo(this)

Check warning on line 39 in app/src/main/kotlin/io/element/android/x/ElementXApplication.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/io/element/android/x/ElementXApplication.kt#L39

Added line #L39 was not covered by tests
}
}
3 changes: 2 additions & 1 deletion app/src/main/kotlin/io/element/android/x/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.element.android.appconfig.ApplicationConfig
import io.element.android.features.messages.impl.timeline.components.customreaction.DefaultEmojibaseProvider
import io.element.android.features.messages.impl.timeline.components.customreaction.EmojibaseProvider
import io.element.android.libraries.androidutils.system.getVersionCodeFromManifest
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.core.meta.BuildMeta
import io.element.android.libraries.core.meta.BuildType
Expand Down Expand Up @@ -87,7 +88,7 @@
// TODO EAx Config.LOW_PRIVACY_LOG_ENABLE,
lowPrivacyLoggingEnabled = false,
versionName = BuildConfig.VERSION_NAME,
versionCode = BuildConfig.VERSION_CODE,
versionCode = context.getVersionCodeFromManifest(),

Check warning on line 91 in app/src/main/kotlin/io/element/android/x/di/AppModule.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/io/element/android/x/di/AppModule.kt#L91

Added line #L91 was not covered by tests
gitRevision = BuildConfig.GIT_REVISION,
gitBranchName = BuildConfig.GIT_BRANCH_NAME,
flavorDescription = BuildConfig.FLAVOR_DESCRIPTION,
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/kotlin/io/element/android/x/info/Logs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@

package io.element.android.x.info

import android.content.Context
import io.element.android.libraries.androidutils.system.getVersionCodeFromManifest
import io.element.android.x.BuildConfig
import timber.log.Timber
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

fun logApplicationInfo() {
fun logApplicationInfo(context: Context) {
val appVersion = buildString {
append(BuildConfig.VERSION_NAME)
append(" (")
append(BuildConfig.VERSION_CODE)
append(context.getVersionCodeFromManifest())

Check warning on line 31 in app/src/main/kotlin/io/element/android/x/info/Logs.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/io/element/android/x/info/Logs.kt#L31

Added line #L31 was not covered by tests
append(") - ")
append(BuildConfig.BUILD_TYPE)
append(" / ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import androidx.activity.result.ActivityResultLauncher
import androidx.annotation.ChecksSdkIntAtLeast
import androidx.annotation.RequiresApi
import androidx.core.content.pm.PackageInfoCompat
import io.element.android.libraries.androidutils.R
import io.element.android.libraries.androidutils.compat.getApplicationInfoCompat
import io.element.android.libraries.core.mimetype.MimeTypes
Expand All @@ -47,6 +48,19 @@
}
}

/**
* Retrieve the versionCode from the Manifest.
* The value is more accurate than BuildConfig.VERSION_CODE, as it is correct according to the
* computation in the `androidComponents` block of the app build.gradle.kts file.
* In other words, the last digit (for the architecture) will be set, whereas BuildConfig.VERSION_CODE
* last digit will always be 0.
*/
fun Context.getVersionCodeFromManifest(): Long {
return PackageInfoCompat.getLongVersionCode(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure it does work for every OS and with R8?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think R8 will remove this from the manifest, since it's used by the system to manage application upgrade.

packageManager.getPackageInfo(packageName, 0)

Check warning on line 60 in libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt

View check run for this annotation

Codecov / codecov/patch

libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt#L59-L60

Added lines #L59 - L60 were not covered by tests
)
}

// ==============================================================================================================
// Clipboard helper
// ==============================================================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ data class BuildMeta(
val applicationId: String,
val lowPrivacyLoggingEnabled: Boolean,
val versionName: String,
val versionCode: Int,
val versionCode: Long,
val gitRevision: String,
val gitBranchName: String,
val flavorDescription: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fun aBuildMeta(
applicationId: String = "",
lowPrivacyLoggingEnabled: Boolean = true,
versionName: String = "",
versionCode: Int = 0,
versionCode: Long = 0,
gitRevision: String = "",
gitBranchName: String = "",
flavorDescription: String = "",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.element.android.tests.konsist

import com.lemonappdev.konsist.api.Konsist
import com.lemonappdev.konsist.api.ext.list.withImportNamed
import com.lemonappdev.konsist.api.verify.assertFalse
import org.junit.Test

class KonsistContentTest {
@Test
fun `assert that BuildConfig dot VersionCode is not used`() {
Konsist
.scopeFromProduction()
.files
.withImportNamed("io.element.android.x.BuildConfig")
.assertFalse(additionalMessage = "Please do not use BuildConfig.VERSION_CODE, but use the versionCode from BuildMeta") {
it.text.contains("BuildConfig.VERSION_CODE")
}
}
}
Loading