1 alert per second.
Bug:
36662487
Test: runtest systemui-notification
Change-Id: I42c2342c7ccb86f5912d729c7c2a0074f3000ad2
static final long ALLOWED_ALERT_INTERVAL = 1000;
private long mLastNotificationMillis = 0;
static final long ALLOWED_ALERT_INTERVAL = 1000;
private long mLastNotificationMillis = 0;
- boolean isRateLimited(long now) {
+ boolean shouldRateLimitAlert(long now) {
final long millisSinceLast = now - mLastNotificationMillis;
if (millisSinceLast < 0 || millisSinceLast < ALLOWED_ALERT_INTERVAL) {
return true;
final long millisSinceLast = now - mLastNotificationMillis;
if (millisSinceLast < 0 || millisSinceLast < ALLOWED_ALERT_INTERVAL) {
return true;
}
public boolean isAlertRateLimited() {
}
public boolean isAlertRateLimited() {
- boolean limited = alertRate.isRateLimited(SystemClock.elapsedRealtime());
+ boolean limited = alertRate.shouldRateLimitAlert(SystemClock.elapsedRealtime());
if (limited) {
numAlertViolations++;
}
if (limited) {
numAlertViolations++;
}
@Test
public void testFirstAlertAllowed() throws Exception {
@Test
public void testFirstAlertAllowed() throws Exception {
- assertFalse(mLimiter.isRateLimited(mTestStartTime));
+ assertFalse(mLimiter.shouldRateLimitAlert(mTestStartTime));
}
@Test
public void testAllowedAfterSecond() throws Exception {
}
@Test
public void testAllowedAfterSecond() throws Exception {
- assertFalse(mLimiter.isRateLimited(mTestStartTime));
- assertFalse(mLimiter.isRateLimited(mTestStartTime + ALLOWED_ALERT_INTERVAL));
+ assertFalse(mLimiter.shouldRateLimitAlert(mTestStartTime));
+ assertFalse(mLimiter.shouldRateLimitAlert(mTestStartTime + ALLOWED_ALERT_INTERVAL));
}
@Test
public void testAllowedAfterSecondEvenWithBlockedEntries() throws Exception {
}
@Test
public void testAllowedAfterSecondEvenWithBlockedEntries() throws Exception {
- assertFalse(mLimiter.isRateLimited(mTestStartTime));
- assertTrue(mLimiter.isRateLimited(mTestStartTime + ALLOWED_ALERT_INTERVAL - 1));
- assertFalse(mLimiter.isRateLimited(mTestStartTime + ALLOWED_ALERT_INTERVAL));
+ assertFalse(mLimiter.shouldRateLimitAlert(mTestStartTime));
+ assertTrue(mLimiter.shouldRateLimitAlert(mTestStartTime + ALLOWED_ALERT_INTERVAL - 1));
+ assertFalse(mLimiter.shouldRateLimitAlert(mTestStartTime + ALLOWED_ALERT_INTERVAL));
}
@Test
public void testAllowedDisallowedBeforeSecond() throws Exception {
}
@Test
public void testAllowedDisallowedBeforeSecond() throws Exception {
- assertFalse(mLimiter.isRateLimited(mTestStartTime));
- assertTrue(mLimiter.isRateLimited(mTestStartTime + ALLOWED_ALERT_INTERVAL - 1));
+ assertFalse(mLimiter.shouldRateLimitAlert(mTestStartTime));
+ assertTrue(mLimiter.shouldRateLimitAlert(mTestStartTime + ALLOWED_ALERT_INTERVAL - 1));
}
@Test
public void testDisallowedTimePast() throws Exception {
}
@Test
public void testDisallowedTimePast() throws Exception {
- assertFalse(mLimiter.isRateLimited(mTestStartTime));
- assertTrue(mLimiter.isRateLimited(mTestStartTime - ALLOWED_ALERT_INTERVAL));
+ assertFalse(mLimiter.shouldRateLimitAlert(mTestStartTime));
+ assertTrue(mLimiter.shouldRateLimitAlert(mTestStartTime - ALLOWED_ALERT_INTERVAL));
@RunWith(AndroidTestingRunner.class)
@RunWithLooper
public class NotificationManagerServiceTest extends NotificationTestCase {
@RunWith(AndroidTestingRunner.class)
@RunWithLooper
public class NotificationManagerServiceTest extends NotificationTestCase {
- private static final long WAIT_FOR_IDLE_TIMEOUT = 2;
private static final String TEST_CHANNEL_ID = "NotificationManagerServiceTestChannelId";
private final int uid = Binder.getCallingUid();
private NotificationManagerService mNotificationManagerService;
private static final String TEST_CHANNEL_ID = "NotificationManagerServiceTestChannelId";
private final int uid = Binder.getCallingUid();
private NotificationManagerService mNotificationManagerService;
private AudioManager mAudioManager;
@Mock
ActivityManager mActivityManager;
private AudioManager mAudioManager;
@Mock
ActivityManager mActivityManager;
private NotificationChannel mTestNotificationChannel = new NotificationChannel(
TEST_CHANNEL_ID, TEST_CHANNEL_ID, NotificationManager.IMPORTANCE_DEFAULT);
@Mock
private NotificationChannel mTestNotificationChannel = new NotificationChannel(
TEST_CHANNEL_ID, TEST_CHANNEL_ID, NotificationManager.IMPORTANCE_DEFAULT);
@Mock