Only use apk uploadTimestamp for non-website builds.

Relates to #13273
This commit is contained in:
Greyson Parrelli
2023-12-04 10:47:31 -05:00
parent 4320d26a3d
commit d58c3292d7
2 changed files with 11 additions and 2 deletions

View File

@@ -20,6 +20,7 @@ import org.thoughtcrime.securesms.apkupdate.ApkUpdateDownloadManagerReceiver
import org.thoughtcrime.securesms.jobmanager.Job
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.util.Environment
import org.thoughtcrime.securesms.util.FileUtils
import org.thoughtcrime.securesms.util.JsonUtils
import java.io.FileInputStream
@@ -81,8 +82,7 @@ class ApkUpdateJob private constructor(parameters: Parameters) : BaseJob(paramet
Log.d(TAG, "Got descriptor: $updateDescriptor")
}
val currentVersionCode = getCurrentAppVersionCode()
if (updateDescriptor.versionCode > currentVersionCode || (updateDescriptor.versionCode == currentVersionCode && (updateDescriptor.uploadTimestamp ?: 0) > SignalStore.apkUpdate().lastApkUploadTime)) {
if (shouldUpdate(getCurrentAppVersionCode(), updateDescriptor, SignalStore.apkUpdate().lastApkUploadTime, Environment.IS_WEBSITE)) {
Log.i(TAG, "Newer version code available. Current: (versionCode: ${getCurrentAppVersionCode()}, uploadTime: ${SignalStore.apkUpdate().lastApkUploadTime}), Update: (versionCode: ${updateDescriptor.versionCode}, uploadTime: ${updateDescriptor.uploadTimestamp})")
val digest: ByteArray = Hex.fromStringCondensed(updateDescriptor.digest)
val downloadStatus: DownloadStatus = getDownloadStatus(updateDescriptor.url, digest)
@@ -206,6 +206,14 @@ class ApkUpdateJob private constructor(parameters: Parameters) : BaseJob(paramet
}
}
private fun shouldUpdate(currentVersionCode: Int, updateDescriptor: UpdateDescriptor, lastApkUploadTime: Long, isWebsite: Boolean): Boolean {
return if (isWebsite) {
return updateDescriptor.versionCode > currentVersionCode
} else {
return updateDescriptor.versionCode > currentVersionCode || (updateDescriptor.versionCode == currentVersionCode && (updateDescriptor.uploadTimestamp ?: 0) > lastApkUploadTime)
}
}
private data class UpdateDescriptor(
@JsonProperty
val versionCode: Int = 0,

View File

@@ -9,6 +9,7 @@ object Environment {
const val IS_STAGING: Boolean = BuildConfig.BUILD_ENVIRONMENT_TYPE == "Staging" || BuildConfig.BUILD_ENVIRONMENT_TYPE == "Pnp"
const val IS_PNP: Boolean = BuildConfig.BUILD_ENVIRONMENT_TYPE == "Pnp"
const val IS_NIGHTLY: Boolean = BuildConfig.BUILD_DISTRIBUTION_TYPE == "nightly"
const val IS_WEBSITE: Boolean = BuildConfig.BUILD_DISTRIBUTION_TYPE == "website"
object Donations {
@JvmStatic