Skip to content
Open
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
34 changes: 34 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

128 changes: 80 additions & 48 deletions FlowCrypt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
*/


import com.android.build.api.artifact.SingleArtifact
import com.android.build.api.variant.ResValue
import org.gradle.api.GradleException
import java.io.File
import com.android.ddmlib.DdmPreferences
import java.io.FileInputStream
import java.text.SimpleDateFormat
Expand All @@ -15,7 +19,6 @@ DdmPreferences.setTimeOut(10 * 60 * 1000)

plugins {
id("com.android.application")
id("kotlin-android")
id("androidx.navigation.safeargs.kotlin")
id("com.starter.easylauncher")
id("kotlin-parcelize")
Expand All @@ -30,7 +33,7 @@ if (propertiesFile.exists()) {
}

android {
compileSdk = extra["compileSdkVersion"] as Int
compileSdk = rootProject.extra["compileSdkVersion"] as Int
namespace = "com.flowcrypt.email"

defaultConfig {
Expand All @@ -42,10 +45,10 @@ android {
testInstrumentationRunnerArguments += mapOf("clearPackageData" to "true")

applicationId = "com.flowcrypt.email"
minSdk = extra["minSdkVersion"] as Int
targetSdk = extra["targetSdkVersion"] as Int
versionCode = extra["appVersionCode"] as Int
versionName = extra["appVersionName"] as String
minSdk = rootProject.extra["minSdkVersion"] as Int
targetSdk = rootProject.extra["targetSdkVersion"] as Int
versionCode = rootProject.extra["appVersionCode"] as Int
versionName = rootProject.extra["appVersionName"] as String
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
buildConfigField("int", "MIN_SDK_VERSION", "$minSdk")
multiDexEnabled = true
Expand Down Expand Up @@ -191,6 +194,7 @@ android {
buildFeatures {
buildConfig = true
viewBinding = true
resValues = true
}

packaging {
Expand Down Expand Up @@ -264,23 +268,89 @@ ksp {
}

androidComponents {

beforeVariants { variantBuilder ->
if (variantBuilder.name in listOf("devRelease", "devUiTests")) {
// Gradle ignores any variants that satisfy the conditions above.
if (variantBuilder.name in setOf("devRelease", "devUiTests")) {
println("INFO: Excluded \"${variantBuilder.name}\" from build variant list as unused")
variantBuilder.enable = false
}
}

// --- Applies to ALL variants ---
onVariants { variant ->
//we share applicationId as a res value
// Share applicationId as a res value
variant.resValues.put(
variant.makeResValueKey("string", "application_id"),
com.android.build.api.variant.ResValue(variant.applicationId.get())
ResValue(variant.applicationId.get())
)
}

val releaseSelector = selector().withBuildType("release")

// --- Release-only tasks ---
onVariants(releaseSelector) { variant ->
val cap = variant.name.replaceFirstChar { it.uppercase() }

// APK output directory provider
val apkDirProvider = variant.artifacts.get(SingleArtifact.APK)

fun listApks(): List<java.io.File> {
val dir = apkDirProvider.get().asFile
return dir.walkTopDown().filter { it.isFile && it.extension == "apk" }.toList()
}

val checkTask = tasks.register("check${cap}ApkSize") {
doLast {
val apks = listApks()
if (apks.isEmpty()) {
throw GradleException("No APK files found in: ${apkDirProvider.get().asFile.absolutePath}")
}

val maxExpected = 50L * 1024L * 1024L
apks.forEach { apk ->
val size = apk.length()
if (size > maxExpected) {
throw GradleException(
"Release APK is bigger than expected. max=$maxExpected, actual=$size, file=${apk.name}"
)
}
}
}
}

val renameTask = tasks.register("rename${cap}Builds") {
doLast {
val apks = listApks()
if (apks.isEmpty()) {
logger.lifecycle("No APK files found to rename in: ${apkDirProvider.get().asFile.absolutePath}")
return@doLast
}

val ts = SimpleDateFormat("yyyy_MM_dd_HH_mm").format(Date())

// If multiple outputs exist (splits), versionCode/versionName can differ;
// fallback to defaultConfig if not available.
val vCode =
variant.outputs.singleOrNull()?.versionCode?.orNull ?: android.defaultConfig.versionCode
val vName =
variant.outputs.singleOrNull()?.versionName?.orNull ?: android.defaultConfig.versionName

apks.forEach { apk ->
val newName = apk.name.removeSuffix(".apk") + "_${vCode}_${vName}_${ts}.apk"
val target = apk.parentFile.resolve(newName)

if (!apk.renameTo(target)) {
throw GradleException("Failed to rename ${apk.absolutePath} -> ${target.absolutePath}")
} else {
logger.lifecycle("Renamed: ${apk.name} -> ${target.name}")
}
}
}
}
}
}


easylauncher {
buildTypes {
register("debug") {
Expand Down Expand Up @@ -345,44 +415,6 @@ tasks.register("checkCorrectBranch") {
}
}

tasks.register("checkReleaseBuildsSize") {
doLast {
android.applicationVariants.forEach { applicationVariant ->
if (applicationVariant.buildType.name == "release") {
applicationVariant.outputs.forEach { variantOutput ->
val apkFile = variantOutput.outputFile
//for now apk up to 50Mb is normal
val maxExpectedSizeInBytes = 50 * 1024 * 1024
if (apkFile.length() > maxExpectedSizeInBytes) {
throw GradleException(
"The generated release build is bigger then expected: " +
"expected = not big then $maxExpectedSizeInBytes, actual = ${apkFile.length()}"
)
}
}
}
}
}
}

tasks.register("renameReleaseBuilds") {
doLast {
android.applicationVariants.forEach { applicationVariant ->
if (applicationVariant.buildType.name == "release") {
applicationVariant.outputs.forEach { variantOutput ->
val file = variantOutput.outputFile
val newName = file.name.replace(
".apk", "_" + android.defaultConfig.versionCode +
"_" + android.defaultConfig.versionName + "_"
+ SimpleDateFormat("yyyy_MM_dd_HH_mm").format(Date()) + ".apk"
)
variantOutput.outputFile.renameTo(File(file.parent, newName))
}
}
}
}
}

tasks.register<Copy>("copyReleaseApks") {
includeEmptyDirs = false

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
* Contributors: DenBond7
* Contributors: denbond7
*/

package com.flowcrypt.email.ui
Expand Down Expand Up @@ -42,9 +42,6 @@ import okhttp3.mockwebserver.Dispatcher
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.RecordedRequest
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.emptyString
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.not
import org.junit.After
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -463,7 +460,8 @@ class ComposeScreenExternalIntentsFlowTest : BaseTest() {
.check(matches(withText(getRidOfCharacterSubstitutes(body.toString()))))
} else {
onView(withId(R.id.editTextEmailMessage))
.check(matches(isDisplayed())).check(matches(withText(`is`(emptyString()))))
.check(matches(isDisplayed()))
.check(matches(withText("")))
}
}

Expand All @@ -474,7 +472,8 @@ class ComposeScreenExternalIntentsFlowTest : BaseTest() {
.check(matches(withText(getRidOfCharacterSubstitutes(subject))))
} else {
onView(withId(R.id.editTextEmailSubject))
.check(matches(isDisplayed())).check(matches(withText(`is`(emptyString()))))
.check(matches(isDisplayed()))
.check(matches(withText("")))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ import org.apache.commons.io.FileUtils
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.emptyString
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.not
import org.junit.Assert.assertEquals
Expand Down Expand Up @@ -152,7 +151,7 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
)
onView(withId(R.id.editTextEmailSubject))
.perform(scrollTo(), click(), typeText("subject"), clearText())
.check(matches(withText(`is`(emptyString()))))
.check(matches(withText("")))
onView(withId(R.id.menuActionSend))
.check(matches(isDisplayed()))
.perform(click())
Expand All @@ -177,7 +176,7 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
.perform(scrollTo(), click(), replaceText(EMAIL_SUBJECT))
onView(withId(R.id.editTextEmailMessage))
.perform(scrollTo(), click(), replaceText(""))
.check(matches(withText(`is`(emptyString()))))
.check(matches(withText("")))
Espresso.closeSoftKeyboard()
onView(withId(R.id.menuActionSend))
.check(matches(isDisplayed()))
Expand Down Expand Up @@ -259,13 +258,13 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
.check(matches(isDisplayed()))
onView(withId(R.id.editTextFrom))
.perform(scrollTo())
.check(matches(withText(not(`is`(emptyString())))))
.check(matches(withText(not(""))))
onView(withId(R.id.recyclerViewChipsTo))
.check(matches(isDisplayed()))
.check(matches(withRecyclerViewItemCount(1)))
onView(withId(R.id.editTextEmailSubject))
.perform(scrollTo())
.check(matches(withText(`is`(emptyString()))))
.check(matches(withText("")))
}

@Test
Expand Down Expand Up @@ -921,7 +920,8 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {

@get:ClassRule
@JvmStatic
val mockWebServerRule = FlowCryptMockWebServerRule(TestConstants.MOCK_WEB_SERVER_PORT,
val mockWebServerRule = FlowCryptMockWebServerRule(
TestConstants.MOCK_WEB_SERVER_PORT,
object : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse {
if (request.path?.startsWith("/attester/pub", ignoreCase = true) == true) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
* Contributors: DenBond7
* Contributors: denbond7
*/

package com.flowcrypt.email.ui
Expand Down Expand Up @@ -34,9 +34,7 @@ import com.flowcrypt.email.rules.RetryRule
import com.flowcrypt.email.rules.ScreenshotTestRule
import com.flowcrypt.email.ui.activity.MainActivity
import com.flowcrypt.email.util.AccountDaoManager
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.emptyString
import org.hamcrest.Matchers.not
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -144,7 +142,7 @@ class SearchMessagesFlowTest : BaseTest() {
onView(withId(androidx.appcompat.R.id.search_close_btn))
.perform(click())
onView(isAssignableFrom(EditText::class.java))
.check(matches(withText(`is`(emptyString()))))
.check(matches(withText("")))
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
* Contributors: DenBond7
* Contributors: denbond7
*/

package com.flowcrypt.email.ui
Expand Down Expand Up @@ -42,8 +42,6 @@ import com.flowcrypt.email.ui.activity.CreateMessageActivity
import com.flowcrypt.email.util.AccountDaoManager
import com.flowcrypt.email.util.TestGeneralUtil
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.emptyString
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.not
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -162,8 +160,11 @@ class StandardReplyWithServiceInfoAndOneFileFlowTest : BaseTest() {
matches(
allOf(
isDisplayed(),
if (TextUtils.isEmpty(serviceInfo.systemMsg)) withText(`is`(emptyString()))
else withText(serviceInfo.systemMsg),
if (TextUtils.isEmpty(serviceInfo.systemMsg)) {
withText("")
} else {
withText(serviceInfo.systemMsg)
},
if (serviceInfo.isMsgEditable) isFocusable() else not(isFocusable())
)
)
Expand Down
Loading