Skip to content
Merged
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 @@ -62,6 +62,9 @@ internal class AppSettingsRepositoryImplTest {
every { factory.getPhoneUtils(ParticipantData.DEFAULT_SELF_SUB_ID) } returns phoneUtils
every { context.resources } returns resources
every { context.getString(R.string.send_sound_pref_key) } returns SEND_SOUND_PREF_KEY
every {
context.getString(R.string.in_conversation_sound_pref_key)
} returns IN_CONVERSATION_SOUND_PREF_KEY
every { context.getString(R.string.dump_sms_pref_key) } returns DUMP_SMS_PREF_KEY
every { context.getString(R.string.dump_mms_pref_key) } returns DUMP_MMS_PREF_KEY
every {
Expand All @@ -72,6 +75,9 @@ internal class AppSettingsRepositoryImplTest {
} returns YOUTUBE_LINK_PREVIEWS_DEFAULT
every { resources.getBoolean(R.bool.send_sound_pref_default) } returns
SEND_SOUND_DEFAULT
every {
resources.getBoolean(R.bool.in_conversation_sound_pref_default)
} returns IN_CONVERSATION_SOUND_DEFAULT
every { resources.getBoolean(R.bool.dump_sms_pref_default) } returns DUMP_SMS_DEFAULT
every { resources.getBoolean(R.bool.dump_mms_pref_default) } returns DUMP_MMS_DEFAULT
}
Expand All @@ -88,6 +94,12 @@ internal class AppSettingsRepositoryImplTest {
every { phoneUtils.defaultSmsAppLabel } returns DEFAULT_SMS_APP_LABEL
every { debugFeaturesProvider.isEnabled() } returns true
every { appPrefs.getBoolean(SEND_SOUND_PREF_KEY, SEND_SOUND_DEFAULT) } returns false
every {
appPrefs.getBoolean(
IN_CONVERSATION_SOUND_PREF_KEY,
IN_CONVERSATION_SOUND_DEFAULT,
)
} returns true
every { appPrefs.getBoolean(DUMP_SMS_PREF_KEY, DUMP_SMS_DEFAULT) } returns true
every { appPrefs.getBoolean(DUMP_MMS_PREF_KEY, DUMP_MMS_DEFAULT) } returns false
every {
Expand All @@ -104,12 +116,17 @@ internal class AppSettingsRepositoryImplTest {
assertTrue(result.isDefaultSmsApp)
assertEquals(DEFAULT_SMS_APP_LABEL, result.defaultSmsAppLabel)
assertFalse(result.sendSoundEnabled)
assertTrue(result.inConversationSoundEnabled)
assertTrue(result.youTubeLinkPreviewsEnabled)
assertTrue(result.isDebugEnabled)
assertTrue(result.dumpSmsEnabled)
assertFalse(result.dumpMmsEnabled)
verify(exactly = 1) {
appPrefs.getBoolean(SEND_SOUND_PREF_KEY, SEND_SOUND_DEFAULT)
appPrefs.getBoolean(
IN_CONVERSATION_SOUND_PREF_KEY,
IN_CONVERSATION_SOUND_DEFAULT,
)
appPrefs.getBoolean(
YOUTUBE_LINK_PREVIEWS_PREF_KEY,
YOUTUBE_LINK_PREVIEWS_DEFAULT,
Expand All @@ -132,6 +149,10 @@ internal class AppSettingsRepositoryImplTest {
pref = AppBooleanPref.SEND_SOUND,
enabled = true,
)
repository.setBooleanPref(
pref = AppBooleanPref.IN_CONVERSATION_SOUND,
enabled = true,
)
repository.setBooleanPref(
pref = AppBooleanPref.DUMP_SMS,
enabled = false,
Expand All @@ -150,6 +171,10 @@ internal class AppSettingsRepositoryImplTest {
SEND_SOUND_PREF_KEY,
true,
)
appPrefs.putBoolean(
IN_CONVERSATION_SOUND_PREF_KEY,
true,
)
appPrefs.putBoolean(
DUMP_SMS_PREF_KEY,
false,
Expand Down Expand Up @@ -213,6 +238,8 @@ internal class AppSettingsRepositoryImplTest {
private const val DUMP_MMS_PREF_KEY = "dump_mms"
private const val DUMP_SMS_DEFAULT = true
private const val DUMP_SMS_PREF_KEY = "dump_sms"
private const val IN_CONVERSATION_SOUND_DEFAULT = false
private const val IN_CONVERSATION_SOUND_PREF_KEY = "in_conversation_sound"
private const val SEND_SOUND_DEFAULT = true
private const val SEND_SOUND_PREF_KEY = "send_sound"
private const val YOUTUBE_LINK_PREVIEWS_DEFAULT = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.android.messaging.datamodel

import android.media.AudioManager
import android.net.Uri
import com.android.messaging.FactoryTestAccess
import com.android.messaging.data.conversationsettings.repository.ConversationSnoozeQuery
Expand Down Expand Up @@ -34,7 +33,6 @@ class BugleNotificationsBlockedConversationTest {
dataModel = dataModel,
)
every { dataModel.getDatabase() } returns database
silenceRinger()
stubConversationLookup()
stubSnoozeLookup()
stubNotificationDelivery()
Expand Down Expand Up @@ -76,25 +74,17 @@ class BugleNotificationsBlockedConversationTest {
}

@Test
fun createMessageNotification_withBlockedObservableConversation_playsNoSound() {
givenNoUnseenMessages()
givenConversationObservable(BLOCKED_CONVERSATION_ID)

BugleNotifications.createMessageNotification(BLOCKED_CONVERSATION_ID)

verify(exactly = 0) { RingtoneUtil.getNotificationRingtoneUri(any(), any()) }
}

@Test
fun createMessageNotification_withAllowedObservableConversation_playsSound() {
fun createMessageNotification_withObservableConversation_postsAndPlaysNothing() {
// Issue #298: a message arriving in the conversation the user is watching is already
// marked seen, so there is nothing to post - and nothing to play either. The app used
// to sound the conversation ringtone here, which no notification setting could silence.
givenNoUnseenMessages()
givenConversationObservable(ALLOWED_CONVERSATION_ID)

BugleNotifications.createMessageNotification(ALLOWED_CONVERSATION_ID)

verify(exactly = 1) {
RingtoneUtil.getNotificationRingtoneUri(ALLOWED_CONVERSATION_ID, null)
}
verify(exactly = 0) { BugleNotifications.processAndSend(any(), any()) }
verify(exactly = 0) { RingtoneUtil.getNotificationRingtoneUri(any(), any()) }
}

private fun stubConversationLookup() {
Expand All @@ -116,7 +106,6 @@ class BugleNotificationsBlockedConversationTest {
) {
val convData = mockk<ConversationListItemData>(relaxed = true)
every { convData.otherParticipantNormalizedDestination } returns sender
every { convData.notificationSoundUri } returns null
every {
ConversationListItemData.getExistingConversation(database, conversationId)
} returns convData
Expand All @@ -135,12 +124,6 @@ class BugleNotificationsBlockedConversationTest {
every { BugleNotifications.processAndSend(any(), any()) } just runs
}

private fun silenceRinger() {
RuntimeEnvironment.getApplication()
.getSystemService(AudioManager::class.java)
.ringerMode = AudioManager.RINGER_MODE_SILENT
}

private fun givenUnseenMessage(
conversationId: String,
): MessageNotificationState.Conversation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal class AppSettingsUiStateMapperImplTest {
isDefaultSmsApp = true,
defaultSmsAppLabel = DEFAULT_SMS_APP_LABEL,
sendSoundEnabled = false,
inConversationSoundEnabled = true,
youTubeLinkPreviewsEnabled = true,
isDebugEnabled = true,
dumpSmsEnabled = true,
Expand All @@ -40,6 +41,7 @@ internal class AppSettingsUiStateMapperImplTest {
isDefaultSmsApp = true,
defaultSmsAppLabel = FORMATTED_DEFAULT_SMS_APP_LABEL,
sendSoundEnabled = false,
inConversationSoundEnabled = true,
youTubeLinkPreviewsEnabled = true,
isDebugEnabled = true,
dumpSmsEnabled = true,
Expand Down
Loading