Skip to content

Commit

Permalink
Added using Content app if 'RESTRICT_ANDROID_ATTACHMENT_HANDLING' is …
Browse files Browse the repository at this point in the history
…present. Refactored code.| #2137
  • Loading branch information
DenBond7 committed May 5, 2023
1 parent 1c92db4 commit 35504ec
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 2 additions & 0 deletions FlowCrypt/src/main/java/com/flowcrypt/email/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,7 @@ class Constants {
*/
const val REQUEST_KEY_BUTTON_CLICK = "REQUEST_KEY_BUTTON_CLICK"
const val REQUEST_KEY_INFO_BUTTON_CLICK = "REQUEST_KEY_INFO_BUTTON_CLICK"

const val APP_PACKAGE_CONTENT = "com.airwatch.contentlocker"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class AttachmentDownloadManagerService : Service() {
}

private interface OnDownloadAttachmentListener {
fun onAttDownloaded(attInfo: AttachmentInfo, uri: Uri, canBeOpened: Boolean = true)
fun onAttDownloaded(attInfo: AttachmentInfo, uri: Uri, useContentApp: Boolean = false)

fun onCanceled(attInfo: AttachmentInfo)

Expand All @@ -186,7 +186,7 @@ class AttachmentDownloadManagerService : Service() {
val attDownloadManagerService = weakRef.get()
val notificationManager = attDownloadManagerService?.attsNotificationManager

val (attInfo, exception, uri, progressInPercentage, timeLeft, isLast, canBeOpened)
val (attInfo, exception, uri, progressInPercentage, timeLeft, isLast, useContentApp)
= message.obj as DownloadAttachmentTaskResult

when (message.what) {
Expand All @@ -208,7 +208,7 @@ class AttachmentDownloadManagerService : Service() {
context = attDownloadManagerService,
attInfo = attInfo!!,
uri = uri!!,
canBeOpened = canBeOpened
useContentApp = useContentApp
)
LogsUtil.d(TAG, attInfo?.getSafeName() + " is downloaded")
}
Expand Down Expand Up @@ -373,15 +373,15 @@ class AttachmentDownloadManagerService : Service() {
}
}

override fun onAttDownloaded(attInfo: AttachmentInfo, uri: Uri, canBeOpened: Boolean) {
override fun onAttDownloaded(attInfo: AttachmentInfo, uri: Uri, useContentApp: Boolean) {
attsInfoMap.remove(attInfo.id)
futureMap.remove(attInfo.uniqueStringId)
try {
val result = DownloadAttachmentTaskResult(
attInfo = attInfo,
uri = uri,
isLast = isLast,
canBeOpened = canBeOpened
useContentApp = useContentApp
)
messenger.send(Message.obtain(null, ReplyHandler.MESSAGE_ATTACHMENT_DOWNLOAD, result))
} catch (remoteException: RemoteException) {
Expand Down Expand Up @@ -463,7 +463,7 @@ class AttachmentDownloadManagerService : Service() {
listener?.onAttDownloaded(
attInfo = att.copy(name = finalFileName),
uri = uri,
canBeOpened = !account.hasClientConfigurationProperty(
useContentApp = account.hasClientConfigurationProperty(
ClientConfiguration.ConfigurationProperty.RESTRICT_ANDROID_ATTACHMENT_HANDLING
)
)
Expand All @@ -488,7 +488,7 @@ class AttachmentDownloadManagerService : Service() {
).use { inputStream ->
handleAttachmentInputStream(
inputStream = inputStream,
canBeOpened = !account.hasClientConfigurationProperty(
useContentApp = account.hasClientConfigurationProperty(
ClientConfiguration.ConfigurationProperty.RESTRICT_ANDROID_ATTACHMENT_HANDLING
)
)
Expand Down Expand Up @@ -517,7 +517,7 @@ class AttachmentDownloadManagerService : Service() {
)?.inputStream?.let { inputStream ->
handleAttachmentInputStream(
inputStream = inputStream,
canBeOpened = !account.hasClientConfigurationProperty(
useContentApp = account.hasClientConfigurationProperty(
ClientConfiguration.ConfigurationProperty.RESTRICT_ANDROID_ATTACHMENT_HANDLING
)
)
Expand All @@ -534,7 +534,10 @@ class AttachmentDownloadManagerService : Service() {
}
}

private fun handleAttachmentInputStream(inputStream: InputStream, canBeOpened: Boolean = true) {
private fun handleAttachmentInputStream(
inputStream: InputStream,
useContentApp: Boolean = false
) {
downloadFile(attTempFile, inputStream)

if (Thread.currentThread().isInterrupted) {
Expand All @@ -548,7 +551,7 @@ class AttachmentDownloadManagerService : Service() {
listener?.onAttDownloaded(
attInfo = att.copy(name = finalFileName),
uri = uri,
canBeOpened = canBeOpened
useContentApp = useContentApp
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.text.TextUtils
import android.text.format.DateUtils
import androidx.core.app.NotificationCompat
import com.flowcrypt.email.BuildConfig
import com.flowcrypt.email.Constants
import com.flowcrypt.email.R
import com.flowcrypt.email.api.email.model.AttachmentInfo
import com.flowcrypt.email.security.pgp.PgpDecryptAndOrVerify
Expand Down Expand Up @@ -88,18 +89,18 @@ class AttachmentNotificationManager(context: Context) : CustomNotificationManage
* @param context Interface to global information about an application environment.
* @param attInfo [AttachmentInfo] object which contains a detail information about an attachment.
* @param uri The [Uri] of the downloaded attachment.
* @param canBeOpened A flag that indicates can we open an attachment after downloading.
* @param useContentApp A flag that indicates should we use the Content app as a viewer.
*/
fun downloadCompleted(
context: Context,
attInfo: AttachmentInfo,
uri: Uri,
canBeOpened: Boolean = true
useContentApp: Boolean = false
) {
val intent = if (canBeOpened) {
GeneralUtil.genViewAttachmentIntent(uri, attInfo)
val intent = if (useContentApp) {
GeneralUtil.genViewAttachmentIntent(uri, attInfo).setPackage(Constants.APP_PACKAGE_CONTENT)
} else {
Intent()
GeneralUtil.genViewAttachmentIntent(uri, attInfo)
}
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)
val builder = genDefBuilder(context, attInfo)
Expand Down Expand Up @@ -198,7 +199,7 @@ class AttachmentNotificationManager(context: Context) : CustomNotificationManage
* @param attachmentInfo The [AttachmentInfo] object.
* @return The prepared title.
*/
private fun prepareContentTitle(attachmentInfo: AttachmentInfo): String? {
private fun prepareContentTitle(attachmentInfo: AttachmentInfo): String {
var contentTitle = attachmentInfo.getSafeName()
if (!TextUtils.isEmpty(contentTitle) && contentTitle.length > MAX_CONTENT_TITLE_LENGTH) {
contentTitle = contentTitle.substring(0, MAX_CONTENT_TITLE_LENGTH) + "..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ data class DownloadAttachmentTaskResult constructor(
val progressInPercentage: Int = 0,
val timeLeft: Long = 0,
val isLast: Boolean = false,
val canBeOpened: Boolean = true
val useContentApp: Boolean = false
)

0 comments on commit 35504ec

Please sign in to comment.