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..598c098 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{ @@ -360,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) { @@ -547,14 +555,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 +594,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 +634,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..26da36b 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 { @@ -62,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); @@ -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;