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
This commit is contained in:
Yining Liu
2023-01-22 20:31:52 +00:00
parent 9e16d20a77
commit 4f7c88015a
3 changed files with 39 additions and 1 deletions

View File

@@ -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;
}
}

View File

@@ -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)
);
}

View File

@@ -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));
}
}