diff --git a/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/HostFeatureEntitlement.java b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/HostFeatureEntitlement.java new file mode 100644 index 0000000..b689534 --- /dev/null +++ b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/HostFeatureEntitlement.java @@ -0,0 +1,18 @@ +package com.cryptlex.android.lexfloatclient; + +public class HostFeatureEntitlement { + /** + * The name of the feature. + */ + public String featureName; + + /** + * The display name of the feature. + */ + public String featureDisplayName; + + /** + * The value of the feature. + */ + public String value; +} 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 4081990..f1fdc4d 100644 --- a/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClient.java +++ b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClient.java @@ -8,6 +8,7 @@ import com.sun.jna.ptr.LongByReference; import java.math.BigInteger; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.JsonProcessingException; import java.util.ArrayList; import java.util.List; @@ -206,6 +207,8 @@ public static HostConfig GetHostConfig() throws LexFloatClientException, Unsuppo /** * Gets the product version name. * + * @deprecated This function is deprecated. Use GetHostLicenseEntitlementSetName() instead. + * * @return name - Returns the name of the Product Version being used. * @throws LexFloatClientException * @throws UnsupportedEncodingException @@ -224,6 +227,8 @@ public static String GetHostProductVersionName() throws LexFloatClientException, /** * Gets the product version display name. * + * @deprecated This function is deprecated. Use GetHostLicenseEntitlementSetDisplayName() instead. + * * @return displayName - Returns the display name of the Product Version being used. * @throws LexFloatClientException * @throws UnsupportedEncodingException @@ -242,6 +247,8 @@ public static String GetHostProductVersionDisplayName() throws LexFloatClientExc /** * Gets the product version feature flag. * + * @deprecated This function is deprecated. Use GetHostFeatureEntitlement() instead. + * * @param name - The name of the Feature Flag. * @return The properties of the Feature Flag as an object. * @throws LexFloatClientException @@ -259,6 +266,105 @@ public static HostProductVersionFeatureFlag GetHostProductVersionFeatureFlag(Str throw new LexFloatClientException(status); } + /** + * Gets the name of the entitlement set associated with the LexFloatServer license. + * + * @return Returns the host license entitlement set name. + * @throws LexFloatClientException + * @throws UnsupportedEncodingException + */ + public static String GetHostLicenseEntitlementSetName() throws LexFloatClientException, UnsupportedEncodingException { + int status; + int bufferSize = 256; + + ByteBuffer buffer = ByteBuffer.allocate(bufferSize); + status = LexFloatClientNative.GetHostLicenseEntitlementSetName(buffer, bufferSize); + if (LF_OK == status) { + return new String(buffer.array(), "UTF-8").trim(); + } + throw new LexFloatClientException(status); + } + + /** + * Gets the display name of the entitlement set associated with the LexFloatServer license. + * + * @return Returns the host license entitlement set display name. + * @throws LexFloatClientException + * @throws UnsupportedEncodingException + */ + public static String GetHostLicenseEntitlementSetDisplayName() throws LexFloatClientException, UnsupportedEncodingException { + int status; + int bufferSize = 256; + + ByteBuffer buffer = ByteBuffer.allocate(bufferSize); + status = LexFloatClientNative.GetHostLicenseEntitlementSetDisplayName(buffer, bufferSize); + if (LF_OK == status) { + return new String(buffer.array(), "UTF-8").trim(); + } + throw new LexFloatClientException(status); + } + + /** + * Gets the feature entitlements associated with the LexFloatServer license. + * + * Feature entitlements can be linked directly to a license (license feature entitlements) + * or via entitlement sets. If a feature entitlement is defined in both, the value from + * the license feature entitlement takes precedence, overriding the entitlement set value. + * + * @return Returns a list of host feature entitlements. + * @throws LexFloatClientException + * @throws UnsupportedEncodingException + */ + public static List GetHostFeatureEntitlements() throws LexFloatClientException, UnsupportedEncodingException { + int status; + int bufferSize = 4096; + + ByteBuffer buffer = ByteBuffer.allocate(bufferSize); + status = LexFloatClientNative.GetHostFeatureEntitlementsInternal(buffer, bufferSize); + if (LF_OK == status) { + String hostFeatureEntitlementsJson = new String(buffer.array(), "UTF-8").trim(); + if (!hostFeatureEntitlementsJson.isEmpty()) { + ObjectMapper objectMapper = new ObjectMapper(); + try { + List hostFeatureEntitlements = objectMapper.readValue(hostFeatureEntitlementsJson, new TypeReference>() {}); + return hostFeatureEntitlements; + } catch (JsonProcessingException e) {} + } else { + return new ArrayList<>(); + } + } + throw new LexFloatClientException(status); + } + + /** + * Gets the feature entitlement associated with the LexFloatServer license. + * + * Feature entitlements can be linked directly to a license (license feature entitlements) + * or via entitlement sets. If a feature entitlement is defined in both, the value from + * the license feature entitlement takes precedence, overriding the entitlement set value. + * + * @param name The name of the feature. + * @return Returns the host feature entitlement object. + * @throws LexFloatClientException + * @throws UnsupportedEncodingException + */ + public static HostFeatureEntitlement GetHostFeatureEntitlement(String name) throws LexFloatClientException, UnsupportedEncodingException { + int status; + int bufferSize = 1024; + + ByteBuffer buffer = ByteBuffer.allocate(bufferSize); + status = LexFloatClientNative.GetHostFeatureEntitlementInternal(name, buffer, bufferSize); + if (LF_OK == status) { + String hostFeatureEntitlementJson = new String(buffer.array(), "UTF-8").trim(); + ObjectMapper objectMapper = new ObjectMapper(); + try { + HostFeatureEntitlement hostFeatureEntitlement = objectMapper.readValue(hostFeatureEntitlementJson, HostFeatureEntitlement.class); + return hostFeatureEntitlement; + } catch (JsonProcessingException e) {} + } + throw new LexFloatClientException(status); + } + /** * Get the value of the license metadata field associated with the * LexFloatServer license key diff --git a/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClientException.java b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClientException.java index c7698d5..86acb45 100644 --- a/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClientException.java +++ b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClientException.java @@ -101,6 +101,12 @@ public static String getErrorMessage(int errorCode) { case LF_E_MACHINE_FINGERPRINT: message = "Machine fingerprint has changed since activation."; break; + case LF_E_ENTITLEMENT_SET_NOT_LINKED: + message = "No entitlement set is linked to the license."; + break; + case LF_E_FEATURE_ENTITLEMENT_NOT_FOUND: + message = "The feature entitlement does not exist."; + break; case LF_E_CLIENT: message = "Client error."; break; @@ -340,7 +346,21 @@ public static String getErrorMessage(int errorCode) { * * MESSAGE: Request blocked due to untrusted proxy. */ - public static final int LF_E_PROXY_NOT_TRUSTED = 67; + public static final int LF_E_PROXY_NOT_TRUSTED = 67; + + /* + * CODE: LF_E_ENTITLEMENT_SET_NOT_LINKED + * + * MESSAGE: No entitlement set is linked to the license. + */ + public static final int LF_E_ENTITLEMENT_SET_NOT_LINKED = 68; + + /* + * CODE: LF_E_FEATURE_ENTITLEMENT_NOT_FOUND + * + * MESSAGE: The feature entitlement does not exist. + */ + public static final int LF_E_FEATURE_ENTITLEMENT_NOT_FOUND = 69; /* * CODE: LF_E_CLIENT 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 afc59fd..2ffd41b 100644 --- a/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClientNative.java +++ b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClientNative.java @@ -44,6 +44,14 @@ public interface CallbackType extends Callback { public static native int GetHostProductVersionFeatureFlag(String name, IntByReference enabled, ByteBuffer data, int length); + public static native int GetHostLicenseEntitlementSetName(ByteBuffer name, int length); + + public static native int GetHostLicenseEntitlementSetDisplayName(ByteBuffer displayName, int length); + + public static native int GetHostFeatureEntitlementsInternal(ByteBuffer featureEntitlementsJson, int length); + + public static native int GetHostFeatureEntitlementInternal(String featureName, ByteBuffer featureEntitlementJson, int length); + public static native int GetHostLicenseMetadata(String key, ByteBuffer value, int length); public static native int GetHostLicenseMeterAttribute(String name, LongByReference allowedUses, LongByReference totalUses, LongByReference grossUses);