Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,13 @@ internal abstract class BaseConversationMessageRenderingTest {
state: MmsDownloadUiModel.State = MmsDownloadUiModel.State.AwaitingManualDownload,
sizeBytes: Long = MMS_SIZE_BYTES,
expiryTimestamp: Long = MMS_EXPIRY_TIMESTAMP,
isSecondaryUser: Boolean = false,
): MmsDownloadUiModel {
return MmsDownloadUiModel(
state = state,
sizeBytes = sizeBytes,
expiryTimestamp = expiryTimestamp,
isSecondaryUser = isSecondaryUser,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal class ConversationMessageUiModelMapperMmsDownloadTest :
state = MmsDownloadUiModel.State.AwaitingManualDownload,
sizeBytes = 2_048L,
expiryTimestamp = 1_700_000_000_000L,
isSecondaryUser = false,
),
uiModel.mmsDownload,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class ResolveConversationMessageSimDisplayNameTest {
state = MmsDownloadUiModel.State.AwaitingManualDownload,
sizeBytes = 0L,
expiryTimestamp = 0L,
isSecondaryUser = false,
)
}

Expand Down
6 changes: 6 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@
<string name="message_status_downloading">Downloading&#8230;</string>
<!-- Timestamp line for MMS for expired or invalid message. -->
<string name="message_status_download_error">Message expired or not available</string>
<!-- Title line for an MMS that only the Owner user can download. -->
<string name="message_title_download_secondary_user">MMS not available for this user</string>
<!-- Timestamp line for an MMS that only the Owner user can download. -->
<string name="message_status_download_secondary_user">Download it from the Owner user</string>
<!-- Display this info line with an MMS notification -->
<string name="mms_info">size: <xliff:g id="messageSize">%1$s</xliff:g>, expiration: <xliff:g id="messageExpire">%2$s</xliff:g></string>
<!-- While sending a message, if it has invalid recipient, display this message. -->
Expand Down Expand Up @@ -494,6 +498,8 @@
<!-- Title for the preference for whether or not to auto-retrieve MMS when roaming -->
<string name="auto_retrieve_mms_when_roaming_pref_title">Roaming auto-retrieve</string>
<string name="auto_retrieve_mms_when_roaming_pref_summary">Automatically retrieve MMS when roaming</string>
<!-- Auto-retrieve MMS summary shown to secondary users, who can't download MMS. -->
<string name="auto_retrieve_mms_secondary_user_summary">Only the Owner user can download MMS</string>
<string name="group_mms_pref_title">Group messaging</string>
<string name="group_mms_pref_summary">Use MMS to send a single message when there are multiple recipients</string>
<!-- Preference title: SMS disabled (Messaging is not default SMS app) -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ protected boolean queueAction(final String messageId, final Action processingAct
final MessageData message = BugleDatabaseOperations.readMessage(db, messageId);
if (message != null && message.canDownloadMessage()) {
final Uri notificationUri = message.getSmsMessageUri();
if (notificationUri == null) {
LogUtil.w(TAG, "DownloadMmsAction: message " + messageId
+ " has no notification uri; skipping download");
return false;
}
final String conversationId = message.getConversationId();
final int status = message.getStatus();

Expand Down
1 change: 0 additions & 1 deletion src/com/android/messaging/debug/TestDataSeeder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,6 @@ private fun insertMmsDownloadMessage(
put(MessageColumns.RECEIVED_TIMESTAMP, timestamp)
put(MessageColumns.SEEN, 1)
put(MessageColumns.READ, 1)
put(MessageColumns.SMS_MESSAGE_URI, "content://mms/${900_000 + seedIndex}")
put(MessageColumns.SMS_PRIORITY, 0)
put(MessageColumns.SMS_MESSAGE_SIZE, messageSizeBytes)
put(MessageColumns.MMS_TRANSACTION_ID, "seeded-transaction-$seedIndex")
Expand Down
3 changes: 3 additions & 0 deletions src/com/android/messaging/sms/MmsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,9 @@ public static StatusPlusUri updateSentMmsMessageStatus(final Context context,
}

public static void clearMmsStatus(final Context context, final Uri uri) {
if (uri == null) {
return;
}
// Messaging application can leave invalid values in STATUS field of M-Notification.ind
// messages. Take this opportunity to clear it.
// Downloading status just kept in local db and not reflected into telephony.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.android.messaging.data.subscriptionsettings.model.PerSubscriptionData
import com.android.messaging.data.subscriptionsettings.model.SubscriptionSettingsData
import com.android.messaging.ui.appsettings.subscription.model.SubscriptionSettingsUiState
import com.android.messaging.ui.appsettings.subscription.model.SubscriptionUiState
import com.android.messaging.util.OsUtil
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import kotlinx.collections.immutable.ImmutableList
Expand Down Expand Up @@ -121,6 +122,7 @@ internal class SubscriptionSettingsUiStateMapperImpl @Inject constructor(
deliveryReportsEnabled = perSub.deliveryReportsEnabled,
isWirelessAlertsSupported = perSub.showCellBroadcast && isCellBroadcastAppEnabled,
isDefaultSmsApp = isDefaultSmsApp,
isSecondaryUser = OsUtil.isSecondaryUser(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ internal data class SubscriptionUiState(
val deliveryReportsEnabled: Boolean = false,
val isWirelessAlertsSupported: Boolean = false,
val isDefaultSmsApp: Boolean = false,
val isSecondaryUser: Boolean = false,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.android.messaging.ui.appsettings.subscription.ui

import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand Down Expand Up @@ -169,31 +170,65 @@ private fun LazyListScope.mmsSettingsItems(
)
}

item(key = "auto_retrieve_mms") {
SettingsSwitchItem(
title = stringResource(R.string.auto_retrieve_mms_pref_title),
summary = stringResource(R.string.auto_retrieve_mms_pref_summary),
checked = subscriptionSettings.autoRetrieveMms,
enabled = subscriptionSettings.isDefaultSmsApp,
onCheckedChange = { enabled ->
onAction(
Action.AutoRetrieveMmsChanged(subscriptionSettings.subId, enabled),
)
},
)
}
autoRetrieveMmsItems(
subscriptionSettings = subscriptionSettings,
onAction = onAction,
)
}

item(key = "auto_retrieve_mms_roaming") {
private fun LazyListScope.autoRetrieveMmsItems(
subscriptionSettings: SubscriptionUiState,
onAction: (Action) -> Unit,
) {
autoRetrieveSwitchItem(
key = "auto_retrieve_mms",
subscriptionSettings = subscriptionSettings,
titleResId = R.string.auto_retrieve_mms_pref_title,
summaryResId = R.string.auto_retrieve_mms_pref_summary,
checked = subscriptionSettings.autoRetrieveMms,
dependencyEnabled = true,
onCheckedChange = { enabled ->
onAction(Action.AutoRetrieveMmsChanged(subscriptionSettings.subId, enabled))
},
)

autoRetrieveSwitchItem(
key = "auto_retrieve_mms_roaming",
subscriptionSettings = subscriptionSettings,
titleResId = R.string.auto_retrieve_mms_when_roaming_pref_title,
summaryResId = R.string.auto_retrieve_mms_when_roaming_pref_summary,
checked = subscriptionSettings.autoRetrieveMmsWhenRoaming,
dependencyEnabled = subscriptionSettings.autoRetrieveMms,
onCheckedChange = { enabled ->
onAction(Action.AutoRetrieveMmsWhenRoamingChanged(subscriptionSettings.subId, enabled))
},
)
}

private fun LazyListScope.autoRetrieveSwitchItem(
key: String,
subscriptionSettings: SubscriptionUiState,
@StringRes titleResId: Int,
@StringRes summaryResId: Int,
checked: Boolean,
dependencyEnabled: Boolean,
onCheckedChange: (Boolean) -> Unit,
) {
item(key = key) {
SettingsSwitchItem(
title = stringResource(R.string.auto_retrieve_mms_when_roaming_pref_title),
summary = stringResource(R.string.auto_retrieve_mms_when_roaming_pref_summary),
checked = subscriptionSettings.autoRetrieveMmsWhenRoaming,
enabled = subscriptionSettings.isDefaultSmsApp && subscriptionSettings.autoRetrieveMms,
onCheckedChange = { enabled ->
onAction(
Action.AutoRetrieveMmsWhenRoamingChanged(subscriptionSettings.subId, enabled),
)
title = stringResource(titleResId),
summary = when {
subscriptionSettings.isSecondaryUser -> {
stringResource(R.string.auto_retrieve_mms_secondary_user_summary)
}

else -> stringResource(summaryResId)
},
checked = checked,
enabled = subscriptionSettings.isDefaultSmsApp &&
dependencyEnabled &&
!subscriptionSettings.isSecondaryUser,
onCheckedChange = onCheckedChange,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.android.messaging.ui.conversation.messages.model.message.Conversation
import com.android.messaging.ui.conversation.messages.model.message.MmsDownloadUiModel
import com.android.messaging.util.ContentType
import com.android.messaging.util.LogUtil
import com.android.messaging.util.OsUtil
import javax.inject.Inject
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
Expand Down Expand Up @@ -93,6 +94,7 @@ internal class ConversationMessageUiModelMapperImpl @Inject constructor(
state = state,
sizeBytes = data.smsMessageSize.toLong(),
expiryTimestamp = data.mmsExpiry,
isSecondaryUser = OsUtil.isSecondaryUser(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ internal data class MmsDownloadUiModel(
val state: State,
val sizeBytes: Long,
val expiryTimestamp: Long,
val isSecondaryUser: Boolean,
) {
enum class State {
AwaitingManualDownload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,34 @@ internal fun ConversationMmsDownloadBody(
isSelected = isSelected,
contentColor = contentColor,
)
val isSecondaryUserReferral = isSecondaryUserDownloadReferral(
state = download.state,
isSecondaryUser = download.isSecondaryUser,
)

ConversationMmsDownloadBodyContent(
titleText = stringResource(id = mmsDownloadTitleResId(state = download.state)),
titleText = stringResource(
id = mmsDownloadTitleResId(
state = download.state,
isSecondaryUserReferral = isSecondaryUserReferral,
),
),
infoText = rememberMmsDownloadInfoText(download = download),
statusLineText = rememberMmsDownloadStatusLineText(
statusText = stringResource(id = mmsDownloadStatusResId(state = download.state)),
statusText = stringResource(
id = mmsDownloadStatusResId(
state = download.state,
isSecondaryUserReferral = isSecondaryUserReferral,
),
),
simDisplayName = simDisplayName,
),
contentColor = contentColor,
supportingColor = supportingColor,
statusColor = mmsDownloadStatusColor(
state = download.state,
canDownloadMessage = canDownloadMessage,
isSecondaryUserReferral = isSecondaryUserReferral,
isSelected = isSelected,
contentColor = contentColor,
supportingColor = supportingColor,
Expand Down Expand Up @@ -144,28 +159,37 @@ private fun rememberMmsDownloadStatusLineText(
private fun mmsDownloadStatusColor(
state: MmsDownloadUiModel.State,
canDownloadMessage: Boolean,
isSecondaryUserReferral: Boolean,
isSelected: Boolean,
contentColor: Color,
supportingColor: Color,
): Color {
val canRetryDownload = canDownloadMessage &&
(
state == MmsDownloadUiModel.State.AwaitingManualDownload ||
state == MmsDownloadUiModel.State.DownloadFailed
)
val isDownloadError = state == MmsDownloadUiModel.State.DownloadFailed ||
state == MmsDownloadUiModel.State.ExpiredOrUnavailable

return when {
isSelected -> contentColor
state == MmsDownloadUiModel.State.AwaitingManualDownload && canDownloadMessage -> {
MaterialTheme.colorScheme.primary
}
state == MmsDownloadUiModel.State.DownloadFailed && canDownloadMessage -> {
MaterialTheme.colorScheme.primary
}
state == MmsDownloadUiModel.State.DownloadFailed -> MaterialTheme.colorScheme.error
state == MmsDownloadUiModel.State.ExpiredOrUnavailable -> {
MaterialTheme.colorScheme.error
}
isSecondaryUserReferral -> supportingColor
canRetryDownload -> MaterialTheme.colorScheme.primary
isDownloadError -> MaterialTheme.colorScheme.error
else -> supportingColor
}
}

@StringRes
private fun mmsDownloadTitleResId(state: MmsDownloadUiModel.State): Int {
private fun mmsDownloadTitleResId(
state: MmsDownloadUiModel.State,
isSecondaryUserReferral: Boolean,
): Int {
if (isSecondaryUserReferral) {
return R.string.message_title_download_secondary_user
}

return when (state) {
MmsDownloadUiModel.State.AwaitingManualDownload -> {
R.string.message_title_manual_download
Expand All @@ -179,7 +203,14 @@ private fun mmsDownloadTitleResId(state: MmsDownloadUiModel.State): Int {
}

@StringRes
private fun mmsDownloadStatusResId(state: MmsDownloadUiModel.State): Int {
private fun mmsDownloadStatusResId(
state: MmsDownloadUiModel.State,
isSecondaryUserReferral: Boolean,
): Int {
if (isSecondaryUserReferral) {
return R.string.message_status_download_secondary_user
}

return when (state) {
MmsDownloadUiModel.State.AwaitingManualDownload -> {
R.string.message_status_download
Expand All @@ -192,6 +223,18 @@ private fun mmsDownloadStatusResId(state: MmsDownloadUiModel.State): Int {
}
}

private fun isSecondaryUserDownloadReferral(
state: MmsDownloadUiModel.State,
isSecondaryUser: Boolean,
): Boolean {
return isSecondaryUser && when (state) {
MmsDownloadUiModel.State.AwaitingManualDownload -> true
MmsDownloadUiModel.State.DownloadFailed -> true
MmsDownloadUiModel.State.Downloading -> false
MmsDownloadUiModel.State.ExpiredOrUnavailable -> false
}
}

private fun buildMmsDownloadInfoText(
context: Context,
download: MmsDownloadUiModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,13 @@ internal fun previewInlineVCardAttachment(

internal fun previewMmsDownloadUiModel(
state: MmsDownloadUiModel.State = MmsDownloadUiModel.State.AwaitingManualDownload,
isSecondaryUser: Boolean = false,
): MmsDownloadUiModel {
return MmsDownloadUiModel(
state = state,
sizeBytes = 2_400_000L,
expiryTimestamp = PREVIEW_NOW_MILLIS + 86_400_000L,
isSecondaryUser = isSecondaryUser,
)
}

Expand Down
Loading