private String getCurrentCode(AccountIndex account, byte[] challenge) throws OtpSourceException {
    // Account is required.
    if (account == null) {
      throw new OtpSourceException("No account");
    }

    OtpType type = mAccountDb.getType(account);
    String secret = getSecret(account);

    long otpState = 0;

    if (type == OtpType.TOTP) {
      // For time-based OTP, the state is derived from clock.
      otpState =
          mTotpCounter.getValueAtTime(Utilities.millisToSeconds(mTotpClock.nowMillis()));
    } else if (type == OtpType.HOTP){
      // For counter-based OTP, the state is obtained by incrementing stored counter.
      mAccountDb.incrementCounter(account);
      Integer counter = mAccountDb.getCounter(account);
      otpState = counter.longValue();
    }

    String result = computePin(secret, otpState, challenge);
    return result;
  }
Class containing implementation of HOTP/TOTP.

<p>Generates OTP codes for one or more accounts.
java/com/google/android/apps/authenticator/otp/OtpProvider.java