#295 fix crash when opening a file using third party app and resuming
Crash or that the file is no longer available only occurs under certain circumstances
This commit is contained in:
parent
7f93b019c4
commit
99408e53fd
@ -850,8 +850,7 @@ class BrowseFilesPresenter @Inject constructor( //
|
||||
private fun createNewDocumentUri(parentUri: Uri, fileName: String): Uri {
|
||||
val mimeType = mimeTypes.fromFilename(fileName) //
|
||||
.orElse(MimeType.APPLICATION_OCTET_STREAM)
|
||||
val newDocumentUri: Uri?
|
||||
newDocumentUri = try {
|
||||
return try {
|
||||
DocumentsContract.createDocument( //
|
||||
context().contentResolver, //
|
||||
parentUri, //
|
||||
@ -859,11 +858,7 @@ class BrowseFilesPresenter @Inject constructor( //
|
||||
fileName)
|
||||
} catch (e: FileNotFoundException) {
|
||||
throw NoSuchCloudFileException(fileName)
|
||||
}
|
||||
if (newDocumentUri == null) {
|
||||
throw IllegalFileNameException()
|
||||
}
|
||||
return newDocumentUri
|
||||
} ?: throw IllegalFileNameException()
|
||||
}
|
||||
|
||||
@Callback
|
||||
@ -1093,7 +1088,7 @@ class BrowseFilesPresenter @Inject constructor( //
|
||||
|
||||
fun openFileFinished() {
|
||||
try {
|
||||
// necessary see https://gitlab.skymatic.de/cryptomator/android/-/issues/569
|
||||
// necessary see https://community.cryptomator.org/t/android-tabelle-nach-upload-unlesbar/6550
|
||||
Thread.sleep(500)
|
||||
} catch (e: InterruptedException) {
|
||||
Timber.tag("BrowseFilesPresenter").e(e, "Failed to sleep after resuming editing, necessary for google office apps")
|
||||
@ -1107,12 +1102,17 @@ class BrowseFilesPresenter @Inject constructor( //
|
||||
context().revokeUriPermission(uriToOpenedFile, Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
|
||||
uriToOpenedFile?.let {
|
||||
val hashAfterEdit = calculateDigestFromUri(it)
|
||||
if (hashAfterEdit.isPresent && openedCloudFileMd5.isPresent //
|
||||
&& Arrays.equals(hashAfterEdit.get(), openedCloudFileMd5.get())) {
|
||||
Timber.tag("BrowseFilesPresenter").i("Opened app finished, file not changed")
|
||||
} else {
|
||||
uploadChangedFile()
|
||||
try {
|
||||
val hashAfterEdit = calculateDigestFromUri(it)
|
||||
if (hashAfterEdit.isPresent && openedCloudFileMd5.isPresent //
|
||||
&& Arrays.equals(hashAfterEdit.get(), openedCloudFileMd5.get())) {
|
||||
Timber.tag("BrowseFilesPresenter").i("Opened app finished, file not changed")
|
||||
} else {
|
||||
uploadChangedFile()
|
||||
}
|
||||
} catch (e: FileNotFoundException) {
|
||||
Timber.tag("BrowseFilesPresenter").e(e, "Failed to read back changes, file isn't present anymore")
|
||||
Toast.makeText(context(), R.string.error_file_not_found_after_opening_using_3party, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1159,6 +1159,7 @@ class BrowseFilesPresenter @Inject constructor( //
|
||||
openWritableFileNotification.ifPresent { obj: OpenWritableFileNotification -> obj.hide() }
|
||||
}
|
||||
|
||||
@Throws(FileNotFoundException::class)
|
||||
private fun calculateDigestFromUri(uri: Uri): Optional<ByteArray> {
|
||||
val digest = MessageDigest.getInstance("MD5")
|
||||
DigestInputStream(context().contentResolver.openInputStream(uri), digest).use { dis ->
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="error_failed_to_decrypt_webdav_password">Failed to decrypt WebDAV password, please re add in settings</string>
|
||||
<string name="error_play_services_not_available">Play Services not installed</string>
|
||||
<string name="error_biometric_auth_aborted">Biometric authentication aborted</string>
|
||||
<string name="error_file_not_found_after_opening_using_3party">Local file isn\'t present anymore after switching back to Cryptomator. Possible changes cannot be propagated back to the cloud.</string>
|
||||
|
||||
<!-- # clouds -->
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user