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) { private void setSlide(@NonNull Slide slide) {
if (getSlideUri() != null) cleanup(getSlideUri()); if (getSlideUri() != null) {
if (captureUri != null && !captureUri.equals(slide.getUri())) cleanup(captureUri); cleanup(getSlideUri());
}
this.captureUri = null; if (captureUri != null && !captureUri.equals(slide.getUri())) {
this.slide = Optional.of(slide); cleanup(captureUri);
captureUri = null;
}
this.slide = Optional.of(slide);
} }
public ListenableFuture<Boolean> setLocation(@NonNull final SignalPlace place, 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.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import android.util.Pair; import android.util.Pair;
import android.webkit.MimeTypeMap; import android.webkit.MimeTypeMap;
@ -145,7 +146,7 @@ public class PersistentBlobProvider {
//noinspection SimplifiableIfStatement //noinspection SimplifiableIfStatement
if (isExternalBlobUri(context, uri)) { if (isExternalBlobUri(context, uri)) {
return new File(uri.getPath()).delete(); return FileProviderUtil.delete(context, uri);
} }
return false; return false;
@ -238,8 +239,9 @@ public class PersistentBlobProvider {
private static boolean isExternalBlobUri(@NonNull Context context, @NonNull Uri uri) { private static boolean isExternalBlobUri(@NonNull Context context, @NonNull Uri uri) {
try { try {
return uri.getPath().startsWith(getExternalDir(context).getAbsolutePath()); return uri.getPath().startsWith(getExternalDir(context).getAbsolutePath()) || FileProviderUtil.isAuthority(uri);
} catch (IOException ioe) { } catch (IOException ioe) {
Log.w(TAG, "Failed to determine if it's an external blob URI.", ioe);
return false; return false;
} }
} }

View File

@ -18,4 +18,14 @@ public class FileProviderUtil {
else return Uri.fromFile(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();
}
} }