2121import com .flowcrypt .email .database .dao .source .AccountDaoSource ;
2222import com .flowcrypt .email .database .dao .source .ContactsDaoSource ;
2323import com .flowcrypt .email .database .dao .source .KeysDaoSource ;
24+ import com .flowcrypt .email .database .dao .source .imap .AttachmentDaoSource ;
2425import com .flowcrypt .email .database .dao .source .imap .ImapLabelsDaoSource ;
2526import com .flowcrypt .email .database .dao .source .imap .MessageDaoSource ;
2627
@@ -46,6 +47,8 @@ public class SecurityContentProvider extends ContentProvider {
4647 private static final int MATCHED_CODE_IMAP_MESSAGES_SINGLE_ROW = 9 ;
4748 private static final int MATCHED_CODE_ACCOUNTS_TABLE = 10 ;
4849 private static final int MATCHED_CODE_ACCOUNTS_SINGLE_ROW = 11 ;
50+ private static final int MATCHED_CODE_ATTACHMENT_TABLE = 12 ;
51+ private static final int MATCHED_CODE_ATTACHMENT_SINGLE_ROW = 13 ;
4952
5053 private static final String SINGLE_APPENDED_SUFFIX = "/#" ;
5154 private static final UriMatcher URI_MATCHER = new UriMatcher (UriMatcher .NO_MATCH );
@@ -75,6 +78,10 @@ public class SecurityContentProvider extends ContentProvider {
7578 MATCHED_CODE_ACCOUNTS_TABLE );
7679 URI_MATCHER .addURI (FlowcryptContract .AUTHORITY , AccountDaoSource .TABLE_NAME_ACCOUNTS +
7780 SINGLE_APPENDED_SUFFIX , MATCHED_CODE_ACCOUNTS_SINGLE_ROW );
81+ URI_MATCHER .addURI (FlowcryptContract .AUTHORITY , AttachmentDaoSource .TABLE_NAME_ATTACHMENT ,
82+ MATCHED_CODE_ATTACHMENT_TABLE );
83+ URI_MATCHER .addURI (FlowcryptContract .AUTHORITY , AttachmentDaoSource .TABLE_NAME_ATTACHMENT +
84+ SINGLE_APPENDED_SUFFIX , MATCHED_CODE_ATTACHMENT_SINGLE_ROW );
7885 }
7986
8087 private FlowCryptSQLiteOpenHelper hotelDBHelper ;
@@ -119,24 +126,29 @@ public Uri insert(@NonNull Uri uri, ContentValues values) {
119126 case MATCHED_CODE_IMAP_LABELS_TABLE :
120127 id = sqLiteDatabase .insert (new ImapLabelsDaoSource ().getTableName (), null ,
121128 values );
122- result = Uri .parse (new ImapLabelsDaoSource ().getBaseContentUri () + "/" +
123- id );
129+ result = Uri .parse (new ImapLabelsDaoSource ().getBaseContentUri ()
130+ + "/" + id );
124131 break ;
125132
126133 case MATCHED_CODE_IMAP_MESSAGES_TABLE :
127134 id = sqLiteDatabase .insert (new MessageDaoSource ().getTableName (),
128135 null , values );
129136 result = Uri .parse (new MessageDaoSource ().getBaseContentUri ()
130- + "/" +
131- id );
137+ + "/" + id );
132138 break ;
133139
134140 case MATCHED_CODE_ACCOUNTS_TABLE :
135141 id = sqLiteDatabase .insert (new AccountDaoSource ().getTableName (),
136142 null , values );
137143 result = Uri .parse (new AccountDaoSource ().getBaseContentUri ()
138- + "/" +
139- id );
144+ + "/" + id );
145+ break ;
146+
147+ case MATCHED_CODE_ATTACHMENT_TABLE :
148+ id = sqLiteDatabase .insert (new AttachmentDaoSource ().getTableName (),
149+ null , values );
150+ result = Uri .parse (new AttachmentDaoSource ().getBaseContentUri ()
151+ + "/" + id );
140152 break ;
141153
142154 default :
@@ -235,6 +247,19 @@ public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
235247 }
236248 break ;
237249
250+ case MATCHED_CODE_ATTACHMENT_TABLE :
251+ for (ContentValues contentValues : values ) {
252+ long id = sqLiteDatabase .insert (
253+ new AttachmentDaoSource ().getTableName (), null ,
254+ contentValues );
255+ if (id <= 0 ) {
256+ throw new SQLException ("Failed to insert row into " + uri );
257+ } else {
258+ insertedRowsCount ++;
259+ }
260+ }
261+ break ;
262+
238263 default :
239264 throw new UnsupportedOperationException ("Unknown uri: " + uri );
240265 }
@@ -305,6 +330,14 @@ public int update(@NonNull Uri uri, ContentValues values, String selection,
305330 selectionArgs );
306331 break ;
307332
333+ case MATCHED_CODE_ATTACHMENT_TABLE :
334+ rowsCount = sqLiteDatabase .update (
335+ new AttachmentDaoSource ().getTableName (),
336+ values ,
337+ selection ,
338+ selectionArgs );
339+ break ;
340+
308341 default :
309342 throw new UnsupportedOperationException ("Unknown uri: " + uri );
310343 }
@@ -358,6 +391,11 @@ public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
358391 selection , selectionArgs );
359392 break ;
360393
394+ case MATCHED_CODE_ATTACHMENT_TABLE :
395+ rowsCount = sqLiteDatabase .delete (new AttachmentDaoSource ().getTableName (),
396+ selection , selectionArgs );
397+ break ;
398+
361399 default :
362400 throw new UnsupportedOperationException ("Unknown uri: " + uri );
363401 }
@@ -403,6 +441,10 @@ public Cursor query(@NonNull Uri uri, String[] projection, String selection,
403441 table = AccountDaoSource .TABLE_NAME_ACCOUNTS ;
404442 break ;
405443
444+ case MATCHED_CODE_ATTACHMENT_TABLE :
445+ table = AttachmentDaoSource .TABLE_NAME_ATTACHMENT ;
446+ break ;
447+
406448 default :
407449 throw new UnsupportedOperationException ("Unknown uri: " + uri );
408450 }
@@ -451,6 +493,12 @@ public String getType(@NonNull Uri uri) {
451493 case MATCHED_CODE_ACCOUNTS_SINGLE_ROW :
452494 return new AccountDaoSource ().getSingleRowContentType ();
453495
496+ case MATCHED_CODE_ATTACHMENT_TABLE :
497+ return new AttachmentDaoSource ().getRowsContentType ();
498+
499+ case MATCHED_CODE_ATTACHMENT_SINGLE_ROW :
500+ return new AttachmentDaoSource ().getSingleRowContentType ();
501+
454502 default :
455503 throw new IllegalArgumentException ("Unknown uri: " + uri );
456504 }
0 commit comments