Merge branch 'master' into '2277-activity-not-found-exception'

# Conflicts:
#   briar-android/src/main/java/org/briarproject/briar/android/conversation/ImageActivity.java
This commit is contained in:
akwizgran
2022-04-18 16:18:14 +00:00
11 changed files with 69 additions and 28 deletions

View File

@@ -26,6 +26,7 @@ import static org.briarproject.bramble.util.IoUtils.tryToClose;
import static org.briarproject.bramble.util.LogUtils.logDuration;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.LogUtils.now;
import static org.briarproject.briar.android.attachment.media.ImageCompressor.MIME_TYPE;
@NotNullByDefault
class AttachmentCreationTask {
@@ -100,14 +101,17 @@ class AttachmentCreationTask {
if (!asList(getSupportedImageContentTypes()).contains(contentType)) {
throw new UnsupportedMimeTypeException(contentType, uri);
}
InputStream is = contentResolver.openInputStream(uri);
if (is == null) throw new IOException();
is = imageCompressor
.compressImage(is, contentType);
InputStream is;
try {
is = contentResolver.openInputStream(uri);
if (is == null) throw new IOException();
} catch (SecurityException e) {
throw new IOException(e);
}
is = imageCompressor.compressImage(is, contentType);
long timestamp = System.currentTimeMillis();
AttachmentHeader h = messagingManager
.addLocalAttachment(groupId, timestamp,
ImageCompressor.MIME_TYPE, is);
AttachmentHeader h = messagingManager.addLocalAttachment(groupId,
timestamp, MIME_TYPE, is);
tryToClose(is, LOG, WARNING);
logDuration(LOG, "Storing attachment", start);
return h;

View File

@@ -1,5 +1,6 @@
package org.briarproject.briar.android.conversation;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
@@ -259,7 +260,11 @@ public class ImageActivity extends BriarActivity
if (SDK_INT >= 19) {
String name = viewModel.getFileName() + "." +
getVisibleAttachment().getExtension();
requireNonNull(launcher).launch(name);
try {
requireNonNull(launcher).launch(name);
} catch (ActivityNotFoundException e) {
viewModel.onSaveImageError();
}
} else {
viewModel.saveImage(getVisibleAttachment());
}

View File

@@ -180,12 +180,17 @@ public class ImageViewModel extends DbViewModel implements EventListener {
@UiThread
void saveImage(AttachmentItem attachment, @Nullable Uri uri) {
if (uri == null) {
saveState.setEvent(true);
onSaveImageError();
} else {
saveImage(attachment, () -> getOutputStream(uri), null);
}
}
@UiThread
void onSaveImageError() {
saveState.setEvent(true);
}
/**
* Saves the attachment on external storage,
* assuming the permission was granted during install time.

View File

@@ -231,9 +231,14 @@ class SettingsViewModel extends DbViewModel implements EventListener {
if (!asList(getSupportedImageContentTypes()).contains(contentType)) {
throw new UnsupportedMimeTypeException(contentType, uri);
}
InputStream is = contentResolver.openInputStream(uri);
if (is == null) throw new IOException(
"ContentResolver returned null when opening InputStream");
InputStream is;
try {
is = contentResolver.openInputStream(uri);
if (is == null) throw new IOException(
"ContentResolver returned null when opening InputStream");
} catch (SecurityException e) {
throw new IOException(e);
}
InputStream compressed = imageCompressor.compressImage(is, contentType);
runOnDbThread(() -> {