Merge "Log whether a notification is non-dismissible after fixing"
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user