#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 {
|
private fun createNewDocumentUri(parentUri: Uri, fileName: String): Uri {
|
||||||
val mimeType = mimeTypes.fromFilename(fileName) //
|
val mimeType = mimeTypes.fromFilename(fileName) //
|
||||||
.orElse(MimeType.APPLICATION_OCTET_STREAM)
|
.orElse(MimeType.APPLICATION_OCTET_STREAM)
|
||||||
val newDocumentUri: Uri?
|
return try {
|
||||||
newDocumentUri = try {
|
|
||||||
DocumentsContract.createDocument( //
|
DocumentsContract.createDocument( //
|
||||||
context().contentResolver, //
|
context().contentResolver, //
|
||||||
parentUri, //
|
parentUri, //
|
||||||
@ -859,11 +858,7 @@ class BrowseFilesPresenter @Inject constructor( //
|
|||||||
fileName)
|
fileName)
|
||||||
} catch (e: FileNotFoundException) {
|
} catch (e: FileNotFoundException) {
|
||||||
throw NoSuchCloudFileException(fileName)
|
throw NoSuchCloudFileException(fileName)
|
||||||
}
|
} ?: throw IllegalFileNameException()
|
||||||
if (newDocumentUri == null) {
|
|
||||||
throw IllegalFileNameException()
|
|
||||||
}
|
|
||||||
return newDocumentUri
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback
|
@Callback
|
||||||
@ -1093,7 +1088,7 @@ class BrowseFilesPresenter @Inject constructor( //
|
|||||||
|
|
||||||
fun openFileFinished() {
|
fun openFileFinished() {
|
||||||
try {
|
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)
|
Thread.sleep(500)
|
||||||
} catch (e: InterruptedException) {
|
} catch (e: InterruptedException) {
|
||||||
Timber.tag("BrowseFilesPresenter").e(e, "Failed to sleep after resuming editing, necessary for google office apps")
|
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)
|
context().revokeUriPermission(uriToOpenedFile, Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
|
||||||
uriToOpenedFile?.let {
|
uriToOpenedFile?.let {
|
||||||
val hashAfterEdit = calculateDigestFromUri(it)
|
try {
|
||||||
if (hashAfterEdit.isPresent && openedCloudFileMd5.isPresent //
|
val hashAfterEdit = calculateDigestFromUri(it)
|
||||||
&& Arrays.equals(hashAfterEdit.get(), openedCloudFileMd5.get())) {
|
if (hashAfterEdit.isPresent && openedCloudFileMd5.isPresent //
|
||||||
Timber.tag("BrowseFilesPresenter").i("Opened app finished, file not changed")
|
&& Arrays.equals(hashAfterEdit.get(), openedCloudFileMd5.get())) {
|
||||||
} else {
|
Timber.tag("BrowseFilesPresenter").i("Opened app finished, file not changed")
|
||||||
uploadChangedFile()
|
} 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() }
|
openWritableFileNotification.ifPresent { obj: OpenWritableFileNotification -> obj.hide() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Throws(FileNotFoundException::class)
|
||||||
private fun calculateDigestFromUri(uri: Uri): Optional<ByteArray> {
|
private fun calculateDigestFromUri(uri: Uri): Optional<ByteArray> {
|
||||||
val digest = MessageDigest.getInstance("MD5")
|
val digest = MessageDigest.getInstance("MD5")
|
||||||
DigestInputStream(context().contentResolver.openInputStream(uri), digest).use { dis ->
|
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_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_play_services_not_available">Play Services not installed</string>
|
||||||
<string name="error_biometric_auth_aborted">Biometric authentication aborted</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 -->
|
<!-- # clouds -->
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user