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
@@ -0,0 +1,90 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
* Contributors: denbond7
*/

package com.flowcrypt.email.ui.fragment

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import com.flowcrypt.email.R
import com.flowcrypt.email.TestConstants
import com.flowcrypt.email.junit.annotations.FlowCryptTestSettings
import com.flowcrypt.email.rules.ClearAppSettingsRule
import com.flowcrypt.email.rules.FlowCryptMockWebServerRule
import com.flowcrypt.email.rules.GrantPermissionRuleChooser
import com.flowcrypt.email.rules.RetryRule
import com.flowcrypt.email.rules.ScreenshotTestRule
import com.flowcrypt.email.ui.activity.MainActivity
import com.flowcrypt.email.ui.base.BaseGmailApiTest
import com.flowcrypt.email.util.TestGeneralUtil
import okhttp3.mockwebserver.Dispatcher
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.RecordedRequest
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
import org.junit.runner.RunWith

/**
* @author Denys Bondarenko
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
@FlowCryptTestSettings(useCommonIdling = false)
class MainSettingsFragmentEnterpriseFlowTest :
BaseGmailApiTest(BASE_ACCOUNT_ENTITY.copy(useConversationMode = true)) {
override val activityScenarioRule = activityScenarioRule<MainActivity>(
TestGeneralUtil.genIntentForNavigationComponent(
destinationId = R.id.mainSettingsFragment
)
)

override val mockWebServerRule =
FlowCryptMockWebServerRule(TestConstants.MOCK_WEB_SERVER_PORT, object : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse {
return when {
else -> handleCommonAPICalls(request)
}
}
})

@get:Rule
var ruleChain: TestRule = RuleChain
.outerRule(RetryRule.DEFAULT)
.around(ClearAppSettingsRule())
.around(GrantPermissionRuleChooser.grant(android.Manifest.permission.POST_NOTIFICATIONS))
.around(addAccountToDatabaseRule)
.around(addPrivateKeyToDatabaseRule)
.around(activityScenarioRule)
.around(ScreenshotTestRule())

@Test
fun testHiddenOrVisibleItems() {
//should be hidden as we have NO_PRV_BACKUP
onView(withText(getResString(R.string.backups)))
.check(doesNotExist())
//should be hidden as we have RESTRICT_ANDROID_ATTACHMENT_HANDLING
onView(withText(getResString(R.string.general)))
.check(doesNotExist())

//should be visible
onView(withText(getResString(R.string.security_and_privacy)))
.check(matches(isDisplayed()))
onView(withText(getResString(R.string.contacts)))
.check(matches(isDisplayed()))
onView(withText(getResString(R.string.keys)))
.check(matches(isDisplayed()))
onView(withText(getResString(R.string.attester)))
.check(matches(isDisplayed()))
onView(withText(getResString(R.string.experimental)))
.check(matches(isDisplayed()))
}
}
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.fragment
Expand Down Expand Up @@ -89,6 +89,24 @@ class MainSettingsFragmentNavigationToSubMenuFlowTest : BaseTest() {
)
}

@Test
fun testHiddenOrVisibleItems() {
onView(withText(getResString(R.string.backups)))
.check(matches(isDisplayed()))
onView(withText(getResString(R.string.security_and_privacy)))
.check(matches(isDisplayed()))
onView(withText(getResString(R.string.contacts)))
.check(matches(isDisplayed()))
onView(withText(getResString(R.string.keys)))
.check(matches(isDisplayed()))
onView(withText(getResString(R.string.attester)))
.check(matches(isDisplayed()))
onView(withText(getResString(R.string.general)))
.check(matches(isDisplayed()))
onView(withText(getResString(R.string.experimental)))
.check(matches(isDisplayed()))
}

private fun checkIsScreenDisplaying(screenName: String) {
checkIsScreenDisplaying(screenName, screenName)
}
Expand Down
3 changes: 3 additions & 0 deletions FlowCrypt/src/main/java/com/flowcrypt/email/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ class Constants {
const val PREF_KEY_MESSAGES_NOTIFICATION_FILTER = "preferences_key_messages_notification_filter"
const val PREF_KEY_MANAGE_NOTIFICATIONS = "preferences_key_manage_notifications"
const val PREF_KEY_SECURITY_CHANGE_PASS_PHRASE = "preferences_key_security_change_pass_phrase"
const val PREFERENCES_KEY_ATTACHMENTS_DISABLE_SMART_MODE_FOR_PREVIEW =
"preferences_key_attachments_disable_smart_mode_for_preview"
const val PREF_KEY_LAST_ATT_ORDER_ID = "preferences_key_last_att_order_id"
const val PREF_KEY_IS_CHECK_KEYS_NEEDED = "preferences_key_is_check_keys_needed"
const val PREF_KEY_BACKUPS = "pref_key_backups"
const val PREF_KEY_INSTALL_VERSION = "pref_key_install_version"
const val PREF_KEY_SERVER_SETTINGS = "pref_key_server_settings"
const val PREF_KEY_GENERAL = "pref_key_general"

/**
* The max total size off all attachment which can be send via the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class EmbeddedAttachmentsProvider : DocumentsProvider() {
return getFileDescriptor(getBytesForDocumentId(documentId))
}

override fun getDocumentType(documentId: String?): String {
return documentId?.let {
Cache.getInstance().get(documentId)?.type ?: super.getDocumentType(documentId)
} ?: super.getDocumentType(documentId)
}

private fun getBytesForDocumentId(documentId: String): ByteArray {
val attachmentInfo = Cache.getInstance().get(documentId)
return requireNotNull(attachmentInfo?.rawData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,23 +623,6 @@ class AttachmentDownloadManagerService : LifecycleService() {
val fileUri = resolver.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues)

requireNotNull(fileUri)

//we should check maybe a file is already exist. Then we will use the file name from the system
val cursor =
resolver.query(fileUri, arrayOf(MediaStore.DownloadColumns.DISPLAY_NAME), null, null, null)
cursor?.let {
if (it.moveToFirst()) {
val nameIndex = it.getColumnIndex(MediaStore.DownloadColumns.DISPLAY_NAME)
if (nameIndex != -1) {
val nameFromSystem = it.getString(nameIndex)
if (nameFromSystem != finalFileName) {
finalFileName = nameFromSystem
}
}
}
}
cursor?.close()

val srcInputStream = attFile.inputStream()
val destOutputStream = resolver.openOutputStream(fileUri)
?: throw IllegalArgumentException("provided URI could not be opened")
Expand All @@ -652,6 +635,23 @@ class AttachmentDownloadManagerService : LifecycleService() {
put(MediaStore.Downloads.IS_PENDING, 0)
}, null, null)

resolver.query(
fileUri,
arrayOf(MediaStore.DownloadColumns.DISPLAY_NAME),
null,
null,
null
)
?.use { cursor ->
//we should check maybe a file is already exist.
//Then we will use the file name from the system.
if (cursor.moveToFirst()) {
finalFileName = cursor.getString(
cursor.getColumnIndexOrThrow(MediaStore.DownloadColumns.DISPLAY_NAME)
)
}
}

return fileUri
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewModel
import androidx.navigation.NavDirections
import androidx.navigation.fragment.navArgs
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.flowcrypt.email.Constants
Expand Down Expand Up @@ -109,6 +110,7 @@ import com.flowcrypt.email.ui.adapter.recyclerview.itemdecoration.MarginItemDeco
import com.flowcrypt.email.util.FileAndDirectoryUtils
import com.flowcrypt.email.util.GeneralUtil
import com.flowcrypt.email.util.LogsUtil
import com.flowcrypt.email.util.SharedPreferencesHelper
import com.flowcrypt.email.util.UIUtil
import com.flowcrypt.email.util.exception.DecryptionException
import com.flowcrypt.email.util.exception.ExceptionUtil
Expand Down Expand Up @@ -253,13 +255,17 @@ class CreateMessageFragment : BaseFragment<FragmentCreateMessageBinding>(),
attachmentActionListener = object : AttachmentsRecyclerViewAdapter.AttachmentActionListener {
override fun onDownloadClick(attachmentInfo: AttachmentInfo) {}

override fun onAttachmentClick(attachmentInfo: AttachmentInfo) {
onPreviewClick(attachmentInfo)
}

override fun onPreviewClick(attachmentInfo: AttachmentInfo) {
if (attachmentInfo.uri != null) {
val intent = GeneralUtil.genViewAttachmentIntent(attachmentInfo.uri, attachmentInfo)
val intent = GeneralUtil.genViewAttachmentIntent(
uri = attachmentInfo.uri,
attachmentInfo = attachmentInfo,
useCommonPattern = SharedPreferencesHelper.getBoolean(
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()),
key = Constants.PREFERENCES_KEY_ATTACHMENTS_DISABLE_SMART_MODE_FOR_PREVIEW,
defaultValue = false
)
)
try {
startActivity(intent)
} catch (e: ActivityNotFoundException) {
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.activity.fragment
Expand Down Expand Up @@ -95,6 +95,14 @@ class MainSettingsFragment : BasePreferenceFragment() {
true
}

findPreference<Preference>(getString(R.string.pref_key_general))
?.setOnPreferenceClickListener {
navController?.navigate(
MainSettingsFragmentDirections.actionMainSettingsFragmentToGeneralSettingsFragment()
)
true
}

findPreference<Preference>(getString(R.string.pref_key_experimental))
?.setOnPreferenceClickListener {
navController?.navigate(
Expand All @@ -110,8 +118,10 @@ class MainSettingsFragment : BasePreferenceFragment() {
!(accountEntity?.hasClientConfigurationProperty(ClientConfiguration.ConfigurationProperty.NO_PRV_BACKUP)
?: false)

if (accountEntity?.useAPI == false) {
findPreference<Preference>(Constants.PREF_KEY_SERVER_SETTINGS)?.isVisible = true
}
findPreference<Preference>(Constants.PREF_KEY_SERVER_SETTINGS)?.isVisible =
accountEntity?.useAPI == false

findPreference<Preference>(Constants.PREF_KEY_GENERAL)?.isVisible =
accountEntity?.isHandlingAttachmentRestricted() == false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavDirections
import androidx.navigation.fragment.navArgs
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.flowcrypt.email.Constants
Expand Down Expand Up @@ -131,6 +132,7 @@ import com.flowcrypt.email.ui.widget.EmailWebView
import com.flowcrypt.email.ui.widget.TileDrawable
import com.flowcrypt.email.util.DateTimeUtil
import com.flowcrypt.email.util.GeneralUtil
import com.flowcrypt.email.util.SharedPreferencesHelper
import com.flowcrypt.email.util.UIUtil
import com.flowcrypt.email.util.exception.CommonConnectionException
import com.flowcrypt.email.util.exception.GmailAPIException
Expand Down Expand Up @@ -201,10 +203,6 @@ class MessageDetailsFragment : BaseFragment<FragmentMessageDetailsBinding>(), Pr
}
}

override fun onAttachmentClick(attachmentInfo: AttachmentInfo) {
onPreviewClick(attachmentInfo)
}

override fun onPreviewClick(attachmentInfo: AttachmentInfo) {
if (attachmentInfo.uri != null) {
if (attachmentInfo.isPossiblyEncrypted) {
Expand Down Expand Up @@ -1828,7 +1826,15 @@ class MessageDetailsFragment : BaseFragment<FragmentMessageDetailsBinding>(), Pr
useContentApp: Boolean = false
) {
val intent = if (attachmentInfo.uri != null) {
GeneralUtil.genViewAttachmentIntent(requireNotNull(attachmentInfo.uri), attachmentInfo)
GeneralUtil.genViewAttachmentIntent(
uri = requireNotNull(attachmentInfo.uri),
attachmentInfo = attachmentInfo,
useCommonPattern = SharedPreferencesHelper.getBoolean(
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()),
key = Constants.PREFERENCES_KEY_ATTACHMENTS_DISABLE_SMART_MODE_FOR_PREVIEW,
defaultValue = false
)
)
} else {
toast(getString(R.string.preview_is_not_available))
return
Expand Down
Loading