Re-ask only on wrong password
This commit is contained in:
parent
393c458495
commit
cb3fc3c70e
1
TODO.md
1
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
|
## UX
|
||||||
- File associations editor
|
- File associations editor
|
||||||
|
- Optional file discovery before file operations
|
||||||
- Modifiable CryFS scrypt parameters
|
- Modifiable CryFS scrypt parameters
|
||||||
- Alert dialog showing details of file operations
|
- Alert dialog showing details of file operations
|
||||||
- Internal file browser to select volumes
|
- Internal file browser to select volumes
|
||||||
|
@ -190,7 +190,9 @@ class VolumeOpener(
|
|||||||
.setTitle(R.string.open_volume_failed)
|
.setTitle(R.string.open_volume_failed)
|
||||||
.setMessage(getErrorMsg(result))
|
.setMessage(getErrorMsg(result))
|
||||||
.setPositiveButton(R.string.ok) { _, _ ->
|
.setPositiveButton(R.string.ok) { _, _ ->
|
||||||
askForPassword(volume, isVolumeSaved, callbacks, savePasswordHash)
|
if (result.worthRetry) {
|
||||||
|
askForPassword(volume, isVolumeSaved, callbacks, savePasswordHash)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
} else {
|
} else {
|
||||||
|
@ -20,6 +20,8 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.MainScope
|
import kotlinx.coroutines.MainScope
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.coroutines.coroutineScope
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
import sushi.hardcore.droidfs.Constants
|
import sushi.hardcore.droidfs.Constants
|
||||||
import sushi.hardcore.droidfs.R
|
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> {
|
private suspend fun <T> waitForTask(notification: FileOperationNotification, task: Deferred<T>): TaskResult<out T> {
|
||||||
tasks[notification.notificationId] = task
|
tasks[notification.notificationId] = task
|
||||||
return serviceScope.async {
|
return coroutineScope {
|
||||||
try {
|
withContext(serviceScope.coroutineContext) {
|
||||||
TaskResult.completed(task.await())
|
try {
|
||||||
} catch (e: CancellationException) {
|
TaskResult.completed(task.await())
|
||||||
TaskResult.cancelled()
|
} catch (e: CancellationException) {
|
||||||
} catch (e: Throwable) {
|
TaskResult.cancelled()
|
||||||
e.printStackTrace()
|
} catch (e: Throwable) {
|
||||||
TaskResult.error(e.localizedMessage)
|
e.printStackTrace()
|
||||||
} finally {
|
TaskResult.error(e.localizedMessage)
|
||||||
cancelNotification(notification)
|
} finally {
|
||||||
|
cancelNotification(notification)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.await()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun <T> volumeTask(
|
private suspend fun <T> volumeTask(
|
||||||
|
@ -68,7 +68,10 @@ class CryfsVolume(private val fusePtr: Long): EncryptedVolume() {
|
|||||||
result.errorCode = errorCode.value ?: 0
|
result.errorCode = errorCode.value ?: 0
|
||||||
result.errorStringId = when (errorCode.value) {
|
result.errorStringId = when (errorCode.value) {
|
||||||
// Values from src/cryfs/impl/ErrorCodes.h
|
// 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
|
16 -> R.string.inaccessible_base_dir
|
||||||
19 -> R.string.config_load_error
|
19 -> R.string.config_load_error
|
||||||
20 -> R.string.filesystem_id_changed
|
20 -> R.string.filesystem_id_changed
|
||||||
|
@ -8,7 +8,6 @@ import sushi.hardcore.droidfs.Constants
|
|||||||
import sushi.hardcore.droidfs.VolumeData
|
import sushi.hardcore.droidfs.VolumeData
|
||||||
import sushi.hardcore.droidfs.explorers.ExplorerElement
|
import sushi.hardcore.droidfs.explorers.ExplorerElement
|
||||||
import sushi.hardcore.droidfs.util.ObjRef
|
import sushi.hardcore.droidfs.util.ObjRef
|
||||||
import sushi.hardcore.droidfs.util.PathUtils
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
@ -16,13 +15,19 @@ import java.io.OutputStream
|
|||||||
|
|
||||||
abstract class EncryptedVolume: Parcelable {
|
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 {
|
class Builder {
|
||||||
var errorCode = 0
|
var errorCode = 0
|
||||||
var errorStringId = 0
|
var errorStringId = 0
|
||||||
|
var worthRetry = false
|
||||||
var volume: EncryptedVolume? = null
|
var volume: EncryptedVolume? = null
|
||||||
|
|
||||||
fun build() = InitResult(errorCode, errorStringId, volume)
|
fun build() = InitResult(errorCode, errorStringId, worthRetry, volume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,10 @@ class GocryptfsVolume(private val sessionID: Int): EncryptedVolume() {
|
|||||||
result.errorCode = sessionId
|
result.errorCode = sessionId
|
||||||
result.errorStringId = when (sessionId) {
|
result.errorStringId = when (sessionId) {
|
||||||
-1 -> R.string.config_load_error
|
-1 -> R.string.config_load_error
|
||||||
-2 -> R.string.wrong_password
|
-2 -> {
|
||||||
|
result.worthRetry = true
|
||||||
|
R.string.wrong_password
|
||||||
|
}
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user