public void computeAndDisplayPin(AccountIndex user, int position, boolean computeHotp)
      throws OtpSourceException {

    PinInfo currentPin;
    if (users[position] != null) {
      currentPin = users[position]; // existing PinInfo, so we'll update it
    } else {
      OtpType type = accountDb.getType(user);
      currentPin = new PinInfo(user, type == OtpType.HOTP);
      currentPin.setPin(getString(R.string.empty_pin));
      currentPin.setIsHotpCodeGenerationAllowed(true);
    }

    if (!currentPin.isHotp() || computeHotp) {
      // Always safe to recompute, because this code path is only
      // reached if the account is:
      // - Time-based, in which case getNextCode() does not change state.
      // - Counter-based (HOTP) and computeHotp is true.
      currentPin.setPin(otpProvider.getNextCode(user));
      currentPin.setIsHotpCodeGenerationAllowed(true);
    }

    users[position] = currentPin;
  }
Computes the PIN and saves it in users. This currently runs in the UI thread so it should not
take more than a second or so. If necessary, we can move the computation to a background
thread.

@param user the user account to display with the PIN
@param position the index for the screen of this user and PIN
@param computeHotp true if we should increment counter and display new hotp
java/com/google/android/apps/authenticator/AuthenticatorActivity.java