From cb3fc3c70e738e083343ac0eb4ecc153a4bb17d1 Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Thu, 11 May 2023 21:58:07 +0200 Subject: [PATCH] Re-ask only on wrong password --- TODO.md | 1 + .../sushi/hardcore/droidfs/VolumeOpener.kt | 4 ++- .../file_operations/FileOperationService.kt | 26 +++++++++++-------- .../droidfs/filesystems/CryfsVolume.kt | 5 +++- .../droidfs/filesystems/EncryptedVolume.kt | 11 +++++--- .../droidfs/filesystems/GocryptfsVolume.kt | 5 +++- 6 files changed, 35 insertions(+), 17 deletions(-) diff --git a/TODO.md b/TODO.md index 5f96c46..471f1a4 100644 --- a/TODO.md +++ b/TODO.md @@ -8,6 +8,7 @@ Here's a list of features that it would be nice to have in DroidFS. As this is a ## UX - File associations editor +- Optional file discovery before file operations - Modifiable CryFS scrypt parameters - Alert dialog showing details of file operations - Internal file browser to select volumes diff --git a/app/src/main/java/sushi/hardcore/droidfs/VolumeOpener.kt b/app/src/main/java/sushi/hardcore/droidfs/VolumeOpener.kt index 7ba5f8a..cfbf18d 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/VolumeOpener.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/VolumeOpener.kt @@ -190,7 +190,9 @@ class VolumeOpener( .setTitle(R.string.open_volume_failed) .setMessage(getErrorMsg(result)) .setPositiveButton(R.string.ok) { _, _ -> - askForPassword(volume, isVolumeSaved, callbacks, savePasswordHash) + if (result.worthRetry) { + askForPassword(volume, isVolumeSaved, callbacks, savePasswordHash) + } } .show() } else { diff --git a/app/src/main/java/sushi/hardcore/droidfs/file_operations/FileOperationService.kt b/app/src/main/java/sushi/hardcore/droidfs/file_operations/FileOperationService.kt index a8f38cb..0ce022f 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/file_operations/FileOperationService.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/file_operations/FileOperationService.kt @@ -20,6 +20,8 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.MainScope import kotlinx.coroutines.async +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.withContext import kotlinx.coroutines.yield import sushi.hardcore.droidfs.Constants import sushi.hardcore.droidfs.R @@ -124,18 +126,20 @@ class FileOperationService : Service() { private suspend fun waitForTask(notification: FileOperationNotification, task: Deferred): TaskResult { tasks[notification.notificationId] = task - return serviceScope.async { - try { - TaskResult.completed(task.await()) - } catch (e: CancellationException) { - TaskResult.cancelled() - } catch (e: Throwable) { - e.printStackTrace() - TaskResult.error(e.localizedMessage) - } finally { - cancelNotification(notification) + return coroutineScope { + withContext(serviceScope.coroutineContext) { + try { + TaskResult.completed(task.await()) + } catch (e: CancellationException) { + TaskResult.cancelled() + } catch (e: Throwable) { + e.printStackTrace() + TaskResult.error(e.localizedMessage) + } finally { + cancelNotification(notification) + } } - }.await() + } } private suspend fun volumeTask( diff --git a/app/src/main/java/sushi/hardcore/droidfs/filesystems/CryfsVolume.kt b/app/src/main/java/sushi/hardcore/droidfs/filesystems/CryfsVolume.kt index e7c0346..c97e9d4 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/filesystems/CryfsVolume.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/filesystems/CryfsVolume.kt @@ -68,7 +68,10 @@ class CryfsVolume(private val fusePtr: Long): EncryptedVolume() { result.errorCode = errorCode.value ?: 0 result.errorStringId = when (errorCode.value) { // Values from src/cryfs/impl/ErrorCodes.h - 11 -> R.string.wrong_password + 11 -> { + result.worthRetry = true + R.string.wrong_password + } 16 -> R.string.inaccessible_base_dir 19 -> R.string.config_load_error 20 -> R.string.filesystem_id_changed diff --git a/app/src/main/java/sushi/hardcore/droidfs/filesystems/EncryptedVolume.kt b/app/src/main/java/sushi/hardcore/droidfs/filesystems/EncryptedVolume.kt index 200e374..1f270d6 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/filesystems/EncryptedVolume.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/filesystems/EncryptedVolume.kt @@ -8,7 +8,6 @@ import sushi.hardcore.droidfs.Constants import sushi.hardcore.droidfs.VolumeData import sushi.hardcore.droidfs.explorers.ExplorerElement import sushi.hardcore.droidfs.util.ObjRef -import sushi.hardcore.droidfs.util.PathUtils import java.io.File import java.io.FileOutputStream import java.io.InputStream @@ -16,13 +15,19 @@ import java.io.OutputStream abstract class EncryptedVolume: Parcelable { - class InitResult(val errorCode: Int, val errorStringId: Int, val volume: EncryptedVolume?) { + class InitResult( + val errorCode: Int, + val errorStringId: Int, + val worthRetry: Boolean, + val volume: EncryptedVolume?, + ) { class Builder { var errorCode = 0 var errorStringId = 0 + var worthRetry = false var volume: EncryptedVolume? = null - fun build() = InitResult(errorCode, errorStringId, volume) + fun build() = InitResult(errorCode, errorStringId, worthRetry, volume) } } diff --git a/app/src/main/java/sushi/hardcore/droidfs/filesystems/GocryptfsVolume.kt b/app/src/main/java/sushi/hardcore/droidfs/filesystems/GocryptfsVolume.kt index 3fe1109..19096a5 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/filesystems/GocryptfsVolume.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/filesystems/GocryptfsVolume.kt @@ -83,7 +83,10 @@ class GocryptfsVolume(private val sessionID: Int): EncryptedVolume() { result.errorCode = sessionId result.errorStringId = when (sessionId) { -1 -> R.string.config_load_error - -2 -> R.string.wrong_password + -2 -> { + result.worthRetry = true + R.string.wrong_password + } else -> 0 } } else {