From 4f7c88015aa43c6669b2ddaab0f6fc4c0954a0f9 Mon Sep 17 00:00:00 2001 From: Yining Liu Date: Sun, 22 Jan 2023 20:31:52 +0000 Subject: [PATCH] Log whether a notification is non-dismissible after fixing This adds a new method to NotificationRecordLogger to detect whether a notification is non-dismissible. Test: NotificationRecordLoggerTest Bug: 266334323 Change-Id: I0f763d1b938fd85ee5ab24df787edb5a3097c0fe --- .../NotificationRecordLogger.java | 11 ++++++++ .../NotificationRecordLoggerImpl.java | 4 ++- .../NotificationRecordLoggerTest.java | 25 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/notification/NotificationRecordLogger.java b/services/core/java/com/android/server/notification/NotificationRecordLogger.java index 4031c833f3c12..25d619dea2967 100644 --- a/services/core/java/com/android/server/notification/NotificationRecordLogger.java +++ b/services/core/java/com/android/server/notification/NotificationRecordLogger.java @@ -473,4 +473,15 @@ public interface NotificationRecordLogger { } return (r.getSbn().getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE) != 0; } + + /** + * @param r NotificationRecord + * @return Whether the notification is a non-dismissible notification. + */ + static boolean isNonDismissible(@NonNull NotificationRecord r) { + if (r.getSbn() == null || r.getSbn().getNotification() == null) { + return false; + } + return (r.getNotification().flags & Notification.FLAG_NO_DISMISS) != 0; + } } diff --git a/services/core/java/com/android/server/notification/NotificationRecordLoggerImpl.java b/services/core/java/com/android/server/notification/NotificationRecordLoggerImpl.java index 17c6c461d80ca..9a1f19d0c5142 100644 --- a/services/core/java/com/android/server/notification/NotificationRecordLoggerImpl.java +++ b/services/core/java/com/android/server/notification/NotificationRecordLoggerImpl.java @@ -86,7 +86,9 @@ public class NotificationRecordLoggerImpl implements NotificationRecordLogger { /* bool is_foreground_service = 23 */ NotificationRecordLogger.isForegroundService(p.r), /* optional int64 timeout_millis = 24 */ - p.r.getSbn().getNotification().getTimeoutAfter() + p.r.getSbn().getNotification().getTimeoutAfter(), + /* bool is_nondismissible = 25 */ + NotificationRecordLogger.isNonDismissible(p.r) ); } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordLoggerTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordLoggerTest.java index 0169a7d96f9f6..beab107ec556f 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordLoggerTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordLoggerTest.java @@ -130,4 +130,29 @@ public class NotificationRecordLoggerTest extends UiServiceTestCase { p.r.getSbn().getNotification().flags |= FLAG_FOREGROUND_SERVICE; assertTrue(NotificationRecordLogger.isForegroundService(p.r)); } + + + @Test + public void testIsNonDismissible_hasFlagNoDismiss_shouldReturnTrue() { + // Given: a notification pair's notification has flag FLAG_NO_DISMISS + NotificationRecordLogger.NotificationRecordPair p = getNotificationRecordPair( + 0, null); + p.r.getNotification().flags |= Notification.FLAG_NO_DISMISS; + + // When: check the value of isNonDismissible() + // Then: should return true + assertTrue(NotificationRecordLogger.isNonDismissible(p.r)); + } + + @Test + public void testIsNonDismissible_noFlagNoDismiss_shouldReturnFalse() { + // Given: a notification pair's notification doesn't have flag FLAG_NO_DISMISS + NotificationRecordLogger.NotificationRecordPair p = getNotificationRecordPair( + 0, null); + p.r.getNotification().flags &= ~Notification.FLAG_NO_DISMISS; + + // When: check the value of isNonDismissible() + // Then: should return false + assertFalse(NotificationRecordLogger.isNonDismissible(p.r)); + } }