fix(android): allow open and reply on non-clearable notifications

This commit is contained in:
Ayaan Zaidi
2026-02-27 09:54:33 +05:30
committed by Ayaan Zaidi
parent b8373eaddc
commit 8807267bfd
2 changed files with 12 additions and 1 deletions

View File

@@ -54,6 +54,10 @@ data class NotificationActionResult(
val message: String? = null,
)
internal fun actionRequiresClearableNotification(kind: NotificationActionKind): Boolean {
return kind == NotificationActionKind.Dismiss
}
private object DeviceNotificationStore {
private val lock = Any()
private var connected = false
@@ -221,7 +225,7 @@ class DeviceNotificationListenerService : NotificationListenerService() {
code = "NOTIFICATION_NOT_FOUND",
message = "NOTIFICATION_NOT_FOUND: notification key not found",
)
if (!sbn.isClearable) {
if (actionRequiresClearableNotification(request.kind) && !sbn.isClearable) {
return NotificationActionResult(
ok = false,
code = "NOTIFICATION_NOT_CLEARABLE",

View File

@@ -182,6 +182,13 @@ class NotificationsHandlerTest {
assertTrue((sanitized ?: "").all { it == 'x' })
}
@Test
fun notificationsActionClearablePolicy_onlyRequiresClearableForDismiss() {
assertTrue(actionRequiresClearableNotification(NotificationActionKind.Dismiss))
assertFalse(actionRequiresClearableNotification(NotificationActionKind.Open))
assertFalse(actionRequiresClearableNotification(NotificationActionKind.Reply))
}
private fun parsePayload(result: GatewaySession.InvokeResult): JsonObject {
val payloadJson = result.payloadJson ?: error("expected payload")
return Json.parseToJsonElement(payloadJson).jsonObject