mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 08:47:46 +00:00
Ensure external camera blob is deleted.
This commit is contained in:
parent
e09c99102e
commit
741b775d3e
@ -175,10 +175,15 @@ 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());
|
||||
}
|
||||
|
||||
if (captureUri != null && !captureUri.equals(slide.getUri())) {
|
||||
cleanup(captureUri);
|
||||
captureUri = null;
|
||||
}
|
||||
|
||||
this.captureUri = null;
|
||||
this.slide = Optional.of(slide);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user