mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
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:
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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(() -> {
|
||||
|
||||
Reference in New Issue
Block a user