Skip to content

Commit

Permalink
Ensure external camera blob is deleted.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Sep 18, 2018
1 parent e09c991 commit 741b775
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/org/thoughtcrime/securesms/mms/AttachmentManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,16 @@ private void markGarbage(@Nullable Uri uri) {
}

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());
}

if (captureUri != null && !captureUri.equals(slide.getUri())) {
cleanup(captureUri);
captureUri = null;
}

this.captureUri = null;
this.slide = Optional.of(slide);
this.slide = Optional.of(slide);
}

public ListenableFuture<Boolean> setLocation(@NonNull final SignalPlace place,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.thoughtcrime.securesms.logging.Log;

import android.util.Pair;
import android.webkit.MimeTypeMap;

Expand Down Expand Up @@ -145,7 +146,7 @@ public boolean delete(@NonNull Context context, @NonNull Uri uri) {

//noinspection SimplifiableIfStatement
if (isExternalBlobUri(context, uri)) {
return new File(uri.getPath()).delete();
return FileProviderUtil.delete(context, uri);
}

return false;
Expand Down Expand Up @@ -238,8 +239,9 @@ public static boolean isAuthority(@NonNull Context context, @NonNull Uri uri) {

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;
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/org/thoughtcrime/securesms/util/FileProviderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@ public static Uri getUriFor(@NonNull Context context, @NonNull File file) {
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();
}
}

0 comments on commit 741b775

Please sign in to comment.