Ensure external camera blob is deleted.

This commit is contained in:
Greyson Parrelli 2018-09-12 17:47:41 -05:00
parent e09c99102e
commit 741b775d3e
3 changed files with 23 additions and 6 deletions

View File

@ -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<Boolean> setLocation(@NonNull final SignalPlace place,

View File

@ -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;
}
}

View File

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