Skip to content
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 @@ -42,6 +42,7 @@ import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import com.flowcrypt.email.BuildConfig
import com.flowcrypt.email.Constants
import com.flowcrypt.email.R
import com.flowcrypt.email.api.email.MsgsCacheManager
import com.flowcrypt.email.api.email.model.AttachmentInfo
Expand Down Expand Up @@ -387,5 +388,8 @@ abstract class BaseTest : BaseActivityTestImplementation {
companion object{
const val NOTIFICATION_RESOURCES_NAME =
"com.android.systemui:id/expandableNotificationRow"

val SHARED_FOLDER = InstrumentationRegistry.getInstrumentation().targetContext
.getExternalFilesDir(Constants.EXTERNAL_FILES_PATH_SHARED)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ import java.util.concurrent.TimeUnit
@RunWith(AndroidJUnit4::class)
class ComposeScreenFlowTest : BaseComposeScreenTest() {
private val addPrivateKeyToDatabaseRule = AddPrivateKeyToDatabaseRule()
private val temporaryFolderRule = TemporaryFolder()
private val temporaryFolderRule = TemporaryFolder.builder().parentFolder(SHARED_FOLDER).build()

@get:Rule
var ruleChain: TestRule = RuleChain
Expand Down Expand Up @@ -907,7 +907,7 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {

@get:ClassRule
@JvmStatic
val temporaryFolderRule = TemporaryFolder()
val temporaryFolderRule = TemporaryFolder.builder().parentFolder(SHARED_FOLDER).build()

@get:ClassRule
@JvmStatic
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 @@ -48,7 +48,7 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ComposeScreenPasswordProtectedFlowTest : BaseComposeScreenTest() {
private val addPrivateKeyToDatabaseRule = AddPrivateKeyToDatabaseRule()
private val temporaryFolderRule = TemporaryFolder()
private val temporaryFolderRule = TemporaryFolder.builder().parentFolder(SHARED_FOLDER).build()

override val addAccountToDatabaseRule: AddAccountToDatabaseRule
get() = AddAccountToDatabaseRule(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
* Contributors: DenBond7
* Contributors: denbond7
*/

package com.flowcrypt.email.ui

import android.app.Activity
import android.app.Instrumentation
import android.content.Intent
import android.os.Environment
import androidx.core.content.FileProvider
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
Expand Down Expand Up @@ -145,7 +144,7 @@ class PublicKeyDetailsFlowTest : BaseTest() {
val fileName = "0x" + keyDetails.fingerprint + "-" + sanitizedEmail + "-publickey" + ".asc"

val file =
File(getTargetContext().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS), fileName)
File(getTargetContext().getExternalFilesDir(Constants.EXTERNAL_FILES_PATH_SHARED), fileName)

if (file.exists()) {
file.delete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package com.flowcrypt.email.ui
import android.app.Activity
import android.app.Instrumentation
import android.content.Intent
import android.os.Environment
import androidx.core.content.FileProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
Expand Down Expand Up @@ -122,7 +121,7 @@ class PublicKeyDetailsHideArmorMetaFlowTest : BaseTest() {
val fileName = "0x" + keyDetails.fingerprint + "-" + sanitizedEmail + "-publickey" + ".asc"

val file =
File(getTargetContext().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS), fileName)
File(getTargetContext().getExternalFilesDir(Constants.EXTERNAL_FILES_PATH_SHARED), fileName)

if (file.exists()) {
file.delete()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
* Contributors: DenBond7
* Contributors: denbond7
*/

package com.flowcrypt.email.ui.fragment.isolation.incontainer

import android.app.Activity
import android.app.Instrumentation
import android.content.Intent
import android.os.Environment
import androidx.core.content.FileProvider
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso.onView
Expand Down Expand Up @@ -164,7 +163,7 @@ class PrivateKeyDetailsFragmentInIsolationTest : BaseTest() {
val details = addPrivateKeyToDatabaseRule.pgpKeyRingDetails

val file = File(
getTargetContext().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS),
getTargetContext().getExternalFilesDir(Constants.EXTERNAL_FILES_PATH_SHARED),
"0x" + details.fingerprint + ".asc"
)

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: ivan
* Contributors: denbond7
*/

package com.flowcrypt.email.util
Expand All @@ -9,7 +9,6 @@ import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.Environment
import androidx.core.content.FileProvider
import androidx.navigation.NavDeepLinkBuilder
import androidx.test.core.app.ApplicationProvider
Expand Down Expand Up @@ -97,7 +96,7 @@ object TestGeneralUtil {
fun createFileWithContent(fileName: String, byteArray: ByteArray): File {
val file = File(
InstrumentationRegistry.getInstrumentation().targetContext
.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS), fileName
.getExternalFilesDir(Constants.EXTERNAL_FILES_PATH_SHARED), fileName
)
try {
FileOutputStream(file).use { outputStream -> outputStream.write(byteArray) }
Expand Down
3 changes: 2 additions & 1 deletion FlowCrypt/src/main/java/com/flowcrypt/email/Constants.kt
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
Expand Down Expand Up @@ -74,6 +74,7 @@ class Constants {
const val FORWARDED_ATTACHMENTS_CACHE_DIR = "forwarded"
const val ATTACHMENTS_CACHE_DIR = "attachments"
const val DRAFT_CACHE_DIR = "draft"
const val EXTERNAL_FILES_PATH_SHARED = "shared"

/**
* The password quality types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ package com.flowcrypt.email.jetpack.viewmodel

import android.app.Application
import android.content.ContentResolver
import android.content.Context
import android.net.Uri
import androidx.lifecycle.viewModelScope
import com.flowcrypt.email.Constants
import com.flowcrypt.email.api.email.model.AttachmentInfo
import com.flowcrypt.email.api.email.model.OutgoingMessageInfo
import com.flowcrypt.email.api.retrofit.response.base.Result
Expand All @@ -24,6 +27,7 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import java.io.File
import java.io.InvalidObjectException

/**
Expand Down Expand Up @@ -99,9 +103,19 @@ class ComposeMsgViewModel(isCandidateToEncrypt: Boolean, application: Applicatio
val allRecipients: Map<String, RecipientItem>
get() = recipientsTo + recipientsCc + recipientsBcc

val hasAttachmentsWithExternalStorageUri: Boolean
get() = attachmentsStateFlow.value.any {
ContentResolver.SCHEME_FILE.equals(it.uri?.scheme, ignoreCase = true)
val hasAttachmentsWittForeignExternalStorageUri: Boolean
get() {
val context: Context = getApplication()
val draftsCacheDirUri = Uri.fromFile(File(context.cacheDir, Constants.DRAFT_CACHE_DIR))

return attachmentsStateFlow.value.any {
val parentUri = it.uri?.buildUpon()?.path(
it.uri.path?.dropLast(it.uri.lastPathSegment?.length?.plus(1) ?: 0)
)?.build()

ContentResolver.SCHEME_FILE.equals(it.uri?.scheme, ignoreCase = true)
&& parentUri != draftsCacheDirUri
}
}

private val outgoingMessageInfoMutableStateFlow: MutableStateFlow<OutgoingMessageInfo> =
Expand Down
Loading