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
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 { clickHandler.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 = mContainerActivity.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,6 +114,16 @@ 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
Expand All @@ -131,7 +141,7 @@ 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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
@Inject ThumbnailGenerator thumbnailGenerator;
@Inject public E2EEActionResolver e2eeActionResolver;
public E2EEDialogPresenter e2eeDialogPresenter;
private EncryptedFolderClickHandler clickHandler;
public EncryptedFolderClickHandler clickHandler;
public FolderEncryption folderEncryption;
public FileFragment.ContainerActivity mContainerActivity;

Expand Down
Loading