aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpedroGitt <pedro.contreiras@amdocs.com>2016-11-07 11:06:26 +0100
committerpedroGitt <pedro.contreiras@amdocs.com>2016-11-07 11:06:26 +0100
commit59bb145ceb0b703e8124fb44b75e85a48a2caed3 (patch)
treeb9f55d4db7dfce01f288bf2a3bac6f35150aa885
parentc71235d508db25bdca1921e9bcddbbe9f3ed1b83 (diff)
Add new API to verify object release
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java7
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java56
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java35
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java4
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java19
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java16
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java18
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java17
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java19
9 files changed, 155 insertions, 36 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java
index 3b6101b..7a6233d 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java
@@ -187,11 +187,8 @@ public class OlmAccountTest {
assertTrue(OlmAccount.JSON_KEY_ONE_TIME_KEY +" object is missing", null!=generatedKeysJsonObj);
// test the count of the generated one time keys:
- Iterator<String> generatedKeysIt = generatedKeysJsonObj.keys();
- while(generatedKeysIt.hasNext()){
- generatedKeysIt.next();
- oneTimeKeysCount++;
- }
+ oneTimeKeysCount = generatedKeysJsonObj.length();
+
assertTrue("Expected count="+GENERATION_ONE_TIME_KEYS_NUMBER+" found="+oneTimeKeysCount,GENERATION_ONE_TIME_KEYS_NUMBER==oneTimeKeysCount);
} catch (JSONException e) {
diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java
index ac369e2..8fc0694 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java
@@ -168,9 +168,14 @@ public class OlmGroupSessionTest {
mBobInboundGroupSession.releaseSession();
}
+ @Test
+ public void test14CheckUnreleaseedCount() {
+ assertTrue(0==mAliceOutboundGroupSession.getUnreleasedCount());
+ assertTrue(0==mBobInboundGroupSession.getUnreleasedCount());
+ }
@Test
- public void test14SerializeOutboundSession() {
+ public void test15SerializeOutboundSession() {
OlmOutboundGroupSession outboundGroupSessionRef=null;
OlmOutboundGroupSession outboundGroupSessionSerial;
@@ -219,21 +224,24 @@ public class OlmGroupSessionTest {
outboundGroupSessionRef.releaseSession();
outboundGroupSessionSerial.releaseSession();
+
+ assertTrue(0==outboundGroupSessionRef.getUnreleasedCount());
+ assertTrue(0==outboundGroupSessionSerial.getUnreleasedCount());
} catch (FileNotFoundException e) {
- Log.e(LOG_TAG, "## test14SerializeOutboundSession(): Exception FileNotFoundException Msg=="+e.getMessage());
+ Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception FileNotFoundException Msg=="+e.getMessage());
} catch (ClassNotFoundException e) {
- Log.e(LOG_TAG, "## test14SerializeOutboundSession(): Exception ClassNotFoundException Msg==" + e.getMessage());
+ Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception ClassNotFoundException Msg==" + e.getMessage());
} catch (OlmException e) {
- Log.e(LOG_TAG, "## test14SerializeOutboundSession(): Exception OlmException Msg==" + e.getMessage());
+ Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception OlmException Msg==" + e.getMessage());
} catch (IOException e) {
- Log.e(LOG_TAG, "## test14SerializeOutboundSession(): Exception IOException Msg==" + e.getMessage());
+ Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception IOException Msg==" + e.getMessage());
} catch (Exception e) {
- Log.e(LOG_TAG, "## test14SerializeOutboundSession(): Exception Msg==" + e.getMessage());
+ Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception Msg==" + e.getMessage());
}
}
@Test
- public void test15SerializeInboundSession() {
+ public void test16SerializeInboundSession() {
OlmOutboundGroupSession aliceOutboundGroupSession=null;
OlmInboundGroupSession bobInboundGroupSessionRef=null;
OlmInboundGroupSession bobInboundGroupSessionSerial;
@@ -290,16 +298,20 @@ public class OlmGroupSessionTest {
aliceOutboundGroupSession.releaseSession();
bobInboundGroupSessionRef.releaseSession();
bobInboundGroupSessionSerial.releaseSession();
+
+ assertTrue(0==aliceOutboundGroupSession.getUnreleasedCount());
+ assertTrue(0==bobInboundGroupSessionRef.getUnreleasedCount());
+ assertTrue(0==bobInboundGroupSessionSerial.getUnreleasedCount());
} catch (FileNotFoundException e) {
- Log.e(LOG_TAG, "## test15SerializeInboundSession(): Exception FileNotFoundException Msg=="+e.getMessage());
+ Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception FileNotFoundException Msg=="+e.getMessage());
} catch (ClassNotFoundException e) {
- Log.e(LOG_TAG, "## test15SerializeInboundSession(): Exception ClassNotFoundException Msg==" + e.getMessage());
+ Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception ClassNotFoundException Msg==" + e.getMessage());
} catch (OlmException e) {
- Log.e(LOG_TAG, "## test15SerializeInboundSession(): Exception OlmException Msg==" + e.getMessage());
+ Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception OlmException Msg==" + e.getMessage());
} catch (IOException e) {
- Log.e(LOG_TAG, "## test15SerializeInboundSession(): Exception IOException Msg==" + e.getMessage());
+ Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception IOException Msg==" + e.getMessage());
} catch (Exception e) {
- Log.e(LOG_TAG, "## test15SerializeInboundSession(): Exception Msg==" + e.getMessage());
+ Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception Msg==" + e.getMessage());
}
}
@@ -308,7 +320,7 @@ public class OlmGroupSessionTest {
* This test validates random series are provide enough random values.
*/
@Test
- public void test16MultipleOutboundSession() {
+ public void test17MultipleOutboundSession() {
OlmOutboundGroupSession outboundGroupSession1;
OlmOutboundGroupSession outboundGroupSession2;
OlmOutboundGroupSession outboundGroupSession3;
@@ -374,7 +386,23 @@ public class OlmGroupSessionTest {
String sessionId8 = outboundGroupSession8.sessionKey();
assertFalse(sessionId7.equals(sessionId8));
-
+ outboundGroupSession1.releaseSession();
+ outboundGroupSession2.releaseSession();
+ outboundGroupSession3.releaseSession();
+ outboundGroupSession4.releaseSession();
+ outboundGroupSession5.releaseSession();
+ outboundGroupSession6.releaseSession();
+ outboundGroupSession7.releaseSession();
+ outboundGroupSession8.releaseSession();
+
+ assertTrue(0==outboundGroupSession1.getUnreleasedCount());
+ assertTrue(0==outboundGroupSession2.getUnreleasedCount());
+ assertTrue(0==outboundGroupSession3.getUnreleasedCount());
+ assertTrue(0==outboundGroupSession4.getUnreleasedCount());
+ assertTrue(0==outboundGroupSession5.getUnreleasedCount());
+ assertTrue(0==outboundGroupSession6.getUnreleasedCount());
+ assertTrue(0==outboundGroupSession7.getUnreleasedCount());
+ assertTrue(0==outboundGroupSession8.getUnreleasedCount());
} catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false);
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java
index a011685..99127e1 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java
@@ -137,9 +137,14 @@ public class OlmSessionTest {
// release accounts
bobAccount.releaseAccount();
aliceAccount.releaseAccount();
+ assertTrue(0==bobAccount.getUnreleasedCount());
+ assertTrue(0==aliceAccount.getUnreleasedCount());
+
// release sessions
bobSession.releaseSession();
aliceSession.releaseSession();
+ assertTrue(0==bobSession.getUnreleasedCount());
+ assertTrue(0==aliceSession.getUnreleasedCount());
}
@@ -251,9 +256,14 @@ public class OlmSessionTest {
// clean objects..
assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession));
bobAccount.releaseAccount();
- bobSession.releaseSession();
aliceAccount.releaseAccount();
+ assertTrue(0==bobAccount.getUnreleasedCount());
+ assertTrue(0==aliceAccount.getUnreleasedCount());
+
+ bobSession.releaseSession();
aliceSession.releaseSession();
+ assertTrue(0==bobSession.getUnreleasedCount());
+ assertTrue(0==aliceSession.getUnreleasedCount());
}
@@ -302,9 +312,14 @@ public class OlmSessionTest {
assertTrue(aliceSessionId.equals(bobSessionId));
aliceAccount.releaseAccount();
- aliceSession.releaseSession();
bobAccount.releaseAccount();
+ assertTrue(0==aliceAccount.getUnreleasedCount());
+ assertTrue(0==bobAccount.getUnreleasedCount());
+
bobSession.releaseSession();
+ aliceSession.releaseSession();
+ assertTrue(0==bobSession.getUnreleasedCount());
+ assertTrue(0==aliceSession.getUnreleasedCount());
}
@Test
@@ -360,8 +375,13 @@ public class OlmSessionTest {
assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession));
aliceAccount.releaseAccount();
bobAccount.releaseAccount();
+ assertTrue(0==aliceAccount.getUnreleasedCount());
+ assertTrue(0==bobAccount.getUnreleasedCount());
+
aliceSession.releaseSession();
bobSession.releaseSession();
+ assertTrue(0==aliceSession.getUnreleasedCount());
+ assertTrue(0==bobSession.getUnreleasedCount());
}
// ********************************************************
@@ -486,9 +506,15 @@ public class OlmSessionTest {
assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession));
bobAccount.releaseAccount();
aliceAccount.releaseAccount();
+ assertTrue(0==bobAccount.getUnreleasedCount());
+ assertTrue(0==aliceAccount.getUnreleasedCount());
+
bobSession.releaseSession();
aliceSession.releaseSession();
aliceSessionDeserial.releaseSession();
+ assertTrue(0==bobSession.getUnreleasedCount());
+ assertTrue(0==aliceSession.getUnreleasedCount());
+ assertTrue(0==aliceSessionDeserial.getUnreleasedCount());
}
catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception FileNotFoundException Msg=="+e.getMessage());
@@ -589,8 +615,13 @@ public class OlmSessionTest {
assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession));
aliceAccount.releaseAccount();
bobAccount.releaseAccount();
+ assertTrue(0==aliceAccount.getUnreleasedCount());
+ assertTrue(0==bobAccount.getUnreleasedCount());
+
aliceSession.releaseSession();
bobSession.releaseSession();
+ assertTrue(0==aliceSession.getUnreleasedCount());
+ assertTrue(0==bobSession.getUnreleasedCount());
}
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java
index d40c35a..9e03453 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java
@@ -99,7 +99,10 @@ public class OlmUtilityTest {
assertFalse(String.valueOf(errorMsg).isEmpty());
utility.releaseUtility();
+ assertTrue(0==utility.getUnreleasedCount());
+
account.releaseAccount();
+ assertTrue(0==account.getUnreleasedCount());
}
@@ -112,5 +115,6 @@ public class OlmUtilityTest {
assertFalse(TextUtils.isEmpty(hashResult));
utility.releaseUtility();
+ assertTrue(0==utility.getUnreleasedCount());
}
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java
index 1345a50..aeeaebc 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java
@@ -35,6 +35,7 @@ import java.io.Serializable;
public class OlmAccount extends CommonSerializeUtils implements Serializable {
private static final long serialVersionUID = 3497486121598434824L;
private static final String LOG_TAG = "OlmAccount";
+ private transient int mUnreleasedCount;
// JSON keys used in the JSON objects returned by JNI
/** As well as the identity key, each device creates a number of Curve25519 key pairs which are
@@ -53,8 +54,8 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
never leave the device, but the public part is published to the Matrix network. **/
public static final String JSON_KEY_FINGER_PRINT_KEY = "ed25519";
- /** account raw pointer value (OlmAccount*) returned by JNI.
- * this value identifies uniquely the native account instance.
+ /** Account Id returned by JNI.
+ * This value identifies uniquely the native account instance.
*/
private transient long mNativeId;
@@ -167,7 +168,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
*/
public void releaseAccount(){
releaseAccountJni();
-
+ mUnreleasedCount--;
mNativeId = 0;
}
@@ -188,6 +189,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
private boolean initNewAccount() {
boolean retCode = false;
if(0 != (mNativeId = initNewAccountJni())){
+ mUnreleasedCount++;
retCode = true;
}
return retCode;
@@ -210,6 +212,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
private boolean createNewAccount() {
boolean retCode = false;
if(0 != (mNativeId = createNewAccountJni())){
+ mUnreleasedCount++;
retCode = true;
}
return retCode;
@@ -353,7 +356,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
private native int markOneTimeKeysAsPublishedJni();
/**
- * Sign a message with the ed25519 fingerprint key for this account.
+ * Sign a message with the ed25519 fingerprint key for this account.<br>
* The signed message is returned by the method.
* @param aMessage message to sign
* @return the signed message if operation succeed, null otherwise
@@ -362,4 +365,12 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
return signMessageJni(aMessage);
}
private native String signMessageJni(String aMessage);
+
+ /**
+ * Return the number of unreleased OlmAccount instances.<br>
+ * @return number of unreleased instances
+ */
+ public int getUnreleasedCount() {
+ return mUnreleasedCount;
+ }
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java
index 6f27507..50e77f7 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java
@@ -37,9 +37,10 @@ import java.io.Serializable;
public class OlmInboundGroupSession extends CommonSerializeUtils implements Serializable {
private static final long serialVersionUID = -772028491251653253L;
private static final String LOG_TAG = "OlmInboundGroupSession";
+ private transient int mUnreleasedCount;
- /** session raw pointer value returned by JNI.<br>
- * this value uniquely identifies the native inbound group session instance.
+ /** Session Id returned by JNI.<br>
+ * This value uniquely identifies the native inbound group session instance.
*/
private transient long mNativeId;
@@ -68,7 +69,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
*/
public void releaseSession(){
releaseSessionJni();
-
+ mUnreleasedCount--;
mNativeId = 0;
}
@@ -88,6 +89,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
private boolean createNewSession() {
boolean retCode = false;
if(0 != (mNativeId = createNewSessionJni())){
+ mUnreleasedCount++;
retCode = true;
}
return retCode;
@@ -232,4 +234,12 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
* @return null if operation succeed, an error message if operation failed
*/
private native String initWithSerializedDataJni(String aSerializedData, String aKey);
+
+ /**
+ * Return the number of unreleased OlmInboundGroupSession instances.<br>
+ * @return number of unreleased instances
+ */
+ public int getUnreleasedCount() {
+ return mUnreleasedCount;
+ }
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java
index 5b59362..f7d5f17 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java
@@ -35,9 +35,10 @@ import java.io.Serializable;
public class OlmOutboundGroupSession extends CommonSerializeUtils implements Serializable {
private static final long serialVersionUID = -3133097431283604416L;
private static final String LOG_TAG = "OlmOutboundGroupSession";
+ private transient int mUnreleasedCount;
- /** session raw pointer value returned by JNI.<br>
- * this value uniquely identifies the native inbound group session instance.
+ /** Session Id returned by JNI.<br>
+ * This value uniquely identifies the native outbound group session instance.
*/
private transient long mNativeId;
@@ -153,7 +154,8 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
* Public API for {@link #releaseSessionJni()}.
*/
public void releaseSession() {
- releaseSessionJni();
+ releaseSessionJni();
+ mUnreleasedCount--;
mNativeId = 0;
}
@@ -174,6 +176,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
private boolean createNewSession() {
boolean retCode = false;
if(0 != (mNativeId = createNewSessionJni())){
+ mUnreleasedCount++;
retCode = true;
}
return retCode;
@@ -237,6 +240,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
/**
* Encrypt some plain-text message.<br>
+ * The message given as parameter is encrypted and returned as the return value.
* @param aClearMsg message to be encrypted
* @return the encrypted message if operation succeed, null otherwise
*/
@@ -250,4 +254,12 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
return retValue;
}
private native String encryptMessageJni(String aClearMsg);
+
+ /**
+ * Return the number of unreleased OlmOutboundGroupSession instances.<br>
+ * @return number of unreleased instances
+ */
+ public int getUnreleasedCount() {
+ return mUnreleasedCount;
+ }
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java
index ffc899a..38e8c89 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java
@@ -35,9 +35,10 @@ import java.io.Serializable;
public class OlmSession extends CommonSerializeUtils implements Serializable {
private static final long serialVersionUID = -8975488639186976419L;
private static final String LOG_TAG = "OlmSession";
+ private transient int mUnreleasedCount;
- /** session raw pointer value (OlmSession*) returned by JNI.
- * this value uniquely identifies the native session instance.
+ /** Session Id returned by JNI.
+ * This value uniquely identifies the native session instance.
**/
private transient long mNativeId;
@@ -158,7 +159,7 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
*/
public void releaseSession(){
releaseSessionJni();
-
+ mUnreleasedCount--;
mNativeId = 0;
}
@@ -171,6 +172,7 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
private boolean initNewSession() {
boolean retCode = false;
if(0 != (mNativeId = initNewSessionJni())){
+ mUnreleasedCount++;
retCode = true;
}
return retCode;
@@ -194,6 +196,7 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
private boolean createNewSession() {
boolean retCode = false;
if(0 != (mNativeId = createNewSessionJni())){
+ mUnreleasedCount++;
retCode = true;
}
return retCode;
@@ -367,5 +370,13 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
}
private native String decryptMessageJni(OlmMessage aEncryptedMsg);
+
+ /**
+ * Return the number of unreleased OlmSession instances.<br>
+ * @return number of unreleased instances
+ */
+ public int getUnreleasedCount() {
+ return mUnreleasedCount;
+ }
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java
index 9bd7aaa..8cc14c0 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java
@@ -29,9 +29,10 @@ public class OlmUtility {
public static final int RANDOM_KEY_SIZE = 32;
public static final int RANDOM_RANGE = 256;
+ private transient int mUnreleasedCount;
- /** raw pointer value returned by JNI.
- * this value uniquely identifies this utility instance.
+ /** Instance Id returned by JNI.
+ * This value uniquely identifies this utility instance.
**/
private long mNativeId;
@@ -47,6 +48,7 @@ public class OlmUtility {
private boolean initUtility() {
boolean retCode = false;
if(0 != (mNativeId = initUtilityJni())){
+ mUnreleasedCount++;
retCode = true;
}
return retCode;
@@ -59,6 +61,7 @@ public class OlmUtility {
*/
public void releaseUtility(){
releaseUtilityJni();
+ mUnreleasedCount--;
mNativeId = 0;
}
private native void releaseUtilityJni();
@@ -126,6 +129,10 @@ public class OlmUtility {
private native String sha256Jni(String aMessage);
+ /**
+ * Helper method to compute a string based on random integers.
+ * @return string containing randoms integer values
+ */
public static String getRandomKey() {
String keyRetValue;
Random rand = new Random();
@@ -138,5 +145,13 @@ public class OlmUtility {
return keyRetValue;
}
+
+ /**
+ * Return the number of unreleased OlmUtility instances.<br>
+ * @return number of unreleased instances
+ */
+ public int getUnreleasedCount() {
+ return mUnreleasedCount;
+ }
}