From 8cf2606b6c3fce63360d75a2a664e66a0eba6c93 Mon Sep 17 00:00:00 2001 From: muneebkq Date: Thu, 25 Jul 2024 00:20:31 +0530 Subject: [PATCH] feat: Add GetHostConfig function --- lexfloatclient/build.gradle | 1 + .../android/lexfloatclient/HostConfig.java | 3 ++ .../lexfloatclient/LexFloatClient.java | 34 ++++++++++++++++++- .../lexfloatclient/LexFloatClientNative.java | 2 ++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/HostConfig.java diff --git a/lexfloatclient/build.gradle b/lexfloatclient/build.gradle index 2a0c0a8..25494e5 100644 --- a/lexfloatclient/build.gradle +++ b/lexfloatclient/build.gradle @@ -35,6 +35,7 @@ android { dependencies { implementation 'net.java.dev.jna:jna:5.8.0' + implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2' } publishing { diff --git a/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/HostConfig.java b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/HostConfig.java new file mode 100644 index 0000000..d013e16 --- /dev/null +++ b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/HostConfig.java @@ -0,0 +1,3 @@ +public class HostConfig { + public String maxOfflineLeaseDuration; +} 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 8f140bd..fdc993a 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.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.core.JsonProcessingException; import java.util.ArrayList; import java.util.List; @@ -123,7 +125,37 @@ public static String GetFloatingClientLibraryVersion() throws LexFloatClientExce return new String(buffer.array(), "UTF-8").trim(); } throw new LexFloatClientException(status); - } + } + + /** + * Gets the host configuration. + * + * @return Returns host configuration. + * @throws LexFloatClientException + * @throws UnsupportedEncodingException + */ + + public static HostConfig GetHostConfig() throws LexFloatClientException, UnsupportedEncodingException { + int status; + int bufferSize = 1024; + + ByteBuffer buffer = ByteBuffer.allocate(bufferSize); + status = LexFloatClientNative.GetHostConfigInternal(buffer, bufferSize); + if (LA_OK == status) { + String hostConfigJson = new String(buffer.array(), "UTF-8").trim(); + if (!hostConfigJson.isEmpty()) { + HostConfig hostConfig = null; + ObjectMapper objectMapper = new ObjectMapper(); + try { + hostConfig = objectMapper.readValue(hostConfigJson, HostConfig.class); + } catch (JsonProcessingException e) {} + return hostConfig; + } else { + return null; + } + } + throw new LexFloatClientException(status); + } /** * Gets the product version name. 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..2c5240f 100644 --- a/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClientNative.java +++ b/lexfloatclient/src/main/java/com/cryptlex/android/lexfloatclient/LexFloatClientNative.java @@ -23,6 +23,8 @@ public interface CallbackType extends Callback { public static native int SetHostProductId(String productId); + public static native int GetHostConfigInternal(ByteBuffer hostconfig, int length); + public static native int SetHostUrl(String hostUrl); public static native int SetFloatingLicenseCallback(CallbackType callback);