Create public version for send failed notifications
Don't expose error details when Android is configured to hide sensitive information on the lock screen.
This commit is contained in:
parent
725c32ea0c
commit
c47d79094c
2 changed files with 22 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
|||
package com.fsck.k9.notification
|
||||
|
||||
import android.app.Notification
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import com.fsck.k9.Account
|
||||
|
@ -29,7 +30,7 @@ internal class SendFailedNotificationController(
|
|||
.setContentText(text)
|
||||
.setContentIntent(folderListPendingIntent)
|
||||
.setStyle(NotificationCompat.BigTextStyle().bigText(text))
|
||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||
.setPublicVersion(createLockScreenNotification(account))
|
||||
.setCategory(NotificationCompat.CATEGORY_ERROR)
|
||||
|
||||
notificationHelper.configureNotification(
|
||||
|
@ -49,6 +50,15 @@ internal class SendFailedNotificationController(
|
|||
notificationManager.cancel(notificationId)
|
||||
}
|
||||
|
||||
private fun createLockScreenNotification(account: Account): Notification {
|
||||
return notificationHelper
|
||||
.createNotificationBuilder(account, NotificationChannelManager.ChannelType.MISCELLANEOUS)
|
||||
.setSmallIcon(resourceProvider.iconWarning)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setContentTitle(resourceProvider.sendFailedTitle())
|
||||
.build()
|
||||
}
|
||||
|
||||
private val notificationManager: NotificationManagerCompat
|
||||
get() = notificationHelper.getNotificationManager()
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.mockito.Mockito.verify
|
|||
import org.mockito.kotlin.any
|
||||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.mock
|
||||
import org.mockito.kotlin.never
|
||||
|
||||
private const val ACCOUNT_NUMBER = 1
|
||||
private const val ACCOUNT_NAME = "TestAccount"
|
||||
|
@ -21,13 +22,15 @@ private const val ACCOUNT_NAME = "TestAccount"
|
|||
class SendFailedNotificationControllerTest : RobolectricTest() {
|
||||
private val resourceProvider: NotificationResourceProvider = TestNotificationResourceProvider()
|
||||
private val notification = mock<Notification>()
|
||||
private val lockScreenNotification = mock<Notification>()
|
||||
private val notificationManager = mock<NotificationManagerCompat>()
|
||||
private val builder = createFakeNotificationBuilder(notification)
|
||||
private val lockScreenNotificationBuilder = createFakeNotificationBuilder(lockScreenNotification)
|
||||
private val account = createFakeAccount()
|
||||
private val contentIntent = mock<PendingIntent>()
|
||||
private val notificationId = NotificationIds.getSendFailedNotificationId(account)
|
||||
private val controller = SendFailedNotificationController(
|
||||
notificationHelper = createFakeNotificationHelper(notificationManager, builder),
|
||||
notificationHelper = createFakeNotificationHelper(notificationManager, builder, lockScreenNotificationBuilder),
|
||||
actionBuilder = createActionBuilder(contentIntent),
|
||||
resourceProvider = resourceProvider
|
||||
)
|
||||
|
@ -44,7 +47,10 @@ class SendFailedNotificationControllerTest : RobolectricTest() {
|
|||
verify(builder).setContentTitle("Failed to send some messages")
|
||||
verify(builder).setContentText("Exception")
|
||||
verify(builder).setContentIntent(contentIntent)
|
||||
verify(builder).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||
verify(builder).setPublicVersion(lockScreenNotification)
|
||||
verify(lockScreenNotificationBuilder).setContentTitle("Failed to send some messages")
|
||||
verify(lockScreenNotificationBuilder, never()).setContentText(any())
|
||||
verify(lockScreenNotificationBuilder, never()).setTicker(any())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -62,12 +68,13 @@ class SendFailedNotificationControllerTest : RobolectricTest() {
|
|||
|
||||
private fun createFakeNotificationHelper(
|
||||
notificationManager: NotificationManagerCompat,
|
||||
builder: NotificationCompat.Builder
|
||||
notificationBuilder: NotificationCompat.Builder,
|
||||
lockScreenNotificationBuilder: NotificationCompat.Builder
|
||||
): NotificationHelper {
|
||||
return mock {
|
||||
on { getContext() } doReturn ApplicationProvider.getApplicationContext()
|
||||
on { getNotificationManager() } doReturn notificationManager
|
||||
on { createNotificationBuilder(any(), any()) } doReturn builder
|
||||
on { createNotificationBuilder(any(), any()) }.doReturn(notificationBuilder, lockScreenNotificationBuilder)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue