mirror of
				https://github.com/oxen-io/session-android.git
				synced 2025-10-25 01:11:17 +00:00 
			
		
		
		
	 Jake McGinty
					Jake McGinty
				
			
				
					committed by
					
						 Moxie Marlinspike
						Moxie Marlinspike
					
				
			
			
				
	
			
			
			 Moxie Marlinspike
						Moxie Marlinspike
					
				
			
						parent
						
							7e2c9f97e9
						
					
				
				
					commit
					80ce83ef9d
				
			| @@ -752,7 +752,7 @@ public class MmsDatabase extends MessagingDatabase { | ||||
|  | ||||
|     if (sendRequest.getBody() != null) { | ||||
|       for (int i = 0; i < sendRequest.getBody().getPartsNum(); i++) { | ||||
|         sendRequest.getBody().getPart(i).setInProgress(true); | ||||
|         sendRequest.getBody().getPart(i).setTransferProgress(PartDatabase.TRANSFER_PROGRESS_STARTED); | ||||
|       } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -23,14 +23,18 @@ import android.database.sqlite.SQLiteDatabase; | ||||
| import android.database.sqlite.SQLiteOpenHelper; | ||||
| import android.graphics.Bitmap; | ||||
| import android.net.Uri; | ||||
| import android.support.annotation.NonNull; | ||||
| import android.text.TextUtils; | ||||
| import android.util.Log; | ||||
| import android.util.Pair; | ||||
|  | ||||
| import org.thoughtcrime.securesms.ApplicationContext; | ||||
| import org.thoughtcrime.securesms.crypto.DecryptingPartInputStream; | ||||
| import org.thoughtcrime.securesms.crypto.EncryptingPartOutputStream; | ||||
| import org.thoughtcrime.securesms.crypto.MasterSecret; | ||||
| import org.thoughtcrime.securesms.crypto.MasterSecretUnion; | ||||
| import org.thoughtcrime.securesms.jobs.requirements.MediaNetworkRequirement; | ||||
| import org.thoughtcrime.securesms.jobs.requirements.MediaNetworkRequirementProvider; | ||||
| import org.thoughtcrime.securesms.mms.PartAuthority; | ||||
| import org.thoughtcrime.securesms.util.MediaUtil; | ||||
| import org.thoughtcrime.securesms.util.MediaUtil.ThumbnailData; | ||||
| @@ -43,12 +47,14 @@ import java.io.FileNotFoundException; | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| import java.io.OutputStream; | ||||
| import java.io.Serializable; | ||||
| import java.util.LinkedList; | ||||
| import java.util.List; | ||||
| import java.util.concurrent.Callable; | ||||
| import java.util.concurrent.ExecutionException; | ||||
| import java.util.concurrent.ExecutorService; | ||||
|  | ||||
| import de.greenrobot.event.EventBus; | ||||
| import ws.com.google.android.mms.ContentType; | ||||
| import ws.com.google.android.mms.MmsException; | ||||
| import ws.com.google.android.mms.pdu.PduBody; | ||||
| @@ -72,12 +78,17 @@ public class PartDatabase extends Database { | ||||
|   private static final String CONTENT_TYPE_TYPE   = "ctt_t"; | ||||
|   private static final String ENCRYPTED           = "encrypted"; | ||||
|   private static final String DATA                = "_data"; | ||||
|   private static final String IN_PROGRESS         = "pending_push"; | ||||
|   private static final String TRANSFER_STATE      = "pending_push"; | ||||
|   private static final String SIZE                = "data_size"; | ||||
|   private static final String THUMBNAIL           = "thumbnail"; | ||||
|   private static final String ASPECT_RATIO        = "aspect_ratio"; | ||||
|   private static final String UNIQUE_ID           = "unique_id"; | ||||
|  | ||||
|   public static final int TRANSFER_PROGRESS_DONE         = 0; | ||||
|   public static final int TRANSFER_PROGRESS_STARTED      = 1; | ||||
|   public static final int TRANSFER_PROGRESS_AUTO_PENDING = 2; | ||||
|   public static final int TRANSFER_PROGRESS_FAILED       = 3; | ||||
|  | ||||
|   private static final String PART_ID_WHERE = ROW_ID + " = ? AND " + UNIQUE_ID + " = ?"; | ||||
|  | ||||
|   public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + ROW_ID + " INTEGER PRIMARY KEY, " + | ||||
| @@ -86,12 +97,12 @@ public class PartDatabase extends Database { | ||||
|     CONTENT_DISPOSITION + " TEXT, " + FILENAME + " TEXT, " + CONTENT_ID + " TEXT, "  + | ||||
|     CONTENT_LOCATION + " TEXT, " + CONTENT_TYPE_START + " INTEGER, "                 + | ||||
|     CONTENT_TYPE_TYPE + " TEXT, " + ENCRYPTED + " INTEGER, "                         + | ||||
|     IN_PROGRESS + " INTEGER, "+ DATA + " TEXT, " + SIZE + " INTEGER, "   + | ||||
|     TRANSFER_STATE + " INTEGER, "+ DATA + " TEXT, " + SIZE + " INTEGER, "   + | ||||
|     THUMBNAIL + " TEXT, " + ASPECT_RATIO + " REAL, " + UNIQUE_ID + " INTEGER NOT NULL);"; | ||||
|  | ||||
|   public static final String[] CREATE_INDEXS = { | ||||
|     "CREATE INDEX IF NOT EXISTS part_mms_id_index ON " + TABLE_NAME + " (" + MMS_ID + ");", | ||||
|     "CREATE INDEX IF NOT EXISTS pending_push_index ON " + TABLE_NAME + " (" + IN_PROGRESS + ");", | ||||
|     "CREATE INDEX IF NOT EXISTS pending_push_index ON " + TABLE_NAME + " (" + TRANSFER_STATE + ");", | ||||
|   }; | ||||
|  | ||||
|   private final static String IMAGES_QUERY = "SELECT " + TABLE_NAME + "." + ROW_ID + ", " | ||||
| @@ -127,7 +138,7 @@ public class PartDatabase extends Database { | ||||
|     SQLiteDatabase database = databaseHelper.getWritableDatabase(); | ||||
|  | ||||
|     part.setContentDisposition(new byte[0]); | ||||
|     part.setInProgress(false); | ||||
|     part.setTransferProgress(TRANSFER_PROGRESS_FAILED); | ||||
|  | ||||
|     ContentValues values = getContentValuesForPart(part); | ||||
|  | ||||
| @@ -223,6 +234,7 @@ public class PartDatabase extends Database { | ||||
|   } | ||||
|  | ||||
|   void insertParts(MasterSecretUnion masterSecret, long mmsId, PduBody body) throws MmsException { | ||||
|     Log.w(TAG, "insertParts(" + body.getPartsNum() + ")"); | ||||
|     for (int i=0;i<body.getPartsNum();i++) { | ||||
|       PduPart part = body.getPart(i); | ||||
|       PartId partId = insertPart(masterSecret, part, mmsId, part.getThumbnail()); | ||||
| @@ -234,6 +246,7 @@ public class PartDatabase extends Database { | ||||
|  | ||||
|     part.setRowId(cursor.getLong(cursor.getColumnIndexOrThrow(ROW_ID))); | ||||
|     part.setUniqueId(cursor.getLong(cursor.getColumnIndexOrThrow(UNIQUE_ID))); | ||||
|     part.setMmsId(cursor.getLong(cursor.getColumnIndexOrThrow(MMS_ID))); | ||||
|  | ||||
|     int charsetColumn = cursor.getColumnIndexOrThrow(CHARSET); | ||||
|  | ||||
| @@ -275,16 +288,15 @@ public class PartDatabase extends Database { | ||||
|     if (!cursor.isNull(encryptedColumn)) | ||||
|       part.setEncrypted(cursor.getInt(encryptedColumn) == 1); | ||||
|  | ||||
|     int inProgressColumn = cursor.getColumnIndexOrThrow(IN_PROGRESS); | ||||
|     int transferStateColumn = cursor.getColumnIndexOrThrow(TRANSFER_STATE); | ||||
|  | ||||
|     if (!cursor.isNull(inProgressColumn)) | ||||
|       part.setInProgress(cursor.getInt(inProgressColumn) == 1); | ||||
|     if (!cursor.isNull(transferStateColumn)) | ||||
|       part.setTransferProgress(cursor.getInt(transferStateColumn)); | ||||
|  | ||||
|     int sizeColumn = cursor.getColumnIndexOrThrow(SIZE); | ||||
|  | ||||
|     if (!cursor.isNull(sizeColumn)) | ||||
|       part.setDataSize(cursor.getLong(cursor.getColumnIndexOrThrow(SIZE))); | ||||
|  | ||||
|   } | ||||
|  | ||||
|   private ContentValues getContentValuesForPart(PduPart part) throws MmsException { | ||||
| @@ -325,7 +337,7 @@ public class PartDatabase extends Database { | ||||
|     } | ||||
|  | ||||
|     contentValues.put(ENCRYPTED, part.getEncrypted() ? 1 : 0); | ||||
|     contentValues.put(IN_PROGRESS, part.isInProgress() ? 1 : 0); | ||||
|     contentValues.put(TRANSFER_STATE, part.getTransferProgress()); | ||||
|     contentValues.put(UNIQUE_ID, part.getUniqueId()); | ||||
|  | ||||
|     return contentValues; | ||||
| @@ -423,7 +435,7 @@ public class PartDatabase extends Database { | ||||
|   } | ||||
|  | ||||
|   private PduPart getPart(Cursor cursor) { | ||||
|     PduPart part   = new PduPart(); | ||||
|     PduPart part = new PduPart(); | ||||
|  | ||||
|     getPartValues(part, cursor); | ||||
|  | ||||
| @@ -432,6 +444,23 @@ public class PartDatabase extends Database { | ||||
|     return part; | ||||
|   } | ||||
|  | ||||
|   public List<PduPart> getPendingParts() { | ||||
|     final SQLiteDatabase database = databaseHelper.getReadableDatabase(); | ||||
|     final List<PduPart>  parts    = new LinkedList<>(); | ||||
|  | ||||
|     Cursor cursor = null; | ||||
|     try { | ||||
|       cursor = database.query(TABLE_NAME, null, TRANSFER_STATE + " = ?", new String[] {String.valueOf(TRANSFER_PROGRESS_STARTED)}, null, null, null); | ||||
|       while (cursor != null && cursor.moveToNext()) { | ||||
|         parts.add(getPart(cursor)); | ||||
|       } | ||||
|     } finally { | ||||
|       if (cursor != null) cursor.close(); | ||||
|     } | ||||
|  | ||||
|     return parts; | ||||
|   } | ||||
|  | ||||
|   private PartId insertPart(MasterSecretUnion masterSecret, PduPart part, long mmsId, Bitmap thumbnail) throws MmsException { | ||||
|     Log.w(TAG, "inserting part to mms " + mmsId); | ||||
|     SQLiteDatabase   database = databaseHelper.getWritableDatabase(); | ||||
| @@ -472,7 +501,7 @@ public class PartDatabase extends Database { | ||||
|     Pair<File, Long> partData = writePartData(masterSecret, part, data); | ||||
|  | ||||
|     part.setContentDisposition(new byte[0]); | ||||
|     part.setInProgress(false); | ||||
|     part.setTransferProgress(TRANSFER_PROGRESS_DONE); | ||||
|  | ||||
|     ContentValues values = getContentValuesForPart(part); | ||||
|  | ||||
| @@ -492,13 +521,23 @@ public class PartDatabase extends Database { | ||||
|     ContentValues  values   = new ContentValues(1); | ||||
|     SQLiteDatabase database = databaseHelper.getWritableDatabase(); | ||||
|  | ||||
|     part.setInProgress(false); | ||||
|     values.put(IN_PROGRESS, false); | ||||
|     part.setTransferProgress(TRANSFER_PROGRESS_DONE); | ||||
|     values.put(TRANSFER_STATE, TRANSFER_PROGRESS_DONE); | ||||
|     database.update(TABLE_NAME, values, PART_ID_WHERE, part.getPartId().toStrings()); | ||||
|  | ||||
|     notifyConversationListeners(DatabaseFactory.getMmsDatabase(context).getThreadIdForMessage(messageId)); | ||||
|   } | ||||
|  | ||||
|   public void setTransferState(long messageId, @NonNull PartId partId, int transferState) { | ||||
|     final ContentValues  values   = new ContentValues(1); | ||||
|     final SQLiteDatabase database = databaseHelper.getWritableDatabase(); | ||||
|  | ||||
|     values.put(TRANSFER_STATE, transferState); | ||||
|     database.update(TABLE_NAME, values, PART_ID_WHERE, partId.toStrings()); | ||||
|     notifyConversationListeners(DatabaseFactory.getMmsDatabase(context).getThreadIdForMessage(messageId)); | ||||
|     ApplicationContext.getInstance(context).notifyMediaControlEvent(); | ||||
|   } | ||||
|  | ||||
|   public void updatePartData(MasterSecret masterSecret, PduPart part, InputStream data) | ||||
|       throws MmsException | ||||
|   { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user