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 c5122b2..2152a8d 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 @@ -180,8 +180,8 @@ public class OlmGroupSessionTest { @Test public void test14CheckUnreleaseedCount() { - assertTrue(0==mAliceOutboundGroupSession.getUnreleasedCount()); - assertTrue(0==mBobInboundGroupSession.getUnreleasedCount()); + assertTrue(mAliceOutboundGroupSession.isReleased()); + assertTrue(mBobInboundGroupSession.isReleased()); } @Test @@ -235,8 +235,8 @@ public class OlmGroupSessionTest { outboundGroupSessionRef.releaseSession(); outboundGroupSessionSerial.releaseSession(); - assertTrue(0==outboundGroupSessionRef.getUnreleasedCount()); - assertTrue(0==outboundGroupSessionSerial.getUnreleasedCount()); + assertTrue(outboundGroupSessionRef.isReleased()); + assertTrue(outboundGroupSessionSerial.isReleased()); } catch (FileNotFoundException e) { Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception FileNotFoundException Msg=="+e.getMessage()); } catch (ClassNotFoundException e) { @@ -309,9 +309,9 @@ public class OlmGroupSessionTest { bobInboundGroupSessionRef.releaseSession(); bobInboundGroupSessionSerial.releaseSession(); - assertTrue(0==aliceOutboundGroupSession.getUnreleasedCount()); - assertTrue(0==bobInboundGroupSessionRef.getUnreleasedCount()); - assertTrue(0==bobInboundGroupSessionSerial.getUnreleasedCount()); + assertTrue(aliceOutboundGroupSession.isReleased()); + assertTrue(bobInboundGroupSessionRef.isReleased()); + assertTrue(bobInboundGroupSessionSerial.isReleased()); } catch (FileNotFoundException e) { Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception FileNotFoundException Msg=="+e.getMessage()); } catch (ClassNotFoundException e) { @@ -405,14 +405,14 @@ public class OlmGroupSessionTest { 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()); + assertTrue(outboundGroupSession1.isReleased()); + assertTrue(outboundGroupSession2.isReleased()); + assertTrue(outboundGroupSession3.isReleased()); + assertTrue(outboundGroupSession4.isReleased()); + assertTrue(outboundGroupSession5.isReleased()); + assertTrue(outboundGroupSession6.isReleased()); + assertTrue(outboundGroupSession7.isReleased()); + assertTrue(outboundGroupSession8.isReleased()); } 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 df8dadb..b25d865 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 @@ -143,14 +143,14 @@ public class OlmSessionTest { // release accounts bobAccount.releaseAccount(); aliceAccount.releaseAccount(); - assertTrue(0==bobAccount.getUnreleasedCount()); - assertTrue(0==aliceAccount.getUnreleasedCount()); + assertTrue(bobAccount.isReleased()); + assertTrue(aliceAccount.isReleased()); // release sessions bobSession.releaseSession(); aliceSession.releaseSession(); - assertTrue(0==bobSession.getUnreleasedCount()); - assertTrue(0==aliceSession.getUnreleasedCount()); + assertTrue(bobSession.isReleased()); + assertTrue(aliceSession.isReleased()); } @@ -273,13 +273,13 @@ public class OlmSessionTest { assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession)); bobAccount.releaseAccount(); aliceAccount.releaseAccount(); - assertTrue(0==bobAccount.getUnreleasedCount()); - assertTrue(0==aliceAccount.getUnreleasedCount()); + assertTrue(bobAccount.isReleased()); + assertTrue(aliceAccount.isReleased()); bobSession.releaseSession(); aliceSession.releaseSession(); - assertTrue(0==bobSession.getUnreleasedCount()); - assertTrue(0==aliceSession.getUnreleasedCount()); + assertTrue(bobSession.isReleased()); + assertTrue(aliceSession.isReleased()); } @@ -329,13 +329,13 @@ public class OlmSessionTest { aliceAccount.releaseAccount(); bobAccount.releaseAccount(); - assertTrue(0==aliceAccount.getUnreleasedCount()); - assertTrue(0==bobAccount.getUnreleasedCount()); + assertTrue(aliceAccount.isReleased()); + assertTrue(bobAccount.isReleased()); bobSession.releaseSession(); aliceSession.releaseSession(); - assertTrue(0==bobSession.getUnreleasedCount()); - assertTrue(0==aliceSession.getUnreleasedCount()); + assertTrue(bobSession.isReleased()); + assertTrue(aliceSession.isReleased()); } @Test @@ -391,13 +391,13 @@ public class OlmSessionTest { assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession)); aliceAccount.releaseAccount(); bobAccount.releaseAccount(); - assertTrue(0==aliceAccount.getUnreleasedCount()); - assertTrue(0==bobAccount.getUnreleasedCount()); + assertTrue(aliceAccount.isReleased()); + assertTrue(bobAccount.isReleased()); aliceSession.releaseSession(); bobSession.releaseSession(); - assertTrue(0==aliceSession.getUnreleasedCount()); - assertTrue(0==bobSession.getUnreleasedCount()); + assertTrue(aliceSession.isReleased()); + assertTrue(bobSession.isReleased()); } // ******************************************************** @@ -522,15 +522,15 @@ public class OlmSessionTest { assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession)); bobAccount.releaseAccount(); aliceAccount.releaseAccount(); - assertTrue(0==bobAccount.getUnreleasedCount()); - assertTrue(0==aliceAccount.getUnreleasedCount()); + assertTrue(bobAccount.isReleased()); + assertTrue(aliceAccount.isReleased()); bobSession.releaseSession(); aliceSession.releaseSession(); aliceSessionDeserial.releaseSession(); - assertTrue(0==bobSession.getUnreleasedCount()); - assertTrue(0==aliceSession.getUnreleasedCount()); - assertTrue(0==aliceSessionDeserial.getUnreleasedCount()); + assertTrue(bobSession.isReleased()); + assertTrue(aliceSession.isReleased()); + assertTrue(aliceSessionDeserial.isReleased()); } catch (FileNotFoundException e) { Log.e(LOG_TAG, "## test03SessionSerialization(): Exception FileNotFoundException Msg=="+e.getMessage()); @@ -631,13 +631,13 @@ public class OlmSessionTest { assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession)); aliceAccount.releaseAccount(); bobAccount.releaseAccount(); - assertTrue(0==aliceAccount.getUnreleasedCount()); - assertTrue(0==bobAccount.getUnreleasedCount()); + assertTrue(aliceAccount.isReleased()); + assertTrue(bobAccount.isReleased()); aliceSession.releaseSession(); bobSession.releaseSession(); - assertTrue(0==aliceSession.getUnreleasedCount()); - assertTrue(0==bobSession.getUnreleasedCount()); + assertTrue(aliceSession.isReleased()); + assertTrue(bobSession.isReleased()); } } 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 a1b3f81..9a97205 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 @@ -106,13 +106,12 @@ public class OlmUtilityTest { assertFalse(String.valueOf(errorMsg).isEmpty()); utility.releaseUtility(); - assertTrue(0==utility.getUnreleasedCount()); + assertTrue(utility.isReleased()); account.releaseAccount(); - assertTrue(0==account.getUnreleasedCount()); + assertTrue(account.isReleased()); } - @Test public void test02sha256() { OlmUtility utility = new OlmUtility(); @@ -122,6 +121,6 @@ public class OlmUtilityTest { assertFalse(TextUtils.isEmpty(hashResult)); utility.releaseUtility(); - assertTrue(0==utility.getUnreleasedCount()); + assertTrue(utility.isReleased()); } } 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 0aa2c3d..2d91634 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 @@ -39,7 +39,6 @@ import java.util.Map; 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 @@ -171,7 +170,6 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { */ public void releaseAccount(){ releaseAccountJni(); - mUnreleasedCount--; mNativeId = 0; } @@ -190,12 +188,8 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { * @return true if init succeed, false otherwise. */ private boolean initNewAccount() { - boolean retCode = false; - if(0 != (mNativeId = initNewAccountJni())){ - mUnreleasedCount++; - retCode = true; - } - return retCode; + mNativeId = initNewAccountJni(); + return (0 != mNativeId); } /** @@ -213,12 +207,8 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { * @return true if init succeed, false otherwise. */ private boolean createNewAccount() { - boolean retCode = false; - if(0 != (mNativeId = createNewAccountJni())){ - mUnreleasedCount++; - retCode = true; - } - return retCode; + mNativeId = initNewAccountJni(); + return (0 != mNativeId); } /** @@ -384,11 +374,11 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { private native String signMessageJni(byte[] aMessage); /** - * Return the number of unreleased OlmAccount instances.
- * @return number of unreleased instances + * Return true the object resources have been released.
+ * @return true the object resources have been released */ - public int getUnreleasedCount() { - return mUnreleasedCount; + public boolean isReleased() { + return (0 == mNativeId); } /** 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 ee5a20a..2e32a30 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 @@ -35,7 +35,6 @@ 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 Id returned by JNI.
* This value uniquely identifies the native inbound group session instance. @@ -75,7 +74,6 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri */ public void releaseSession(){ releaseSessionJni(); - mUnreleasedCount--; mNativeId = 0; } @@ -93,12 +91,8 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri * @return true if init succeed, false otherwise. */ private boolean createNewSession() { - boolean retCode = false; - if(0 != (mNativeId = createNewSessionJni())){ - mUnreleasedCount++; - retCode = true; - } - return retCode; + mNativeId = createNewSessionJni(); + return (0 != mNativeId); } /** @@ -263,10 +257,10 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri private native String initWithSerializedDataJni(String aSerializedData, String aKey); /** - * Return the number of unreleased OlmInboundGroupSession instances.
- * @return number of unreleased instances + * Return true the object resources have been released.
+ * @return true the object resources have been released */ - public int getUnreleasedCount() { - return mUnreleasedCount; + public boolean isReleased() { + return (0 == mNativeId); } } 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 4aa07b4..4c09313 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 @@ -36,7 +36,6 @@ 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 Id returned by JNI.
* This value uniquely identifies the native outbound group session instance. @@ -156,7 +155,6 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser */ public void releaseSession() { releaseSessionJni(); - mUnreleasedCount--; mNativeId = 0; } @@ -175,12 +173,8 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser * @return true if init succeed, false otherwise. */ private boolean createNewSession() { - boolean retCode = false; - if(0 != (mNativeId = createNewSessionJni())){ - mUnreleasedCount++; - retCode = true; - } - return retCode; + mNativeId = createNewSessionJni(); + return (0 != mNativeId); } /** @@ -204,11 +198,9 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser * @return session identifier if operation succeed, null otherwise. */ public String sessionIdentifier() { - String retValue = null; - retValue = sessionIdentifierJni(); - - return retValue; + return sessionIdentifierJni(); } + private native String sessionIdentifierJni(); /** @@ -218,10 +210,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser * @return current session index */ public int messageIndex() { - int retValue =0; - retValue = messageIndexJni(); - - return retValue; + return messageIndexJni(); } private native int messageIndexJni(); @@ -232,10 +221,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser * @return outbound session key */ public String sessionKey() { - String retValue = null; - retValue = sessionKeyJni(); - - return retValue; + return sessionKeyJni(); } private native String sessionKeyJni(); @@ -257,10 +243,10 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser private native String encryptMessageJni(String aClearMsg); /** - * Return the number of unreleased OlmOutboundGroupSession instances.
- * @return number of unreleased instances + * Return true the object resources have been released.
+ * @return true the object resources have been released */ - public int getUnreleasedCount() { - return mUnreleasedCount; + public boolean isReleased() { + return (0 == mNativeId); } } 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 374659d..139cbb6 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 @@ -36,14 +36,12 @@ 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 Id returned by JNI. * This value uniquely identifies the native session instance. **/ private transient long mNativeId; - public OlmSession() throws OlmException { if(!initNewSession()) { throw new OlmException(OlmException.EXCEPTION_CODE_INIT_SESSION_CREATION, OlmException.EXCEPTION_MSG_INIT_SESSION_CREATION); @@ -160,7 +158,6 @@ public class OlmSession extends CommonSerializeUtils implements Serializable { */ public void releaseSession(){ releaseSessionJni(); - mUnreleasedCount--; mNativeId = 0; } @@ -171,12 +168,8 @@ public class OlmSession extends CommonSerializeUtils implements Serializable { * @return true if init succeed, false otherwise. */ private boolean initNewSession() { - boolean retCode = false; - if(0 != (mNativeId = initNewSessionJni())){ - mUnreleasedCount++; - retCode = true; - } - return retCode; + mNativeId = initNewSessionJni(); + return (0 != mNativeId); } /** @@ -195,12 +188,8 @@ public class OlmSession extends CommonSerializeUtils implements Serializable { * @return true if init succeed, false otherwise. */ private boolean createNewSession() { - boolean retCode = false; - if(0 != (mNativeId = createNewSessionJni())){ - mUnreleasedCount++; - retCode = true; - } - return retCode; + mNativeId = initNewSessionJni(); + return (0 != mNativeId); } /** @@ -368,11 +357,11 @@ public class OlmSession extends CommonSerializeUtils implements Serializable { private native String decryptMessageJni(OlmMessage aEncryptedMsg, boolean aIsUtf8ConversionRequired); /** - * Return the number of unreleased OlmSession instances.
- * @return number of unreleased instances + * Return true the object resources have been released.
+ * @return true the object resources have been released */ - public int getUnreleasedCount() { - return mUnreleasedCount; + public boolean isReleased() { + return (0 == mNativeId); } } 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 c90e552..8db9dca 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 @@ -30,7 +30,6 @@ public class OlmUtility { public static final int RANDOM_KEY_SIZE = 32; public static final int RANDOM_RANGE = 256; - private transient int mUnreleasedCount; /** Instance Id returned by JNI. * This value uniquely identifies this utility instance. @@ -47,13 +46,10 @@ public class OlmUtility { * @return true if init succeed, false otherwise. */ private boolean initUtility() { - boolean retCode = false; - if(0 != (mNativeId = initUtilityJni())){ - mUnreleasedCount++; - retCode = true; - } - return retCode; + mNativeId = initUtilityJni(); + return (0 != mNativeId); } + private native long initUtilityJni(); /** @@ -62,7 +58,6 @@ public class OlmUtility { */ public void releaseUtility(){ releaseUtilityJni(); - mUnreleasedCount--; mNativeId = 0; } private native void releaseUtilityJni(); @@ -148,11 +143,11 @@ public class OlmUtility { } /** - * Return the number of unreleased OlmUtility instances.
- * @return number of unreleased instances + * Return true the object resources have been released.
+ * @return true the object resources have been released */ - public int getUnreleasedCount() { - return mUnreleasedCount; + public boolean isReleased() { + return (0 == mNativeId); } }