public int onRadioActivate()

in metrics/src/main/java/com/facebook/battery/metrics/network/MonotonicRadioMonitor.java [38:69]


  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;

    /*
     * Theoretically, it's possible that a call to this function could be made,
     * not be scheduled for about 10 seconds, and then another call could be scheduled before it,
     * meaning that a wakeup/active time that occurred would not be counted.
     * Realistically, the odds of a thread going 10 seconds without being scheduled are fairly
     * low so it's not a huge worry.
     */

    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;
    }
  }