Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4f7c8801 authored by Yining Liu's avatar Yining Liu
Browse files

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
parent 9e16d20a
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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;
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -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)
        );
    }

+25 −0
Original line number Diff line number Diff line
@@ -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));
    }
}