mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 21:03:38 +00:00
fix crash on pending self-sent media
fixes #4016 Closes #4017 // FREEBIE
This commit is contained in:
parent
df164a58c9
commit
923d9fb07b
@ -34,6 +34,7 @@ import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.MmsDatabase;
|
||||
import org.thoughtcrime.securesms.database.MmsDatabase.Reader;
|
||||
import org.thoughtcrime.securesms.database.PartDatabase;
|
||||
import org.thoughtcrime.securesms.database.PushDatabase;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.jobs.AttachmentDownloadJob;
|
||||
@ -223,16 +224,20 @@ public class DatabaseUpgradeActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void schedulePendingIncomingParts(Context context) {
|
||||
MmsDatabase db = DatabaseFactory.getMmsDatabase(context);
|
||||
List<PduPart> pendingParts = DatabaseFactory.getPartDatabase(context).getPendingParts();
|
||||
final PartDatabase partDb = DatabaseFactory.getPartDatabase(context);
|
||||
final MmsDatabase mmsDb = DatabaseFactory.getMmsDatabase(context);
|
||||
final List<PduPart> pendingParts = DatabaseFactory.getPartDatabase(context).getPendingParts();
|
||||
|
||||
Log.w(TAG, pendingParts.size() + " pending parts.");
|
||||
for (PduPart part : pendingParts) {
|
||||
final Reader reader = db.readerFor(masterSecret, db.getMessage(part.getMmsId()));
|
||||
final Reader reader = mmsDb.readerFor(masterSecret, mmsDb.getMessage(part.getMmsId()));
|
||||
final MessageRecord record = reader.getNext();
|
||||
|
||||
if (record != null && !record.isOutgoing() && record.isPush()) {
|
||||
Log.w(TAG, "queuing new attachment download job for incoming push part.");
|
||||
if (part.getContentLocation() == null) {
|
||||
Log.w(TAG, "corrected a pending self-sent media part " + part.getPartId() + ".");
|
||||
partDb.setTransferState(part.getMmsId(), part.getPartId(), PartDatabase.TRANSFER_PROGRESS_DONE);
|
||||
} else if (record != null && !record.isOutgoing() && record.isPush()) {
|
||||
Log.w(TAG, "queuing new attachment download job for incoming push part " + part.getPartId() + ".");
|
||||
ApplicationContext.getInstance(context)
|
||||
.getJobManager()
|
||||
.add(new AttachmentDownloadJob(context, part.getMmsId(), part.getPartId()));
|
||||
|
@ -577,6 +577,10 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
contentValues.put(READ, 1);
|
||||
contentValues.put(DATE_RECEIVED, contentValues.getAsLong(DATE_SENT));
|
||||
|
||||
for (int i = 0; i < request.getBody().getPartsNum(); i++) {
|
||||
request.getBody().getPart(i).setTransferProgress(PartDatabase.TRANSFER_PROGRESS_DONE);
|
||||
}
|
||||
|
||||
return insertMediaMessage(new MasterSecretUnion(masterSecret), request.getPduHeaders(),
|
||||
request.getBody(), contentValues);
|
||||
} catch (NoSuchMessageException e) {
|
||||
|
@ -444,7 +444,7 @@ public class PartDatabase extends Database {
|
||||
return part;
|
||||
}
|
||||
|
||||
public List<PduPart> getPendingParts() {
|
||||
public @NonNull List<PduPart> getPendingParts() {
|
||||
final SQLiteDatabase database = databaseHelper.getReadableDatabase();
|
||||
final List<PduPart> parts = new LinkedList<>();
|
||||
|
||||
|
@ -88,6 +88,7 @@ public class AttachmentDownloadJob extends MasterSecretJob implements Injectable
|
||||
private void retrievePart(MasterSecret masterSecret, PduPart part, long messageId)
|
||||
throws IOException
|
||||
{
|
||||
|
||||
PartDatabase database = DatabaseFactory.getPartDatabase(context);
|
||||
File attachmentFile = null;
|
||||
|
||||
@ -115,6 +116,8 @@ public class AttachmentDownloadJob extends MasterSecretJob implements Injectable
|
||||
private TextSecureAttachmentPointer createAttachmentPointer(MasterSecret masterSecret, PduPart part)
|
||||
throws InvalidPartException
|
||||
{
|
||||
if (part.getContentLocation() == null) throw new InvalidPartException("null content location");
|
||||
|
||||
try {
|
||||
AsymmetricMasterSecret asymmetricMasterSecret = MasterSecretUtil.getAsymmetricMasterSecret(context, masterSecret);
|
||||
long id = Long.parseLong(Util.toIsoString(part.getContentLocation()));
|
||||
@ -153,6 +156,7 @@ public class AttachmentDownloadJob extends MasterSecretJob implements Injectable
|
||||
}
|
||||
|
||||
private static class InvalidPartException extends Exception {
|
||||
public InvalidPartException(String s) {super(s);}
|
||||
public InvalidPartException(Exception e) {super(e);}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user