fix direct capture file writing race condition

fixes #4612
Closes #4634
// FREEBIE
This commit is contained in:
Jake McGinty 2015-11-20 11:03:40 -08:00 committed by Moxie Marlinspike
parent 3bfb123b33
commit a04e737526
2 changed files with 8 additions and 6 deletions

View File

@ -1351,7 +1351,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
@Override
public void onImageCapture(@NonNull final byte[] imageBytes) {
setMedia(PersistentBlobProvider.getInstance(this).create(masterSecret, recipients, imageBytes), MediaType.IMAGE);
setMedia(PersistentBlobProvider.getInstance(this).create(masterSecret, imageBytes), MediaType.IMAGE);
quickAttachmentDrawer.hide(false);
}

View File

@ -4,7 +4,6 @@ import android.content.ContentUris;
import android.content.Context;
import android.content.UriMatcher;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.util.Log;
@ -61,10 +60,9 @@ public class PersistentBlobProvider {
}
public Uri create(@NonNull MasterSecret masterSecret,
@NonNull Recipients recipients,
@NonNull byte[] imageBytes)
{
final long id = generateId(recipients);
final long id = System.currentTimeMillis();
cache.put(id, imageBytes);
return create(masterSecret, new ByteArrayInputStream(imageBytes), id);
}
@ -108,8 +106,12 @@ public class PersistentBlobProvider {
public boolean delete(@NonNull Uri uri) {
switch (MATCHER.match(uri)) {
case MATCH: return getFile(ContentUris.parseId(uri)).delete();
default: return new File(uri.getPath()).delete();
case MATCH:
long id = ContentUris.parseId(uri);
cache.remove(id);
return getFile(ContentUris.parseId(uri)).delete();
default:
return new File(uri.getPath()).delete();
}
}