protected boolean isThrottled() {
    // Throttle logging the HotKeyDetection to every 5 minutes.
    long nowMs = clock.currentTimeMillis();
    if (nowMs - prevHotKeyDetectionLogMs < loggingPeriod.getMillis()) {
      return true;
    }
    prevHotKeyDetectionLogMs = nowMs;
    return false;
  }
@Test
  public void throttlesLoggingHotKeyMessage() {
    HotKeyLogger hotKeyLogger = new HotKeyLogger(clock);

    clock.setTime(Clock.SYSTEM.currentTimeMillis());
    assertFalse(hotKeyLogger.isThrottled());
    assertTrue(hotKeyLogger.isThrottled());

    // The class throttles every 5 minutes, so the first time it is called is true. The second time
    // is throttled and returns false.
    clock.setTime(clock.currentTimeMillis() + Duration.standardMinutes(5L).getMillis());
    assertFalse(hotKeyLogger.isThrottled());
    assertTrue(hotKeyLogger.isThrottled());

    // Test that the state variable is set and can log again in 5 minutes.
    clock.setTime(clock.currentTimeMillis() + Duration.standardMinutes(5L).getMillis());
    assertFalse(hotKeyLogger.isThrottled());
    assertTrue(hotKeyLogger.isThrottled());
  }