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 @@ -28,7 +28,7 @@ class SetupEncryptionDialogFragmentIT : AbstractIT() {
launchActivity<TestActivity>().use { scenario ->
var sut: SetupEncryptionDialogFragment? = null
scenario.onActivity { activity ->
sut = SetupEncryptionDialogFragment.newInstance(user, null)
sut = SetupEncryptionDialogFragment.newInstance(user, null, null)
sut.show(activity.supportFragmentManager, "1")
val keyWords = arrayListOf(
"ability",
Expand Down Expand Up @@ -64,7 +64,7 @@ class SetupEncryptionDialogFragmentIT : AbstractIT() {
launchActivity<TestActivity>().use { scenario ->
var sut: SetupEncryptionDialogFragment? = null
scenario.onActivity { activity ->
sut = SetupEncryptionDialogFragment.newInstance(user, null)
sut = SetupEncryptionDialogFragment.newInstance(user, null, null)
sut.show(activity.supportFragmentManager, "1")
sut.errorSavingKeys()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ package com.nextcloud.utils.extensions

import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.nextcloud.utils.e2ee.model.E2EEAction
import com.owncloud.android.R
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.ui.activity.FileActivity
import com.owncloud.android.ui.dialog.setupEncryption.SetupEncryptionDialogFragment
import com.owncloud.android.ui.dialog.setupEncryption.SetupEncryptionDialogFragment.Companion.ARG_ACTION
import com.owncloud.android.ui.dialog.setupEncryption.SetupEncryptionDialogFragment.Companion.ARG_FILE_PATH
import com.owncloud.android.ui.dialog.setupEncryption.SetupEncryptionDialogFragment.Companion.RESULT_REQUEST_KEY
import com.owncloud.android.ui.dialog.setupEncryption.SetupEncryptionDialogFragment.Companion.SUCCESS
Expand All @@ -23,16 +25,16 @@ import kotlinx.coroutines.launch

private const val TAG = "OCFileListFragmentExtensions"

fun OCFileListFragment.showEncryptionDialog(remotePath: String?) {
fun OCFileListFragment.showEncryptionDialog(remotePath: String?, action: E2EEAction) {
if (parentFragmentManager.findFragmentByTag(SetupEncryptionDialogFragment.SETUP_ENCRYPTION_DIALOG_TAG) != null) {
return
}

val user = accountManager.user
val connectivityService = typedActivity<FileActivity>()?.connectivityService
connectivityService?.isNetworkAndServerAvailable { result ->
if (result == true) {
SetupEncryptionDialogFragment.newInstance(user, remotePath)
if (result) {
SetupEncryptionDialogFragment.newInstance(user, remotePath, action)
.show(parentFragmentManager, SetupEncryptionDialogFragment.SETUP_ENCRYPTION_DIALOG_TAG)
return@isNetworkAndServerAvailable
}
Expand All @@ -55,30 +57,37 @@ fun OCFileListFragment.listenEncryptionDialogResult() {
return@setFragmentResultListener
}

val fileRemotePath = bundle.getString(ARG_FILE_PATH, null)
if (fileRemotePath == null) {
Log_OC.e(TAG, "file path is null")
val action = bundle.getSerializableArgument(ARG_ACTION, E2EEAction::class.java)
if (action == null) {
Log_OC.e(TAG, "no pending encryption action, nothing to continue with")
return@setFragmentResultListener
}

val file: OCFile? = mContainerActivity.getStorageManager().getFileByDecryptedRemotePath(fileRemotePath)
if (file == null) {
Log_OC.e(TAG, "file is null, cannot toggle encryption")
return@setFragmentResultListener
}
when (action) {
E2EEAction.NEW_FOLDER -> createFolder(true)

if (file.isRootDirectory) {
Log_OC.d(
TAG,
"result of setup encryption triggered in root directory, this call is for " +
"creating encrypted folder"
)
createFolder(true)
return@setFragmentResultListener
}
E2EEAction.OPEN -> folderFromResult(bundle)?.let { encryptedClickHandler.openAfterKeySetup(it) }

lifecycleScope.launch {
folderEncryption.toggle(file.toEncryptionEvent(true))
E2EEAction.ENCRYPT -> folderFromResult(bundle)?.let { file ->
lifecycleScope.launch {
folderEncryption.toggle(file.toEncryptionEvent(true))
}
}
}
}
}

private fun OCFileListFragment.folderFromResult(bundle: Bundle): OCFile? {
val remotePath = bundle.getString(ARG_FILE_PATH, null)
if (remotePath == null) {
Log_OC.e(TAG, "file path is null")
return null
}

val file = containerActivity.storageManager.getFileByEncryptedRemotePath(remotePath)
if (file == null) {
Log_OC.e(TAG, "file is null, cannot continue encryption action")
}

return file
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SetupEncryptionActivity : AppCompatActivity() {
finish()
}

val setupEncryptionDialogFragment = SetupEncryptionDialogFragment.newInstance(user, null)
val setupEncryptionDialogFragment = SetupEncryptionDialogFragment.newInstance(user, null, null)
supportFragmentManager.setFragmentResultListener(
SetupEncryptionDialogFragment.RESULT_REQUEST_KEY,
this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import com.google.android.material.textfield.TextInputLayout
import com.nextcloud.client.account.User
import com.nextcloud.client.di.Injectable
import com.nextcloud.client.network.ClientFactory
import com.nextcloud.utils.e2ee.model.E2EEAction
import com.nextcloud.utils.extensions.getParcelableArgument
import com.nextcloud.utils.extensions.getSerializableArgument
import com.owncloud.android.BuildConfig
import com.owncloud.android.R
import com.owncloud.android.databinding.SetupEncryptionDialogBinding
Expand Down Expand Up @@ -243,6 +245,7 @@ class SetupEncryptionDialogFragment :
return Bundle().apply {
putBoolean(SUCCESS, true)
putString(ARG_FILE_PATH, requireArguments().getString(ARG_FILE_PATH))
putSerializable(ARG_ACTION, arguments.getSerializableArgument(ARG_ACTION, E2EEAction::class.java))
}
}

Expand Down Expand Up @@ -526,6 +529,7 @@ class SetupEncryptionDialogFragment :
const val SETUP_ENCRYPTION_RESULT_CODE = 101
const val SETUP_ENCRYPTION_DIALOG_TAG = "SETUP_ENCRYPTION_DIALOG_TAG"
const val ARG_FILE_PATH = "ARG_FILE_PATH"
const val ARG_ACTION = "ARG_ACTION"
const val RESULT_REQUEST_KEY = "RESULT_REQUEST"
const val RESULT_KEY_CANCELLED = "IS_CANCELLED"
private const val NUMBER_OF_WORDS = 12
Expand All @@ -537,11 +541,12 @@ class SetupEncryptionDialogFragment :
private const val KEY_GENERATE = "KEY_GENERATE"

@JvmStatic
fun newInstance(user: User?, filePath: String?): SetupEncryptionDialogFragment =
fun newInstance(user: User?, filePath: String?, action: E2EEAction?): SetupEncryptionDialogFragment =
SetupEncryptionDialogFragment().apply {
arguments = Bundle().apply {
putParcelable(ARG_USER, user)
putString(ARG_FILE_PATH, filePath)
putSerializable(ARG_ACTION, action)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class EncryptionEvent(val localId: Long, val remoteId: String, val remotePath: S
}

E2EEKeyCheck.ONLY_ON_SERVER, E2EEKeyCheck.MISSING_EVERYWHERE -> {
fragment.showEncryptionDialog(remotePath)
fragment.showEncryptionDialog(remotePath, E2EEAction.ENCRYPT)
}

E2EEKeyCheck.ONLY_ON_DEVICE, E2EEKeyCheck.DIFFERS_FROM_SERVER -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class EncryptedFolderClickHandler(private val fragment: OCFileListFragment) {

E2EEKeyCheck.ONLY_ON_SERVER, E2EEKeyCheck.MISSING_EVERYWHERE -> {
Log_OC.d(TAG, "keys found on server but missing locally, redirecting to encryption setup")
fragment.showEncryptionDialog(OCFile.ROOT_PATH)
fragment.showEncryptionDialog(OCFile.ROOT_PATH, E2EEAction.NEW_FOLDER)
}

E2EEKeyCheck.SAME_AS_SERVER -> {
Expand Down Expand Up @@ -86,7 +86,7 @@ class EncryptedFolderClickHandler(private val fragment: OCFileListFragment) {
}

E2EEKeyCheck.ONLY_ON_SERVER -> {
fragment.showEncryptionDialog(file.remotePath)
fragment.showEncryptionDialog(file.remotePath, E2EEAction.OPEN)
}

E2EEKeyCheck.MISSING_EVERYWHERE -> {
Expand Down Expand Up @@ -114,14 +114,24 @@ class EncryptedFolderClickHandler(private val fragment: OCFileListFragment) {
}
}

fun openAfterKeySetup(file: OCFile) {
fragment.lifecycleScope.launch {
if (fragment.e2eeActionResolver.checkFolderMetadataKey(file)) {
onEncryptionSetupComplete(file, fragment.adapter.getItemPosition(file))
} else {
DisplayUtils.showSnackMessage(fragment, R.string.encryption_open_key_mismatch)
}
}
}

private fun dismissCheckingSnackbar() {
DisplayUtils.dismissSnackMessage(checkingKeysSnackbar)
checkingKeysSnackbar = null
}

private fun onFolderKeyVerified(file: OCFile, position: Int, fileActivity: FileActivity) {
val user = fileActivity.user.orElseThrow { RuntimeException() }
val capability = fragment.mContainerActivity.getStorageManager().getCapability(user.accountName)
val capability = fragment.containerActivity.getStorageManager().getCapability(user.accountName)

if (capability.endToEndEncryption.isFalse || capability.endToEndEncryption.isUnknown) {
DisplayUtils.showSnackMessage(fragment, R.string.end_to_end_encryption_not_enabled)
Expand All @@ -131,15 +141,15 @@ class EncryptedFolderClickHandler(private val fragment: OCFileListFragment) {
if (FileOperationsHelper.isEndToEndEncryptionSetup(fragment.context, user)) {
onEncryptionSetupComplete(file, position)
} else {
fragment.showEncryptionDialog(file.remotePath)
fragment.showEncryptionDialog(file.remotePath, E2EEAction.OPEN)
}
}

private fun onEncryptionSetupComplete(file: OCFile?, position: Int) {
fragment.searchFragment = false
fragment.mHideFab = false

val folderPickerActivity = fragment.mContainerActivity as? FolderPickerActivity
val folderPickerActivity = fragment.containerActivity as? FolderPickerActivity
if (folderPickerActivity?.isDoNotEnterEncryptedFolder == true) {
DisplayUtils.showSnackMessage(fragment, R.string.copy_move_to_encrypted_folder_not_supported)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FolderEncryption(private val fragment: OCFileListFragment) {
val shouldBeEncrypted = event.shouldBeEncrypted

try {
val storageManager = fragment.mContainerActivity.storageManager
val storageManager = fragment.containerActivity.storageManager
val folder = storageManager.getFileByRemoteId(remoteId) ?: run {
Log_OC.e(TAG, "folder is null, cannot encrypt")
return@withContext false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class GalleryFragment :
requireContext(),
accountManager.user,
this,
mContainerActivity,
containerActivity,
viewThemeUtils,
this.columnsCount,
ThumbnailsCacheManager.getThumbnailDimension(),
Expand Down Expand Up @@ -362,7 +362,7 @@ class GalleryFragment :
}

private fun runGallerySearchTask() {
if (mContainerActivity == null) {
if (containerActivity == null) {
Log_OC.w(TAG, "container activity is null, can't run search task")
return
}
Expand All @@ -372,7 +372,7 @@ class GalleryFragment :
photoSearchTask = GallerySearchTask(
this,
accountManager.user,
mContainerActivity.getStorageManager(),
containerActivity.getStorageManager(),
endDate,
limit
).execute()
Expand Down Expand Up @@ -445,7 +445,7 @@ class GalleryFragment :
showGalleryJob?.cancel()
showGalleryJob = lifecycleScope.launch(Dispatchers.Default) {
val remotePath = preferences.getLastSelectedMediaFolder()
val items = mContainerActivity.storageManager.getGalleryItemsPageSuspended(
val items = containerActivity.storageManager.getGalleryItemsPageSuspended(
remotePath,
mimeFilter,
loadedItemCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class GroupfolderListFragment :
GroupfoldersSearchTask(
this,
accountManager.user,
mContainerActivity.storageManager
containerActivity.storageManager
).execute()
}

Expand Down
Loading
Loading