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