Add new API to verify object release

This commit is contained in:
pedroGitt 2016-11-07 11:06:26 +01:00
parent c71235d508
commit 59bb145ceb
9 changed files with 154 additions and 35 deletions

View file

@ -187,11 +187,8 @@ public class OlmAccountTest {
assertTrue(OlmAccount.JSON_KEY_ONE_TIME_KEY +" object is missing", null!=generatedKeysJsonObj); assertTrue(OlmAccount.JSON_KEY_ONE_TIME_KEY +" object is missing", null!=generatedKeysJsonObj);
// test the count of the generated one time keys: // test the count of the generated one time keys:
Iterator<String> generatedKeysIt = generatedKeysJsonObj.keys(); oneTimeKeysCount = generatedKeysJsonObj.length();
while(generatedKeysIt.hasNext()){
generatedKeysIt.next();
oneTimeKeysCount++;
}
assertTrue("Expected count="+GENERATION_ONE_TIME_KEYS_NUMBER+" found="+oneTimeKeysCount,GENERATION_ONE_TIME_KEYS_NUMBER==oneTimeKeysCount); assertTrue("Expected count="+GENERATION_ONE_TIME_KEYS_NUMBER+" found="+oneTimeKeysCount,GENERATION_ONE_TIME_KEYS_NUMBER==oneTimeKeysCount);
} catch (JSONException e) { } catch (JSONException e) {

View file

@ -168,9 +168,14 @@ public class OlmGroupSessionTest {
mBobInboundGroupSession.releaseSession(); mBobInboundGroupSession.releaseSession();
} }
@Test
public void test14CheckUnreleaseedCount() {
assertTrue(0==mAliceOutboundGroupSession.getUnreleasedCount());
assertTrue(0==mBobInboundGroupSession.getUnreleasedCount());
}
@Test @Test
public void test14SerializeOutboundSession() { public void test15SerializeOutboundSession() {
OlmOutboundGroupSession outboundGroupSessionRef=null; OlmOutboundGroupSession outboundGroupSessionRef=null;
OlmOutboundGroupSession outboundGroupSessionSerial; OlmOutboundGroupSession outboundGroupSessionSerial;
@ -219,21 +224,24 @@ public class OlmGroupSessionTest {
outboundGroupSessionRef.releaseSession(); outboundGroupSessionRef.releaseSession();
outboundGroupSessionSerial.releaseSession(); outboundGroupSessionSerial.releaseSession();
assertTrue(0==outboundGroupSessionRef.getUnreleasedCount());
assertTrue(0==outboundGroupSessionSerial.getUnreleasedCount());
} catch (FileNotFoundException e) { } 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) { } 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) { } 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) { } 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) { } catch (Exception e) {
Log.e(LOG_TAG, "## test14SerializeOutboundSession(): Exception Msg==" + e.getMessage()); Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception Msg==" + e.getMessage());
} }
} }
@Test @Test
public void test15SerializeInboundSession() { public void test16SerializeInboundSession() {
OlmOutboundGroupSession aliceOutboundGroupSession=null; OlmOutboundGroupSession aliceOutboundGroupSession=null;
OlmInboundGroupSession bobInboundGroupSessionRef=null; OlmInboundGroupSession bobInboundGroupSessionRef=null;
OlmInboundGroupSession bobInboundGroupSessionSerial; OlmInboundGroupSession bobInboundGroupSessionSerial;
@ -290,16 +298,20 @@ public class OlmGroupSessionTest {
aliceOutboundGroupSession.releaseSession(); aliceOutboundGroupSession.releaseSession();
bobInboundGroupSessionRef.releaseSession(); bobInboundGroupSessionRef.releaseSession();
bobInboundGroupSessionSerial.releaseSession(); bobInboundGroupSessionSerial.releaseSession();
assertTrue(0==aliceOutboundGroupSession.getUnreleasedCount());
assertTrue(0==bobInboundGroupSessionRef.getUnreleasedCount());
assertTrue(0==bobInboundGroupSessionSerial.getUnreleasedCount());
} catch (FileNotFoundException e) { } 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) { } 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) { } 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) { } 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) { } 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. * This test validates random series are provide enough random values.
*/ */
@Test @Test
public void test16MultipleOutboundSession() { public void test17MultipleOutboundSession() {
OlmOutboundGroupSession outboundGroupSession1; OlmOutboundGroupSession outboundGroupSession1;
OlmOutboundGroupSession outboundGroupSession2; OlmOutboundGroupSession outboundGroupSession2;
OlmOutboundGroupSession outboundGroupSession3; OlmOutboundGroupSession outboundGroupSession3;
@ -374,7 +386,23 @@ public class OlmGroupSessionTest {
String sessionId8 = outboundGroupSession8.sessionKey(); String sessionId8 = outboundGroupSession8.sessionKey();
assertFalse(sessionId7.equals(sessionId8)); 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) { } catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false); assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false);
} }

View file

@ -137,9 +137,14 @@ public class OlmSessionTest {
// release accounts // release accounts
bobAccount.releaseAccount(); bobAccount.releaseAccount();
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
assertTrue(0==bobAccount.getUnreleasedCount());
assertTrue(0==aliceAccount.getUnreleasedCount());
// release sessions // release sessions
bobSession.releaseSession(); bobSession.releaseSession();
aliceSession.releaseSession(); aliceSession.releaseSession();
assertTrue(0==bobSession.getUnreleasedCount());
assertTrue(0==aliceSession.getUnreleasedCount());
} }
@ -251,9 +256,14 @@ public class OlmSessionTest {
// clean objects.. // clean objects..
assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession)); assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession));
bobAccount.releaseAccount(); bobAccount.releaseAccount();
bobSession.releaseSession();
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
assertTrue(0==bobAccount.getUnreleasedCount());
assertTrue(0==aliceAccount.getUnreleasedCount());
bobSession.releaseSession();
aliceSession.releaseSession(); aliceSession.releaseSession();
assertTrue(0==bobSession.getUnreleasedCount());
assertTrue(0==aliceSession.getUnreleasedCount());
} }
@ -302,9 +312,14 @@ public class OlmSessionTest {
assertTrue(aliceSessionId.equals(bobSessionId)); assertTrue(aliceSessionId.equals(bobSessionId));
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
aliceSession.releaseSession();
bobAccount.releaseAccount(); bobAccount.releaseAccount();
assertTrue(0==aliceAccount.getUnreleasedCount());
assertTrue(0==bobAccount.getUnreleasedCount());
bobSession.releaseSession(); bobSession.releaseSession();
aliceSession.releaseSession();
assertTrue(0==bobSession.getUnreleasedCount());
assertTrue(0==aliceSession.getUnreleasedCount());
} }
@Test @Test
@ -360,8 +375,13 @@ public class OlmSessionTest {
assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession)); assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession));
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
bobAccount.releaseAccount(); bobAccount.releaseAccount();
assertTrue(0==aliceAccount.getUnreleasedCount());
assertTrue(0==bobAccount.getUnreleasedCount());
aliceSession.releaseSession(); aliceSession.releaseSession();
bobSession.releaseSession(); bobSession.releaseSession();
assertTrue(0==aliceSession.getUnreleasedCount());
assertTrue(0==bobSession.getUnreleasedCount());
} }
// ******************************************************** // ********************************************************
@ -486,9 +506,15 @@ public class OlmSessionTest {
assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession)); assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession));
bobAccount.releaseAccount(); bobAccount.releaseAccount();
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
assertTrue(0==bobAccount.getUnreleasedCount());
assertTrue(0==aliceAccount.getUnreleasedCount());
bobSession.releaseSession(); bobSession.releaseSession();
aliceSession.releaseSession(); aliceSession.releaseSession();
aliceSessionDeserial.releaseSession(); aliceSessionDeserial.releaseSession();
assertTrue(0==bobSession.getUnreleasedCount());
assertTrue(0==aliceSession.getUnreleasedCount());
assertTrue(0==aliceSessionDeserial.getUnreleasedCount());
} }
catch (FileNotFoundException e) { catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception FileNotFoundException Msg=="+e.getMessage()); Log.e(LOG_TAG, "## test03SessionSerialization(): Exception FileNotFoundException Msg=="+e.getMessage());
@ -589,8 +615,13 @@ public class OlmSessionTest {
assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession)); assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession));
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
bobAccount.releaseAccount(); bobAccount.releaseAccount();
assertTrue(0==aliceAccount.getUnreleasedCount());
assertTrue(0==bobAccount.getUnreleasedCount());
aliceSession.releaseSession(); aliceSession.releaseSession();
bobSession.releaseSession(); bobSession.releaseSession();
assertTrue(0==aliceSession.getUnreleasedCount());
assertTrue(0==bobSession.getUnreleasedCount());
} }
} }

View file

@ -99,7 +99,10 @@ public class OlmUtilityTest {
assertFalse(String.valueOf(errorMsg).isEmpty()); assertFalse(String.valueOf(errorMsg).isEmpty());
utility.releaseUtility(); utility.releaseUtility();
assertTrue(0==utility.getUnreleasedCount());
account.releaseAccount(); account.releaseAccount();
assertTrue(0==account.getUnreleasedCount());
} }
@ -112,5 +115,6 @@ public class OlmUtilityTest {
assertFalse(TextUtils.isEmpty(hashResult)); assertFalse(TextUtils.isEmpty(hashResult));
utility.releaseUtility(); utility.releaseUtility();
assertTrue(0==utility.getUnreleasedCount());
} }
} }

View file

@ -35,6 +35,7 @@ import java.io.Serializable;
public class OlmAccount extends CommonSerializeUtils implements Serializable { public class OlmAccount extends CommonSerializeUtils implements Serializable {
private static final long serialVersionUID = 3497486121598434824L; private static final long serialVersionUID = 3497486121598434824L;
private static final String LOG_TAG = "OlmAccount"; private static final String LOG_TAG = "OlmAccount";
private transient int mUnreleasedCount;
// JSON keys used in the JSON objects returned by JNI // 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 /** 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. **/ never leave the device, but the public part is published to the Matrix network. **/
public static final String JSON_KEY_FINGER_PRINT_KEY = "ed25519"; public static final String JSON_KEY_FINGER_PRINT_KEY = "ed25519";
/** account raw pointer value (OlmAccount*) returned by JNI. /** Account Id returned by JNI.
* this value identifies uniquely the native account instance. * This value identifies uniquely the native account instance.
*/ */
private transient long mNativeId; private transient long mNativeId;
@ -167,7 +168,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
*/ */
public void releaseAccount(){ public void releaseAccount(){
releaseAccountJni(); releaseAccountJni();
mUnreleasedCount--;
mNativeId = 0; mNativeId = 0;
} }
@ -188,6 +189,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
private boolean initNewAccount() { private boolean initNewAccount() {
boolean retCode = false; boolean retCode = false;
if(0 != (mNativeId = initNewAccountJni())){ if(0 != (mNativeId = initNewAccountJni())){
mUnreleasedCount++;
retCode = true; retCode = true;
} }
return retCode; return retCode;
@ -210,6 +212,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
private boolean createNewAccount() { private boolean createNewAccount() {
boolean retCode = false; boolean retCode = false;
if(0 != (mNativeId = createNewAccountJni())){ if(0 != (mNativeId = createNewAccountJni())){
mUnreleasedCount++;
retCode = true; retCode = true;
} }
return retCode; return retCode;
@ -353,7 +356,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
private native int markOneTimeKeysAsPublishedJni(); 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. * The signed message is returned by the method.
* @param aMessage message to sign * @param aMessage message to sign
* @return the signed message if operation succeed, null otherwise * @return the signed message if operation succeed, null otherwise
@ -362,4 +365,12 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
return signMessageJni(aMessage); return signMessageJni(aMessage);
} }
private native String signMessageJni(String 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;
}
} }

View file

@ -37,9 +37,10 @@ import java.io.Serializable;
public class OlmInboundGroupSession extends CommonSerializeUtils implements Serializable { public class OlmInboundGroupSession extends CommonSerializeUtils implements Serializable {
private static final long serialVersionUID = -772028491251653253L; private static final long serialVersionUID = -772028491251653253L;
private static final String LOG_TAG = "OlmInboundGroupSession"; private static final String LOG_TAG = "OlmInboundGroupSession";
private transient int mUnreleasedCount;
/** session raw pointer value returned by JNI.<br> /** Session Id returned by JNI.<br>
* this value uniquely identifies the native inbound group session instance. * This value uniquely identifies the native inbound group session instance.
*/ */
private transient long mNativeId; private transient long mNativeId;
@ -68,7 +69,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
*/ */
public void releaseSession(){ public void releaseSession(){
releaseSessionJni(); releaseSessionJni();
mUnreleasedCount--;
mNativeId = 0; mNativeId = 0;
} }
@ -88,6 +89,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
private boolean createNewSession() { private boolean createNewSession() {
boolean retCode = false; boolean retCode = false;
if(0 != (mNativeId = createNewSessionJni())){ if(0 != (mNativeId = createNewSessionJni())){
mUnreleasedCount++;
retCode = true; retCode = true;
} }
return retCode; return retCode;
@ -232,4 +234,12 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
* @return null if operation succeed, an error message if operation failed * @return null if operation succeed, an error message if operation failed
*/ */
private native String initWithSerializedDataJni(String aSerializedData, String aKey); 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;
}
} }

View file

@ -35,9 +35,10 @@ import java.io.Serializable;
public class OlmOutboundGroupSession extends CommonSerializeUtils implements Serializable { public class OlmOutboundGroupSession extends CommonSerializeUtils implements Serializable {
private static final long serialVersionUID = -3133097431283604416L; private static final long serialVersionUID = -3133097431283604416L;
private static final String LOG_TAG = "OlmOutboundGroupSession"; private static final String LOG_TAG = "OlmOutboundGroupSession";
private transient int mUnreleasedCount;
/** session raw pointer value returned by JNI.<br> /** Session Id returned by JNI.<br>
* this value uniquely identifies the native inbound group session instance. * This value uniquely identifies the native outbound group session instance.
*/ */
private transient long mNativeId; private transient long mNativeId;
@ -154,6 +155,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
*/ */
public void releaseSession() { public void releaseSession() {
releaseSessionJni(); releaseSessionJni();
mUnreleasedCount--;
mNativeId = 0; mNativeId = 0;
} }
@ -174,6 +176,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
private boolean createNewSession() { private boolean createNewSession() {
boolean retCode = false; boolean retCode = false;
if(0 != (mNativeId = createNewSessionJni())){ if(0 != (mNativeId = createNewSessionJni())){
mUnreleasedCount++;
retCode = true; retCode = true;
} }
return retCode; return retCode;
@ -237,6 +240,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
/** /**
* Encrypt some plain-text message.<br> * 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 * @param aClearMsg message to be encrypted
* @return the encrypted message if operation succeed, null otherwise * @return the encrypted message if operation succeed, null otherwise
*/ */
@ -250,4 +254,12 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
return retValue; return retValue;
} }
private native String encryptMessageJni(String aClearMsg); private native String encryptMessageJni(String aClearMsg);
/**
* Return the number of unreleased OlmOutboundGroupSession instances.<br>
* @return number of unreleased instances
*/
public int getUnreleasedCount() {
return mUnreleasedCount;
}
} }

View file

@ -35,9 +35,10 @@ import java.io.Serializable;
public class OlmSession extends CommonSerializeUtils implements Serializable { public class OlmSession extends CommonSerializeUtils implements Serializable {
private static final long serialVersionUID = -8975488639186976419L; private static final long serialVersionUID = -8975488639186976419L;
private static final String LOG_TAG = "OlmSession"; private static final String LOG_TAG = "OlmSession";
private transient int mUnreleasedCount;
/** session raw pointer value (OlmSession*) returned by JNI. /** Session Id returned by JNI.
* this value uniquely identifies the native session instance. * This value uniquely identifies the native session instance.
**/ **/
private transient long mNativeId; private transient long mNativeId;
@ -158,7 +159,7 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
*/ */
public void releaseSession(){ public void releaseSession(){
releaseSessionJni(); releaseSessionJni();
mUnreleasedCount--;
mNativeId = 0; mNativeId = 0;
} }
@ -171,6 +172,7 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
private boolean initNewSession() { private boolean initNewSession() {
boolean retCode = false; boolean retCode = false;
if(0 != (mNativeId = initNewSessionJni())){ if(0 != (mNativeId = initNewSessionJni())){
mUnreleasedCount++;
retCode = true; retCode = true;
} }
return retCode; return retCode;
@ -194,6 +196,7 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
private boolean createNewSession() { private boolean createNewSession() {
boolean retCode = false; boolean retCode = false;
if(0 != (mNativeId = createNewSessionJni())){ if(0 != (mNativeId = createNewSessionJni())){
mUnreleasedCount++;
retCode = true; retCode = true;
} }
return retCode; return retCode;
@ -367,5 +370,13 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
} }
private native String decryptMessageJni(OlmMessage aEncryptedMsg); private native String decryptMessageJni(OlmMessage aEncryptedMsg);
/**
* Return the number of unreleased OlmSession instances.<br>
* @return number of unreleased instances
*/
public int getUnreleasedCount() {
return mUnreleasedCount;
}
} }

View file

@ -29,9 +29,10 @@ public class OlmUtility {
public static final int RANDOM_KEY_SIZE = 32; public static final int RANDOM_KEY_SIZE = 32;
public static final int RANDOM_RANGE = 256; public static final int RANDOM_RANGE = 256;
private transient int mUnreleasedCount;
/** raw pointer value returned by JNI. /** Instance Id returned by JNI.
* this value uniquely identifies this utility instance. * This value uniquely identifies this utility instance.
**/ **/
private long mNativeId; private long mNativeId;
@ -47,6 +48,7 @@ public class OlmUtility {
private boolean initUtility() { private boolean initUtility() {
boolean retCode = false; boolean retCode = false;
if(0 != (mNativeId = initUtilityJni())){ if(0 != (mNativeId = initUtilityJni())){
mUnreleasedCount++;
retCode = true; retCode = true;
} }
return retCode; return retCode;
@ -59,6 +61,7 @@ public class OlmUtility {
*/ */
public void releaseUtility(){ public void releaseUtility(){
releaseUtilityJni(); releaseUtilityJni();
mUnreleasedCount--;
mNativeId = 0; mNativeId = 0;
} }
private native void releaseUtilityJni(); private native void releaseUtilityJni();
@ -126,6 +129,10 @@ public class OlmUtility {
private native String sha256Jni(String aMessage); 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() { public static String getRandomKey() {
String keyRetValue; String keyRetValue;
Random rand = new Random(); Random rand = new Random();
@ -138,5 +145,13 @@ public class OlmUtility {
return keyRetValue; return keyRetValue;
} }
/**
* Return the number of unreleased OlmUtility instances.<br>
* @return number of unreleased instances
*/
public int getUnreleasedCount() {
return mUnreleasedCount;
}
} }