Re-ask only on wrong password

This commit is contained in:
Matéo Duparc 2023-05-11 21:58:07 +02:00
parent 393c458495
commit cb3fc3c70e
Signed by untrusted user: hardcoresushi
GPG Key ID: AFE384344A45E13A
6 changed files with 35 additions and 17 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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 <T> waitForTask(notification: FileOperationNotification, task: Deferred<T>): TaskResult<out T> {
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 <T> volumeTask(

View File

@ -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

View File

@ -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)
}
}

View File

@ -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 {