diff --git a/FlowCrypt/build.gradle.kts b/FlowCrypt/build.gradle.kts index 115884ad10..9ac672fcf5 100644 --- a/FlowCrypt/build.gradle.kts +++ b/FlowCrypt/build.gradle.kts @@ -5,6 +5,7 @@ import com.android.build.api.artifact.SingleArtifact +import com.android.build.api.dsl.ApplicationBuildType import com.android.build.api.variant.ResValue import com.android.ddmlib.DdmPreferences import java.io.FileInputStream @@ -21,9 +22,18 @@ plugins { id("com.starter.easylauncher") id("kotlin-parcelize") id("com.google.devtools.ksp") - id("org.ajoberstar.grgit") } +val gitCommitId = providers.exec { + workingDir(rootProject.rootDir) + commandLine("git", "rev-parse", "HEAD") +}.standardOutput.asText.map { it.trim().take(7) } + +val gitBranchName = providers.exec { + workingDir(rootProject.rootDir) + commandLine("git", "rev-parse", "--abbrev-ref", "HEAD") +}.standardOutput.asText.map { it.trim() } + val keystoreProperties = Properties() val propertiesFile = project.file("keystore.properties") if (propertiesFile.exists()) { @@ -105,25 +115,33 @@ android { signingConfig = signingConfigs.getByName("release") } - getByName("debug") { + // Shared by debug and uiTests. uiTests doesn't use initWith(debug) because overriding + // inherited resValues triggers the AGP RES_VALUE_REPLACED warning. + fun ApplicationBuildType.configureDebuggable(isHttpLogEnabled: Boolean) { isDebuggable = true - versionNameSuffix = "_" + - defaultConfig.versionCode + - "__" + SimpleDateFormat("yyyy_MM_dd").format(Date()) + - "__" + grgit.head().id.substring(0, 7) + isCrunchPngs = false applicationIdSuffix = ".debug" signingConfig = signingConfigs.getByName("debug") + val httpLogLevel = if (isHttpLogEnabled) "BODY" else "NONE" buildConfigField("boolean", "IS_ACRA_ENABLED", "false") - buildConfigField("boolean", "IS_HTTP_LOG_ENABLED", "true") - buildConfigField("String", "HTTP_LOG_LEVEL", "\"BODY\"") + buildConfigField("boolean", "IS_HTTP_LOG_ENABLED", isHttpLogEnabled.toString()) + buildConfigField("String", "HTTP_LOG_LEVEL", "\"$httpLogLevel\"") resValue("string", "gradle_is_acra_enabled", "false") - resValue("string", "gradle_is_http_log_enabled", "true") - resValue("string", "gradle_http_log_level", "BODY") + resValue("string", "gradle_is_http_log_enabled", isHttpLogEnabled.toString()) + resValue("string", "gradle_http_log_level", httpLogLevel) + } + + getByName("debug") { + configureDebuggable(isHttpLogEnabled = true) + versionNameSuffix = "_" + + defaultConfig.versionCode + + "__" + SimpleDateFormat("yyyy_MM_dd").format(Date()) + + "__" + gitCommitId.get() } create("uiTests") { - initWith(getByName("debug")) + configureDebuggable(isHttpLogEnabled = false) versionNameSuffix = "_test_" + defaultConfig.versionCode + "__" + SimpleDateFormat("yyyy_MM_dd").format(Date()) buildConfigField("String", "ATTESTER_URL", "\"https://flowcrypt.test/attester/\"") @@ -132,10 +150,6 @@ android { "SHARED_TENANT_FES_URL", "\"https://flowcrypt.test/shared-tenant-fes/\"" ) - buildConfigField("boolean", "IS_HTTP_LOG_ENABLED", "false") - buildConfigField("String", "HTTP_LOG_LEVEL", "\"NONE\"") - resValue("string", "gradle_is_http_log_enabled", "false") - resValue("string", "gradle_http_log_level", "NONE") } } @@ -419,8 +433,11 @@ easylauncher { } tasks.register("checkCorrectBranch") { - if (!grgit.branch.current().name.equals("master")) { - throw GradleException("Please use 'master' branch to generate a release build") + val branchName = gitBranchName + doLast { + if (branchName.get() != "master") { + throw GradleException("Please use 'master' branch to generate a release build") + } } } diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenDisallowUpdateRevokedKeyFlowTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenDisallowUpdateRevokedKeyFlowTest.kt index 4aa4e36b00..46231dd872 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenDisallowUpdateRevokedKeyFlowTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenDisallowUpdateRevokedKeyFlowTest.kt @@ -127,7 +127,7 @@ class ComposeScreenDisallowUpdateRevokedKeyFlowTest : BaseComposeScreenTest() { val existingRecipientAfter = roomDatabase.recipientDao() .getRecipientWithPubKeysByEmail(userWithRevokedKey) assertNotNull(existingRecipientAfter) - val pubKeyAfter = requireNotNull(existingRecipientBefore?.publicKeys?.first()?.publicKey) + val pubKeyAfter = requireNotNull(existingRecipientAfter).publicKeys.first().publicKey val pgpKeyDetailsAfter = PgpKey.parseKeys(pubKeyAfter) .pgpKeyRingCollection.pgpPublicKeyRingCollection.first().toPgpKeyRingDetails() assertTrue(pgpKeyDetailsAfter.isRevoked) diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenReplyAllFlowTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenReplyAllFlowTest.kt index 709b2f9be3..238cf4ec6e 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenReplyAllFlowTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/ComposeScreenReplyAllFlowTest.kt @@ -48,7 +48,7 @@ class ComposeScreenReplyAllFlowTest : BaseTest() { private val account = AccountDaoManager.getDefaultAccountDao() private val accountAliasesEntity = AccountAliasesEntity( email = account.email, - accountType = account.accountType ?: "", + accountType = account.accountType, sendAsEmail = "alias@flowcrypt.test", displayName = "Alias", isDefault = true, diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/base/BaseGmailApiTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/base/BaseGmailApiTest.kt index e6961557ec..c20a180f4f 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/base/BaseGmailApiTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/base/BaseGmailApiTest.kt @@ -448,7 +448,7 @@ abstract class BaseGmailApiTest(val accountEntity: AccountEntity = BASE_ACCOUNT_ append(it.first + ": " + it.second + "\n") } append("\n") - append(response.body?.string()) + append(response.body.string()) } responseMimeMultipart.addBodyPart( diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/okhttp/LoggingInFileInterceptor.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/okhttp/LoggingInFileInterceptor.kt index 5a3d297015..9b4bc75774 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/okhttp/LoggingInFileInterceptor.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/okhttp/LoggingInFileInterceptor.kt @@ -73,7 +73,7 @@ class LoggingInFileInterceptor constructor(context: Context, fileName: String) : var requestStartMsg = "--> " + request.method + ' '.toString() + request.url + ' '.toString() + protocol if (!logHeaders && hasRequestBody) { - requestStartMsg += " (" + requestBody!!.contentLength() + "-byte body)" + requestStartMsg += " (" + requestBody.contentLength() + "-byte body)" } logger.log(requestStartMsg) @@ -82,7 +82,7 @@ class LoggingInFileInterceptor constructor(context: Context, fileName: String) : // Request body headers are only present when installed as a network interceptor. // Force // them to be included (when available) so there values are known. - if (requestBody!!.contentType() != null) { + if (requestBody.contentType() != null) { logger.log("Content-Type: " + requestBody.contentType()!!) } if (requestBody.contentLength() != (-1).toLong()) { @@ -110,7 +110,7 @@ class LoggingInFileInterceptor constructor(context: Context, fileName: String) : logger.log("--> END " + request.method + " (encoded body omitted)") } else { val buffer = Buffer() - requestBody!!.writeTo(buffer) + requestBody.writeTo(buffer) var charset: Charset? = UTF8 val contentType = requestBody.contentType() @@ -146,7 +146,7 @@ class LoggingInFileInterceptor constructor(context: Context, fileName: String) : val tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs) val responseBody = response.body - val contentLength = responseBody?.contentLength() ?: 0 + val contentLength = responseBody.contentLength() val bodySize = if (contentLength != (-1).toLong()) "$contentLength-byte" else "unknown-length" logger.log( "<-- " + response.code + ' '.toString() + response.message @@ -168,7 +168,7 @@ class LoggingInFileInterceptor constructor(context: Context, fileName: String) : } else if (isBodyEncoded(response.headers)) { logger.log("<-- END HTTP (encoded body omitted)") } else { - val source = responseBody!!.source() + val source = responseBody.source() source.request(java.lang.Long.MAX_VALUE) // Buffer the entire body. val buffer = source.buffer diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/AccountAliasesDao.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/AccountAliasesDao.kt index 759a6b9f47..3149d60436 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/AccountAliasesDao.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/AccountAliasesDao.kt @@ -39,7 +39,7 @@ interface AccountAliasesDao : BaseDao { }.toSet() val existingAliases = getAliases( account = accountEntity.email, - accountType = accountEntity.accountType ?: "" + accountType = accountEntity.accountType ) val existingUniqueSendAsSet = existingAliases.map { entity -> entity.sendAsEmail?.lowercase() diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/com/google/api/services/gmail/model/SendAsExt.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/com/google/api/services/gmail/model/SendAsExt.kt index f945c4130f..c05dc76b8d 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/com/google/api/services/gmail/model/SendAsExt.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/extensions/com/google/api/services/gmail/model/SendAsExt.kt @@ -7,7 +7,6 @@ package com.flowcrypt.email.extensions.com.google.api.services.gmail.model import android.accounts.Account import com.flowcrypt.email.database.entity.AccountAliasesEntity -import com.flowcrypt.email.database.entity.AccountEntity import com.google.api.services.gmail.model.SendAs /** @@ -16,7 +15,7 @@ import com.google.api.services.gmail.model.SendAs fun SendAs.toAccountAliasesEntity(account: Account): AccountAliasesEntity { return AccountAliasesEntity( email = account.name.lowercase(), - accountType = account.type ?: AccountEntity.ACCOUNT_TYPE_GOOGLE, + accountType = account.type, sendAsEmail = sendAsEmail?.lowercase(), displayName = displayName, replyToAddress = replyToAddress, @@ -26,4 +25,4 @@ fun SendAs.toAccountAliasesEntity(account: Account): AccountAliasesEntity { treatAsAlias = treatAsAlias, verificationStatus = verificationStatus ) -} \ No newline at end of file +} diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/AccountAliasesViewModel.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/AccountAliasesViewModel.kt index 0c8fefbba7..a23281ac27 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/AccountAliasesViewModel.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/AccountAliasesViewModel.kt @@ -51,7 +51,7 @@ class AccountAliasesViewModel(application: Application) : AccountViewModel(appli val hasAliasesSignature = roomDatabase.accountAliasesDao().getAliases( account = accountEntity.email, - accountType = accountEntity.accountType ?: "" + accountType = accountEntity.accountType ).any { it.signature?.isNotEmpty() == true } if (!hasAliasesSignature) { diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/MessagesViewModel.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/MessagesViewModel.kt index 9bad8f7342..b22a0e42c4 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/MessagesViewModel.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/MessagesViewModel.kt @@ -398,9 +398,7 @@ class MessagesViewModel(application: Application) : AccountViewModel(application if (isOnlyPgpModeEnabled == true) { foundMsgs = imapFolder.search(EmailUtil.genPgpThingsSearchTerm(accountEntity)) - foundMsgs?.let { - msgsCount = foundMsgs.size - } + msgsCount = foundMsgs.size } else { msgsCount = imapFolder.messageCount } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/RefreshPrivateKeysFromEkmViewModel.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/RefreshPrivateKeysFromEkmViewModel.kt index 2090370cd5..25b84232f2 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/RefreshPrivateKeysFromEkmViewModel.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/RefreshPrivateKeysFromEkmViewModel.kt @@ -96,10 +96,10 @@ class RefreshPrivateKeysFromEkmViewModel(application: Application) : AccountView } } - requireNotNull(ekmPrivateResult.data?.privateKeys) + val privateKeys = requireNotNull(ekmPrivateResult.data?.privateKeys) val pgpKeyRingDetailsList = mutableListOf() - ekmPrivateResult.data?.privateKeys?.forEach { key -> + privateKeys.forEach { key -> val parsedList = PgpKey.parsePrivateKeys(requireNotNull(key.decryptedPrivateKey)) .map { it.copy( diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/ThreadDetailsViewModel.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/ThreadDetailsViewModel.kt index bc98354ae6..5e7eae6a0a 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/ThreadDetailsViewModel.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/ThreadDetailsViewModel.kt @@ -608,7 +608,7 @@ class ThreadDetailsViewModel( return@collectLatest } else { loadMessagesManuallyMutableStateFlow.update { - val existingValue = existingResult.data ?: Data(false, emptyList()) + val existingValue = existingResult.data val updatedList = existingValue.list.toMutableList().apply { replaceAll { item -> if (item.type == MessagesInThreadListAdapter.Type.HEADER) { @@ -732,4 +732,4 @@ class ThreadDetailsViewModel( companion object { val FROM = FROM() } -} \ No newline at end of file +} diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/providers/EmbeddedAttachmentsProvider.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/providers/EmbeddedAttachmentsProvider.kt index 35af0ac35d..786ad9a7e9 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/providers/EmbeddedAttachmentsProvider.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/providers/EmbeddedAttachmentsProvider.kt @@ -111,8 +111,8 @@ class EmbeddedAttachmentsProvider : DocumentsProvider() { val maxMemory = Runtime.getRuntime().maxMemory() val cacheSize = max(maxMemory / 4, FileUtils.ONE_MB * 25).toInt() lruCache = object : LruCache(cacheSize) { - override fun sizeOf(key: String, attachmentInfo: AttachmentInfo): Int { - return attachmentInfo.rawData?.size ?: attachmentInfo.encodedSize.toInt() + override fun sizeOf(key: String, value: AttachmentInfo): Int { + return value.rawData?.size ?: value.encodedSize.toInt() } } } @@ -177,4 +177,4 @@ class EmbeddedAttachmentsProvider : DocumentsProvider() { } } } -} \ No newline at end of file +} diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreateMessageFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreateMessageFragment.kt index 9b3927197c..32e0d9e2c8 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreateMessageFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CreateMessageFragment.kt @@ -1984,7 +1984,7 @@ class CreateMessageFragment : BaseFragment(), "unknown RecipientType: ${autoCompleteResults?.recipientType}" ) } - val pattern = it.data?.pattern?.lowercase() ?: "" + val pattern = autoCompleteResults.pattern.lowercase() val autoCompleteList = results.map { recipientWithPubKeys -> AutoCompleteResultRecyclerViewAdapter.AutoCompleteItem( @@ -2017,12 +2017,12 @@ class CreateMessageFragment : BaseFragment(), } } - val adapter = when (autoCompleteResults?.recipientType) { + val adapter = when (autoCompleteResults.recipientType) { Message.RecipientType.TO -> toAutoCompleteResultRecyclerViewAdapter Message.RecipientType.CC -> ccAutoCompleteResultRecyclerViewAdapter Message.RecipientType.BCC -> bccAutoCompleteResultRecyclerViewAdapter else -> throw InvalidObjectException( - "unknown RecipientType: ${autoCompleteResults?.recipientType}" + "unknown RecipientType: ${autoCompleteResults.recipientType}" ) } adapter.submitList(finalList) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ThreadDetailsFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ThreadDetailsFragment.kt index 674954e964..86498e7f9a 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ThreadDetailsFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ThreadDetailsFragment.kt @@ -638,9 +638,9 @@ class ThreadDetailsFragment : BaseFragment(), Prog val hasUnverifiedSignatures = message.incomingMessageInfo?.verificationResult?.hasUnverifiedSignatures == true val hasActiveSignatureVerification = if (hasUnverifiedSignatures) { - val messageFromAddresses = message.incomingMessageInfo?.getFrom()?.map { + val messageFromAddresses = message.incomingMessageInfo.getFrom().map { it.address.lowercase() - } ?: emptyList() + } val alreadyCheckedFromAddresses = threadDetailsViewModel.sessionFromRecipientsStateFlow.value.filter { @@ -1592,4 +1592,4 @@ class ThreadDetailsFragment : BaseFragment(), Prog private const val CONTENT_MAX_ALLOWED_LENGTH = 50000 } -} \ No newline at end of file +} diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/InfoDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/InfoDialogFragment.kt index 4b48f0046a..ba02c83df7 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/InfoDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/InfoDialogFragment.kt @@ -82,7 +82,7 @@ class InfoDialogFragment : BaseDialogFragment() { override fun onResume() { super.onResume() if (!args.useWebViewToRender) { - val textView = dialog?.window?.decorView?.findViewById(android.R.id.message) as? TextView + val textView = dialog?.window?.decorView?.findViewById(android.R.id.message) textView?.setTextIsSelectable(true) } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/MsgsPagedListAdapter.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/MsgsPagedListAdapter.kt index 4b33a6080e..3771d2f154 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/MsgsPagedListAdapter.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/adapter/MsgsPagedListAdapter.kt @@ -443,9 +443,6 @@ class MsgsPagedListAdapter(private val onMessageClickListener: OnMessageClickLis MessageState.ERROR_PASSWORD_PROTECTED -> state = context.getString(R.string.can_not_send_password_protected) - - else -> { - } } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/util/ProgressOutputStream.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/util/ProgressOutputStream.kt index 706bcf439d..d2887ff671 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/util/ProgressOutputStream.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/util/ProgressOutputStream.kt @@ -15,7 +15,7 @@ import java.io.OutputStream * * @author Denys Bondarenko */ -class ProgressOutputStream(val out: OutputStream) : BufferedOutputStream(out) { +class ProgressOutputStream(out: OutputStream) : BufferedOutputStream(out) { override fun write(b: ByteArray) { if (Thread.interrupted()) { throw SyncTaskTerminatedException() diff --git a/build.gradle.kts b/build.gradle.kts index 21bf218112..f262decbd2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,9 +8,10 @@ apply(from = "$rootDir/ext.gradle.kts") plugins { id("com.android.application") version "9.5.1" apply false + // Safe Args still emits casts suppressed as CAST_NEVER_SUCCEEDS; Kotlin reports them as + // UNSAFE_CAST_RELYING_ON_NULL. Keep these warnings visible until the generator is fixed. id("androidx.navigation.safeargs.kotlin") version "2.10.2" apply false id("com.starter.easylauncher") version "6.4.1" apply false id("org.jetbrains.kotlin.plugin.parcelize") version "2.4.21" apply false - id("com.google.devtools.ksp") version "2.3.13" apply false - id("org.ajoberstar.grgit") version "5.3.3" apply false + id("com.google.devtools.ksp") version "2.3.14" apply false }