diff --git a/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/HostLicenseMeterAttribute.java b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/HostLicenseMeterAttribute.java index 653ebfd..70587bf 100644 --- a/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/HostLicenseMeterAttribute.java +++ b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/HostLicenseMeterAttribute.java @@ -1,16 +1,29 @@ package com.cryptlex.android.lexfloatclient; +import java.math.BigInteger; public class HostLicenseMeterAttribute { + /** + * The name of the meter attribute. + */ public String name; - public int allowedUses; + /** + * The allowed uses of the meter attribute. A value of -1 indicates unlimited allowed uses. + */ + public long allowedUses; - public int totalUses; + /** + * The total uses of the meter attribute. + */ + public BigInteger totalUses; - public int grossUses; + /** + * The gross uses of the meter attribute. + */ + public BigInteger grossUses; - public HostLicenseMeterAttribute(String name, int allowedUses, int totalUses, int grossUses) { + public HostLicenseMeterAttribute(String name, long allowedUses, BigInteger totalUses, BigInteger grossUses) { this.name = name; this.allowedUses = allowedUses; this.totalUses = totalUses; diff --git a/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClient.java b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClient.java index 00d4483..512169d 100644 --- a/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClient.java +++ b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClient.java @@ -5,6 +5,8 @@ import java.nio.CharBuffer; import java.io.UnsupportedEncodingException; import com.sun.jna.ptr.IntByReference; +import com.sun.jna.ptr.LongByReference; +import java.math.BigInteger; import java.util.ArrayList; import java.util.List; @@ -23,6 +25,11 @@ public class LexFloatClient { */ public static final int LF_FAIL = 1; + // Convert long to BigInteger to correctly handle unsigned 64-bit values + private static BigInteger toUnsignedBigInteger(long value) { + return BigInteger.valueOf(value).and(BigInteger.valueOf(0xFFFFFFFFFFFFFFFFL)); + } + /** * Sets the product id of your application * @@ -212,13 +219,14 @@ public static String GetHostLicenseMetadata(String key) throws LexFloatClientExc */ public static HostLicenseMeterAttribute GetHostLicenseMeterAttribute(String name) throws LexFloatClientException, UnsupportedEncodingException { int status; - IntByReference allowedUses = new IntByReference(0); - IntByReference totalUses = new IntByReference(0); - IntByReference grossUses = new IntByReference(0); + LongByReference allowedUses = new LongByReference(0); + // These references can still hold the uint64_t values populated by the native function + LongByReference totalUses = new LongByReference(0); + LongByReference grossUses = new LongByReference(0); status = LexFloatClientNative.GetHostLicenseMeterAttribute(name, allowedUses, totalUses, grossUses); if (LF_OK == status) { - return new HostLicenseMeterAttribute(name, allowedUses.getValue(), totalUses.getValue(), grossUses.getValue()); + return new HostLicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()), toUnsignedBigInteger(grossUses.getValue())); } throw new LexFloatClientException(status); } diff --git a/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClientNative.java b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClientNative.java index dcabc29..4c6ae8e 100644 --- a/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClientNative.java +++ b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClientNative.java @@ -8,6 +8,7 @@ import java.nio.CharBuffer; import java.nio.ByteBuffer; import com.sun.jna.ptr.IntByReference; +import com.sun.jna.ptr.LongByReference; import com.sun.jna.Callback; import java.io.File; @@ -39,7 +40,7 @@ public interface CallbackType extends Callback { public static native int GetHostLicenseMetadata(String key, ByteBuffer value, int length); - public static native int GetHostLicenseMeterAttribute(String name, IntByReference allowedUses, IntByReference totalUses, IntByReference grossUses); + public static native int GetHostLicenseMeterAttribute(String name, LongByReference allowedUses, LongByReference totalUses, LongByReference grossUses); public static native int GetHostLicenseExpiryDate(IntByReference expiryDate);