Skip to content

Commit f3cf428

Browse files
authored
wip (#2826)
1 parent fd7d2d7 commit f3cf428

File tree

1 file changed

+5
-42
lines changed

1 file changed

+5
-42
lines changed

FlowCrypt/src/main/java/com/flowcrypt/email/providers/EmbeddedAttachmentsProvider.kt

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55

66
package com.flowcrypt.email.providers
77

8-
import android.content.res.AssetFileDescriptor
98
import android.database.Cursor
109
import android.database.MatrixCursor
1110
import android.net.Uri
12-
import android.os.Bundle
1311
import android.os.CancellationSignal
1412
import android.os.ParcelFileDescriptor
1513
import android.provider.DocumentsContract
1614
import android.provider.DocumentsProvider
17-
import android.util.Log
18-
import android.widget.Toast
1915
import com.flowcrypt.email.BuildConfig
2016
import com.flowcrypt.email.api.email.model.AttachmentInfo
2117
import 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

Comments
 (0)