+ * The functionality of this class should be refactored to use
+ * MediaStore.
*/
class MediaRepository {
diff --git a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java
index 5f13c13e6c..53e4ca54cc 100644
--- a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java
+++ b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java
@@ -46,6 +46,7 @@ import org.thoughtcrime.securesms.components.RemovableEditableMediaView;
import org.thoughtcrime.securesms.components.ThumbnailView;
import org.thoughtcrime.securesms.components.location.SignalMapView;
import org.thoughtcrime.securesms.components.location.SignalPlace;
+import org.thoughtcrime.securesms.database.NoExternalStorageException;
import org.thoughtcrime.securesms.giph.ui.GiphyActivity;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.mediasend.MediaSendActivity;
@@ -54,6 +55,8 @@ import org.thoughtcrime.securesms.providers.BlobProvider;
import org.thoughtcrime.securesms.providers.DeprecatedPersistentBlobProvider;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.BitmapUtil;
+import org.thoughtcrime.securesms.util.ExternalStorageUtil;
+import org.thoughtcrime.securesms.util.FileProviderUtil;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.thoughtcrime.securesms.util.ThemeUtil;
import org.thoughtcrime.securesms.util.Util;
@@ -65,6 +68,7 @@ import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
import org.thoughtcrime.securesms.util.views.Stub;
import org.whispersystems.libsignal.util.guava.Optional;
+import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
@@ -73,6 +77,8 @@ import java.util.concurrent.ExecutionException;
import network.loki.messenger.R;
+import static android.provider.MediaStore.EXTRA_OUTPUT;
+
public class AttachmentManager {
@@ -112,7 +118,6 @@ public class AttachmentManager {
thumbnail.setOnClickListener(new ThumbnailClickListener());
documentView.getBackground().setColorFilter(ThemeUtil.getThemedColor(context, R.attr.conversation_item_bubble_background), PorterDuff.Mode.MULTIPLY);
}
-
}
public void clear(@NonNull GlideRequests glideRequests, boolean animate) {
@@ -438,25 +443,29 @@ public class AttachmentManager {
public void capturePhoto(Activity activity, int requestCode) {
Permissions.with(activity)
- .request(Manifest.permission.CAMERA)
- .ifNecessary()
- .withPermanentDenialDialog(activity.getString(R.string.AttachmentManager_signal_requires_the_camera_permission_in_order_to_take_photos_but_it_has_been_permanently_denied))
- .onAllGranted(() -> {
- try {
- Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- if (captureIntent.resolveActivity(activity.getPackageManager()) != null) {
- if (captureUri == null) {
- captureUri = DeprecatedPersistentBlobProvider.getInstance(context).createForExternal(context, MediaUtil.IMAGE_JPEG);
- }
- Log.d(TAG, "captureUri path is " + captureUri.getPath());
- captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, captureUri);
- activity.startActivityForResult(captureIntent, requestCode);
- }
- } catch (IOException ioe) {
- Log.w(TAG, ioe);
- }
- })
- .execute();
+ .request(Manifest.permission.CAMERA)
+ .ifNecessary()
+ .withPermanentDenialDialog(activity.getString(R.string.AttachmentManager_signal_requires_the_camera_permission_in_order_to_take_photos_but_it_has_been_permanently_denied))
+ .onAllGranted(() -> {
+ try {
+ File captureFile = File.createTempFile(
+ "conversation-capture",
+ ".jpg",
+ ExternalStorageUtil.getImageDir(activity));
+ Uri captureUri = FileProviderUtil.getUriFor(context, captureFile);
+ Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
+ captureIntent.putExtra(EXTRA_OUTPUT, captureUri);
+ captureIntent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+ if (captureIntent.resolveActivity(activity.getPackageManager()) != null) {
+ Log.d(TAG, "captureUri path is " + captureUri.getPath());
+ this.captureUri = captureUri;
+ activity.startActivityForResult(captureIntent, requestCode);
+ }
+ } catch (IOException | NoExternalStorageException e) {
+ throw new RuntimeException("Error creating image capture intent.", e);
+ }
+ })
+ .execute();
}
private static void selectMediaType(Activity activity, @NonNull String type, @Nullable String[] extraMimeType, int requestCode) {
diff --git a/src/org/thoughtcrime/securesms/mms/DocumentSlide.java b/src/org/thoughtcrime/securesms/mms/DocumentSlide.java
index 24d6ceb133..968e8dd441 100644
--- a/src/org/thoughtcrime/securesms/mms/DocumentSlide.java
+++ b/src/org/thoughtcrime/securesms/mms/DocumentSlide.java
@@ -7,7 +7,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.thoughtcrime.securesms.attachments.Attachment;
-import org.thoughtcrime.securesms.util.StorageUtil;
+import org.thoughtcrime.securesms.util.ExternalStorageUtil;
public class DocumentSlide extends Slide {
@@ -19,7 +19,7 @@ public class DocumentSlide extends Slide {
@NonNull String contentType, long size,
@Nullable String fileName)
{
- super(context, constructAttachmentFromUri(context, uri, contentType, size, 0, 0, true, StorageUtil.getCleanFileName(fileName), null, null, false, false));
+ super(context, constructAttachmentFromUri(context, uri, contentType, size, 0, 0, true, ExternalStorageUtil.getCleanFileName(fileName), null, null, false, false));
}
@Override
diff --git a/src/org/thoughtcrime/securesms/permissions/Permissions.java b/src/org/thoughtcrime/securesms/permissions/Permissions.java
index 70e2da80fb..f647da6db4 100644
--- a/src/org/thoughtcrime/securesms/permissions/Permissions.java
+++ b/src/org/thoughtcrime/securesms/permissions/Permissions.java
@@ -171,7 +171,7 @@ public class Permissions {
}
for (String permission : requestedPermissions) {
- request.addMapping(permission, permissionObject.shouldShouldPermissionRationale(permission));
+ request.addMapping(permission, permissionObject.shouldShowPermissionRationale(permission));
}
permissionObject.requestPermissions(requestCode, requestedPermissions);
@@ -240,7 +240,7 @@ public class Permissions {
for (int i=0;i