From e6ba27180e450073d6574509ff7702910103fb2a Mon Sep 17 00:00:00 2001 From: Ahmad Kemsan Date: Tue, 30 Jul 2024 23:34:53 +0530 Subject: [PATCH 1/3] feat: implementation of unlimited values for allowedActivations, allowedDeactivations and meter attributes --- .../android/lexactivator/LexActivator.java | 26 ++++++++++++------- .../lexactivator/LexActivatorNative.java | 7 ++--- .../lexactivator/LicenseMeterAttribute.java | 21 ++++++++++++--- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivator.java b/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivator.java index 2ccf866..dade0b2 100644 --- a/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivator.java +++ b/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivator.java @@ -6,6 +6,8 @@ import java.nio.ByteBuffer; 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; import com.fasterxml.jackson.databind.ObjectMapper; @@ -30,6 +32,11 @@ public class LexActivator { public static final int LA_RELEASES_ALL = 1; public static final int LA_RELEASES_ALLOWED = 2; + // 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)); + } + // Exceptions are not caught. // static{ // try{ @@ -547,14 +554,15 @@ public static String GetLicenseMetadata(String key) throws LexActivatorException */ public static LicenseMeterAttribute GetLicenseMeterAttribute(String name) throws LexActivatorException, 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 = LexActivatorNative.GetLicenseMeterAttribute(name, allowedUses, totalUses, grossUses); if (LA_OK == status) { - return new LicenseMeterAttribute(name, allowedUses.getValue(), totalUses.getValue(), grossUses.getValue()); + return new LicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()), + toUnsignedBigInteger(grossUses.getValue())); } throw new LexActivatorException(status); @@ -585,9 +593,9 @@ public static String GetLicenseKey() throws LexActivatorException, UnsupportedEn * @return Returns the allowed activations * @throws LexActivatorException */ - public static int GetLicenseAllowedActivations() throws LexActivatorException { + public static long GetLicenseAllowedActivations() throws LexActivatorException { int status; - IntByReference allowedActivations = new IntByReference(0); + LongByReference allowedActivations = new LongByReference(0); status = LexActivatorNative.GetLicenseAllowedActivations(allowedActivations); switch (status) { case LA_OK: @@ -625,9 +633,9 @@ public static int GetLicenseTotalActivations() throws LexActivatorException { * @return Returns the allowed deactivations * @throws LexActivatorException */ - public static int GetLicenseAllowedDeactivations() throws LexActivatorException { + public static long GetLicenseAllowedDeactivations() throws LexActivatorException { int status; - IntByReference allowedDeactivations = new IntByReference(0); + LongByReference allowedDeactivations = new LongByReference(0); status = LexActivatorNative.GetLicenseAllowedDeactivations(allowedDeactivations); switch (status) { case LA_OK: diff --git a/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivatorNative.java b/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivatorNative.java index 9a3d021..061cea5 100644 --- a/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivatorNative.java +++ b/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivatorNative.java @@ -7,6 +7,7 @@ import com.sun.jna.JNIEnv; import java.nio.ByteBuffer; import com.sun.jna.ptr.IntByReference; +import com.sun.jna.ptr.LongByReference; import com.sun.jna.Callback; public class LexActivatorNative implements Library { @@ -82,7 +83,7 @@ public interface ReleaseUpdateCallbackType extends Callback { public static native int GetLicenseMetadata(String key, ByteBuffer value, int length); - public static native int GetLicenseMeterAttribute(String name, IntByReference allowedUses, IntByReference totalUses, IntByReference grossUses); + public static native int GetLicenseMeterAttribute(String name, LongByReference allowedUses, LongByReference totalUses, LongByReference grossUses); public static native int GetLicenseKey(ByteBuffer licenseKey, int length); @@ -96,11 +97,11 @@ public interface ReleaseUpdateCallbackType extends Callback { public static native int GetLicenseMaxAllowedReleaseVersion(ByteBuffer maxAllowedReleaseVersion, int length); - public static native int GetLicenseAllowedActivations(IntByReference allowedActivations); + public static native int GetLicenseAllowedActivations(LongByReference allowedActivations); public static native int GetLicenseTotalActivations(IntByReference totalActivations); - public static native int GetLicenseAllowedDeactivations(IntByReference allowedDeactivations); + public static native int GetLicenseAllowedDeactivations(LongByReference allowedDeactivations); public static native int GetLicenseTotalDeactivations(IntByReference totalDeactivations); diff --git a/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LicenseMeterAttribute.java b/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LicenseMeterAttribute.java index ec5c8a6..6fb9f0b 100644 --- a/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LicenseMeterAttribute.java +++ b/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LicenseMeterAttribute.java @@ -1,16 +1,29 @@ package com.cryptlex.android.lexactivator; +import java.math.BigInteger; public class LicenseMeterAttribute { + /** + * 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 LicenseMeterAttribute(String name, int allowedUses, int totalUses, int grossUses) { + public LicenseMeterAttribute(String name, long allowedUses, BigInteger totalUses, BigInteger grossUses) { this.name = name; this.allowedUses = allowedUses; this.totalUses = totalUses; From 224bbc215c2568781173fcf58060cfa6d8c8f48d Mon Sep 17 00:00:00 2001 From: Ahmad Kemsan Date: Wed, 31 Jul 2024 11:59:23 +0530 Subject: [PATCH 2/3] refactor: update data type to long for activationLeaseDuration setter --- .../com/cryptlex/android/lexactivator/LexActivator.java | 7 ++++--- .../cryptlex/android/lexactivator/LexActivatorNative.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivator.java b/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivator.java index dade0b2..598c098 100644 --- a/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivator.java +++ b/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivator.java @@ -367,13 +367,14 @@ public static void SetReleaseChannel(String releaseChannel) throws LexActivatorE } /** - * Sets the lease duration for the activation. + * Sets the lease duration for the activation. The activation lease duration + * is honoured when the allow client lease duration property is enabled. * - * @param leaseDuration + * @param leaseDuration value of the lease duration. A value of -1 indicates unlimited lease duration. * * @throws LexActivatorException */ - public static void SetActivationLeaseDuration(int leaseDuration) throws LexActivatorException { + public static void SetActivationLeaseDuration(long leaseDuration) throws LexActivatorException { int status; status = LexActivatorNative.SetActivationLeaseDuration(leaseDuration); if (LA_OK != status) { diff --git a/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivatorNative.java b/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivatorNative.java index 061cea5..26da36b 100644 --- a/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivatorNative.java +++ b/lexactivator/src/main/java/com/cryptlex/android/lexactivator/LexActivatorNative.java @@ -63,7 +63,7 @@ public interface ReleaseUpdateCallbackType extends Callback { public static native int SetReleaseChannel(String releaseChannel); - public static native int SetActivationLeaseDuration(int leaseDuration); + public static native int SetActivationLeaseDuration(long leaseDuration); public static native int SetOfflineActivationRequestMeterAttributeUses(String name, int uses); From c62129f0d399d0a31c9d6b872c06e971b353fea4 Mon Sep 17 00:00:00 2001 From: Ahmad Kemsan Date: Wed, 31 Jul 2024 14:52:11 +0530 Subject: [PATCH 3/3] refactor: update UserLicense property data type to long --- .../android/lexactivator/UserLicense.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lexactivator/src/main/java/com/cryptlex/android/lexactivator/UserLicense.java b/lexactivator/src/main/java/com/cryptlex/android/lexactivator/UserLicense.java index 4aaaa7c..be72e2e 100644 --- a/lexactivator/src/main/java/com/cryptlex/android/lexactivator/UserLicense.java +++ b/lexactivator/src/main/java/com/cryptlex/android/lexactivator/UserLicense.java @@ -2,11 +2,23 @@ public class UserLicense { - public int allowedActivations; + /** + * The allowed activations of the license. A value of -1 indicates unlimited number of activations. + */ + public long allowedActivations; - public int allowedDeactivations; + /** + * The allowed deactivations of the license. A value of -1 indicates unlimited number of deactivations. + */ + public long allowedDeactivations; + /** + * The license key. + */ public String key; + /** + * The license type (node-locked or hosted-floating). + */ public String type; }