@Test public void testMixedRadioActive() throws Exception { MonotonicRadioMonitor radioMonitor = new MonotonicRadioMonitor(WAKEUP_INTERVAL_S); radioMonitor.onRadioActivate(1000L, 4000L); radioMonitor.onRadioActivate(2000L, 3000L); radioMonitor.onRadioActivate(15000L, 18000L); radioMonitor.onRadioActivate(16000L, 18000L); int radioActiveS = radioMonitor.onRadioActivate(29000L, 30000L); assertThat(radioActiveS, is(6 + 2 * WAKEUP_INTERVAL_S)); assertThat(getRadioActiveS(radioMonitor), is(7 + 3 * WAKEUP_INTERVAL_S)); assertThat(radioMonitor.mWakeupCounter.get(), is(3)); }
public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } }
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } }
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); }
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount(); }
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount();  }