From 9ffcabd8bcd424d5c2585bc544b58ae55b1d9b2d Mon Sep 17 00:00:00 2001 From: Ahmad Kemsan Date: Tue, 30 Jul 2024 09:29:27 +0530 Subject: [PATCH 1/2] feat: unlimited implementation of meter attribute getter --- .../HostLicenseMeterAttribute.java | 20 +++++++++++++++---- .../lexfloatclient/LexFloatClient.java | 14 +++++++++---- .../lexfloatclient/LexFloatClientNative.java | 3 ++- 3 files changed, 28 insertions(+), 9 deletions(-) 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..4c7b5d3 100644 --- a/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/HostLicenseMeterAttribute.java +++ b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/HostLicenseMeterAttribute.java @@ -2,15 +2,27 @@ 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 long totalUses; - public int grossUses; + /** + * The gross uses of the meter attribute. + */ + public long grossUses; - public HostLicenseMeterAttribute(String name, int allowedUses, int totalUses, int grossUses) { + public HostLicenseMeterAttribute(String name, long allowedUses, long totalUses, long 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..8350384 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,10 @@ public class LexFloatClient { */ public static final int LF_FAIL = 1; + private static long toUnsignedLong(long value) { + return BigInteger.valueOf(value).and(BigInteger.valueOf(0xFFFFFFFFFFFFFFFFL)).longValue(); + } + /** * Sets the product id of your application * @@ -212,13 +218,13 @@ 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); + 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(), toUnsignedLong(totalUses.getValue()), toUnsignedLong(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); From 706fef08d207e5d2f552b09f0b96d7116a28ea52 Mon Sep 17 00:00:00 2001 From: Ahmad Kemsan Date: Tue, 30 Jul 2024 11:04:40 +0530 Subject: [PATCH 2/2] fix: handle uint64_t values --- .../android/lexfloatclient/HostLicenseMeterAttribute.java | 7 ++++--- .../cryptlex/android/lexfloatclient/LexFloatClient.java | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) 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 4c7b5d3..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,4 +1,5 @@ package com.cryptlex.android.lexfloatclient; +import java.math.BigInteger; public class HostLicenseMeterAttribute { @@ -15,14 +16,14 @@ public class HostLicenseMeterAttribute { /** * The total uses of the meter attribute. */ - public long totalUses; + public BigInteger totalUses; /** * The gross uses of the meter attribute. */ - public long grossUses; + public BigInteger grossUses; - public HostLicenseMeterAttribute(String name, long allowedUses, long totalUses, long 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 8350384..512169d 100644 --- a/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClient.java +++ b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClient.java @@ -25,8 +25,9 @@ public class LexFloatClient { */ public static final int LF_FAIL = 1; - private static long toUnsignedLong(long value) { - return BigInteger.valueOf(value).and(BigInteger.valueOf(0xFFFFFFFFFFFFFFFFL)).longValue(); + // 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)); } /** @@ -219,12 +220,13 @@ public static String GetHostLicenseMetadata(String key) throws LexFloatClientExc public static HostLicenseMeterAttribute GetHostLicenseMeterAttribute(String name) throws LexFloatClientException, UnsupportedEncodingException { int status; 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(), toUnsignedLong(totalUses.getValue()), toUnsignedLong(grossUses.getValue())); + return new HostLicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()), toUnsignedBigInteger(grossUses.getValue())); } throw new LexFloatClientException(status); }