55
66package com.flowcrypt.email.providers
77
8- import android.content.res.AssetFileDescriptor
98import android.database.Cursor
109import android.database.MatrixCursor
1110import android.net.Uri
12- import android.os.Bundle
1311import android.os.CancellationSignal
1412import android.os.ParcelFileDescriptor
1513import android.provider.DocumentsContract
1614import android.provider.DocumentsProvider
17- import android.util.Log
18- import android.widget.Toast
1915import com.flowcrypt.email.BuildConfig
2016import com.flowcrypt.email.api.email.model.AttachmentInfo
2117import com.flowcrypt.email.extensions.java.lang.printStackTraceIfDebugOnly
@@ -39,33 +35,7 @@ class EmbeddedAttachmentsProvider : DocumentsProvider() {
3935 }
4036
4137 override fun queryDocument (documentId : String? , projection : Array <String >? ): Cursor {
42- val finalProjection = projection ? : DEFAULT_DOCUMENT_PROJECTION
43- return MatrixCursor (finalProjection).apply {
44- documentId?.let { id ->
45- getAttachmentByDocumentId(id)?.let { attachmentInfo ->
46- newRow().apply {
47- if (DocumentsContract .Document .COLUMN_DOCUMENT_ID in finalProjection) {
48- add(DocumentsContract .Document .COLUMN_DOCUMENT_ID , id)
49- }
50- if (DocumentsContract .Document .COLUMN_DISPLAY_NAME in finalProjection) {
51- add(DocumentsContract .Document .COLUMN_DISPLAY_NAME , attachmentInfo.getSafeName())
52- }
53- if (DocumentsContract .Document .COLUMN_MIME_TYPE in finalProjection) {
54- add(DocumentsContract .Document .COLUMN_MIME_TYPE , attachmentInfo.getAndroidMimeType())
55- }
56- if (DocumentsContract .Document .COLUMN_FLAGS in finalProjection) {
57- add(DocumentsContract .Document .COLUMN_FLAGS , 0 )
58- }
59- if (DocumentsContract .Document .COLUMN_SIZE in finalProjection) {
60- add(DocumentsContract .Document .COLUMN_SIZE , attachmentInfo.rawData?.size ? : 0 )
61- }
62- if (DocumentsContract .Document .COLUMN_LAST_MODIFIED in finalProjection) {
63- add(DocumentsContract .Document .COLUMN_LAST_MODIFIED , null )
64- }
65- }
66- }
67- }
68- }
38+ return MatrixCursor (emptyArray())
6939 }
7040
7141 override fun queryChildDocuments (
@@ -80,6 +50,10 @@ class EmbeddedAttachmentsProvider : DocumentsProvider() {
8050 mode : String ,
8151 signal : CancellationSignal ?
8252 ): ParcelFileDescriptor ? {
53+ if (mode.contains(" w" )) {
54+ throw IllegalStateException (" Modification is not allowed" )
55+ }
56+
8357 return getFileDescriptor(getBytesForDocumentId(documentId))
8458 }
8559
@@ -185,15 +159,4 @@ class EmbeddedAttachmentsProvider : DocumentsProvider() {
185159 }
186160 }
187161 }
188-
189- companion object {
190- private val DEFAULT_DOCUMENT_PROJECTION = arrayOf(
191- DocumentsContract .Document .COLUMN_DOCUMENT_ID ,
192- DocumentsContract .Document .COLUMN_MIME_TYPE ,
193- DocumentsContract .Document .COLUMN_DISPLAY_NAME ,
194- DocumentsContract .Document .COLUMN_LAST_MODIFIED ,
195- DocumentsContract .Document .COLUMN_FLAGS ,
196- DocumentsContract .Document .COLUMN_SIZE
197- )
198- }
199162}
0 commit comments