diff --git a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java index 80d75a8224..0d9ad9b730 100644 --- a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java +++ b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java @@ -175,11 +175,16 @@ public class AttachmentManager { } private void setSlide(@NonNull Slide slide) { - if (getSlideUri() != null) cleanup(getSlideUri()); - if (captureUri != null && !captureUri.equals(slide.getUri())) cleanup(captureUri); + if (getSlideUri() != null) { + cleanup(getSlideUri()); + } - this.captureUri = null; - this.slide = Optional.of(slide); + if (captureUri != null && !captureUri.equals(slide.getUri())) { + cleanup(captureUri); + captureUri = null; + } + + this.slide = Optional.of(slide); } public ListenableFuture setLocation(@NonNull final SignalPlace place, diff --git a/src/org/thoughtcrime/securesms/providers/PersistentBlobProvider.java b/src/org/thoughtcrime/securesms/providers/PersistentBlobProvider.java index 0c5f57b440..8da3b63f24 100644 --- a/src/org/thoughtcrime/securesms/providers/PersistentBlobProvider.java +++ b/src/org/thoughtcrime/securesms/providers/PersistentBlobProvider.java @@ -8,6 +8,7 @@ import android.net.Uri; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.thoughtcrime.securesms.logging.Log; + import android.util.Pair; import android.webkit.MimeTypeMap; @@ -145,7 +146,7 @@ public class PersistentBlobProvider { //noinspection SimplifiableIfStatement if (isExternalBlobUri(context, uri)) { - return new File(uri.getPath()).delete(); + return FileProviderUtil.delete(context, uri); } return false; @@ -238,8 +239,9 @@ public class PersistentBlobProvider { private static boolean isExternalBlobUri(@NonNull Context context, @NonNull Uri uri) { try { - return uri.getPath().startsWith(getExternalDir(context).getAbsolutePath()); + return uri.getPath().startsWith(getExternalDir(context).getAbsolutePath()) || FileProviderUtil.isAuthority(uri); } catch (IOException ioe) { + Log.w(TAG, "Failed to determine if it's an external blob URI.", ioe); return false; } } diff --git a/src/org/thoughtcrime/securesms/util/FileProviderUtil.java b/src/org/thoughtcrime/securesms/util/FileProviderUtil.java index 26146e9dc4..cd45228503 100644 --- a/src/org/thoughtcrime/securesms/util/FileProviderUtil.java +++ b/src/org/thoughtcrime/securesms/util/FileProviderUtil.java @@ -18,4 +18,14 @@ public class FileProviderUtil { else return Uri.fromFile(file); } + public static boolean isAuthority(@NonNull Uri uri) { + return AUTHORITY.equals(uri.getAuthority()); + } + + public static boolean delete(@NonNull Context context, @NonNull Uri uri) { + if (AUTHORITY.equals(uri.getAuthority())) { + return context.getContentResolver().delete(uri, null, null) > 0; + } + return new File(uri.getPath()).delete(); + } }