Commit 5e0bbe77 authored by ylecollen's avatar ylecollen
Browse files

Rename getUnreleasedCount to isReleased.

parent 47a52dcf
...@@ -180,8 +180,8 @@ public class OlmGroupSessionTest { ...@@ -180,8 +180,8 @@ public class OlmGroupSessionTest {
@Test @Test
public void test14CheckUnreleaseedCount() { public void test14CheckUnreleaseedCount() {
assertTrue(0==mAliceOutboundGroupSession.getUnreleasedCount()); assertTrue(mAliceOutboundGroupSession.isReleased());
assertTrue(0==mBobInboundGroupSession.getUnreleasedCount()); assertTrue(mBobInboundGroupSession.isReleased());
} }
@Test @Test
...@@ -235,8 +235,8 @@ public class OlmGroupSessionTest { ...@@ -235,8 +235,8 @@ public class OlmGroupSessionTest {
outboundGroupSessionRef.releaseSession(); outboundGroupSessionRef.releaseSession();
outboundGroupSessionSerial.releaseSession(); outboundGroupSessionSerial.releaseSession();
assertTrue(0==outboundGroupSessionRef.getUnreleasedCount()); assertTrue(outboundGroupSessionRef.isReleased());
assertTrue(0==outboundGroupSessionSerial.getUnreleasedCount()); assertTrue(outboundGroupSessionSerial.isReleased());
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception FileNotFoundException Msg=="+e.getMessage()); Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception FileNotFoundException Msg=="+e.getMessage());
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
...@@ -309,9 +309,9 @@ public class OlmGroupSessionTest { ...@@ -309,9 +309,9 @@ public class OlmGroupSessionTest {
bobInboundGroupSessionRef.releaseSession(); bobInboundGroupSessionRef.releaseSession();
bobInboundGroupSessionSerial.releaseSession(); bobInboundGroupSessionSerial.releaseSession();
assertTrue(0==aliceOutboundGroupSession.getUnreleasedCount()); assertTrue(aliceOutboundGroupSession.isReleased());
assertTrue(0==bobInboundGroupSessionRef.getUnreleasedCount()); assertTrue(bobInboundGroupSessionRef.isReleased());
assertTrue(0==bobInboundGroupSessionSerial.getUnreleasedCount()); assertTrue(bobInboundGroupSessionSerial.isReleased());
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception FileNotFoundException Msg=="+e.getMessage()); Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception FileNotFoundException Msg=="+e.getMessage());
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
...@@ -405,14 +405,14 @@ public class OlmGroupSessionTest { ...@@ -405,14 +405,14 @@ public class OlmGroupSessionTest {
outboundGroupSession7.releaseSession(); outboundGroupSession7.releaseSession();
outboundGroupSession8.releaseSession(); outboundGroupSession8.releaseSession();
assertTrue(0==outboundGroupSession1.getUnreleasedCount()); assertTrue(outboundGroupSession1.isReleased());
assertTrue(0==outboundGroupSession2.getUnreleasedCount()); assertTrue(outboundGroupSession2.isReleased());
assertTrue(0==outboundGroupSession3.getUnreleasedCount()); assertTrue(outboundGroupSession3.isReleased());
assertTrue(0==outboundGroupSession4.getUnreleasedCount()); assertTrue(outboundGroupSession4.isReleased());
assertTrue(0==outboundGroupSession5.getUnreleasedCount()); assertTrue(outboundGroupSession5.isReleased());
assertTrue(0==outboundGroupSession6.getUnreleasedCount()); assertTrue(outboundGroupSession6.isReleased());
assertTrue(0==outboundGroupSession7.getUnreleasedCount()); assertTrue(outboundGroupSession7.isReleased());
assertTrue(0==outboundGroupSession8.getUnreleasedCount()); assertTrue(outboundGroupSession8.isReleased());
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false); assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false);
} }
......
...@@ -143,14 +143,14 @@ public class OlmSessionTest { ...@@ -143,14 +143,14 @@ public class OlmSessionTest {
// release accounts // release accounts
bobAccount.releaseAccount(); bobAccount.releaseAccount();
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
assertTrue(0==bobAccount.getUnreleasedCount()); assertTrue(bobAccount.isReleased());
assertTrue(0==aliceAccount.getUnreleasedCount()); assertTrue(aliceAccount.isReleased());
// release sessions // release sessions
bobSession.releaseSession(); bobSession.releaseSession();
aliceSession.releaseSession(); aliceSession.releaseSession();
assertTrue(0==bobSession.getUnreleasedCount()); assertTrue(bobSession.isReleased());
assertTrue(0==aliceSession.getUnreleasedCount()); assertTrue(aliceSession.isReleased());
} }
...@@ -273,13 +273,13 @@ public class OlmSessionTest { ...@@ -273,13 +273,13 @@ 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(bobAccount.isReleased());
assertTrue(0==aliceAccount.getUnreleasedCount()); assertTrue(aliceAccount.isReleased());
bobSession.releaseSession(); bobSession.releaseSession();
aliceSession.releaseSession(); aliceSession.releaseSession();
assertTrue(0==bobSession.getUnreleasedCount()); assertTrue(bobSession.isReleased());
assertTrue(0==aliceSession.getUnreleasedCount()); assertTrue(aliceSession.isReleased());
} }
...@@ -329,13 +329,13 @@ public class OlmSessionTest { ...@@ -329,13 +329,13 @@ public class OlmSessionTest {
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
bobAccount.releaseAccount(); bobAccount.releaseAccount();
assertTrue(0==aliceAccount.getUnreleasedCount()); assertTrue(aliceAccount.isReleased());
assertTrue(0==bobAccount.getUnreleasedCount()); assertTrue(bobAccount.isReleased());
bobSession.releaseSession(); bobSession.releaseSession();
aliceSession.releaseSession(); aliceSession.releaseSession();
assertTrue(0==bobSession.getUnreleasedCount()); assertTrue(bobSession.isReleased());
assertTrue(0==aliceSession.getUnreleasedCount()); assertTrue(aliceSession.isReleased());
} }
@Test @Test
...@@ -391,13 +391,13 @@ public class OlmSessionTest { ...@@ -391,13 +391,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(aliceAccount.isReleased());
assertTrue(0==bobAccount.getUnreleasedCount()); assertTrue(bobAccount.isReleased());
aliceSession.releaseSession(); aliceSession.releaseSession();
bobSession.releaseSession(); bobSession.releaseSession();
assertTrue(0==aliceSession.getUnreleasedCount()); assertTrue(aliceSession.isReleased());
assertTrue(0==bobSession.getUnreleasedCount()); assertTrue(bobSession.isReleased());
} }
// ******************************************************** // ********************************************************
...@@ -522,15 +522,15 @@ public class OlmSessionTest { ...@@ -522,15 +522,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(bobAccount.isReleased());
assertTrue(0==aliceAccount.getUnreleasedCount()); assertTrue(aliceAccount.isReleased());
bobSession.releaseSession(); bobSession.releaseSession();
aliceSession.releaseSession(); aliceSession.releaseSession();
aliceSessionDeserial.releaseSession(); aliceSessionDeserial.releaseSession();
assertTrue(0==bobSession.getUnreleasedCount()); assertTrue(bobSession.isReleased());
assertTrue(0==aliceSession.getUnreleasedCount()); assertTrue(aliceSession.isReleased());
assertTrue(0==aliceSessionDeserial.getUnreleasedCount()); assertTrue(aliceSessionDeserial.isReleased());
} }
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());
...@@ -631,13 +631,13 @@ public class OlmSessionTest { ...@@ -631,13 +631,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(aliceAccount.isReleased());
assertTrue(0==bobAccount.getUnreleasedCount()); assertTrue(bobAccount.isReleased());
aliceSession.releaseSession(); aliceSession.releaseSession();
bobSession.releaseSession(); bobSession.releaseSession();
assertTrue(0==aliceSession.getUnreleasedCount()); assertTrue(aliceSession.isReleased());
assertTrue(0==bobSession.getUnreleasedCount()); assertTrue(bobSession.isReleased());
} }
} }
...@@ -106,13 +106,12 @@ public class OlmUtilityTest { ...@@ -106,13 +106,12 @@ public class OlmUtilityTest {
assertFalse(String.valueOf(errorMsg).isEmpty()); assertFalse(String.valueOf(errorMsg).isEmpty());
utility.releaseUtility(); utility.releaseUtility();
assertTrue(0==utility.getUnreleasedCount()); assertTrue(utility.isReleased());
account.releaseAccount(); account.releaseAccount();
assertTrue(0==account.getUnreleasedCount()); assertTrue(account.isReleased());
} }
@Test @Test
public void test02sha256() { public void test02sha256() {
OlmUtility utility = new OlmUtility(); OlmUtility utility = new OlmUtility();
...@@ -122,6 +121,6 @@ public class OlmUtilityTest { ...@@ -122,6 +121,6 @@ public class OlmUtilityTest {
assertFalse(TextUtils.isEmpty(hashResult)); assertFalse(TextUtils.isEmpty(hashResult));
utility.releaseUtility(); utility.releaseUtility();
assertTrue(0==utility.getUnreleasedCount()); assertTrue(utility.isReleased());
} }
} }
...@@ -39,7 +39,6 @@ import java.util.Map; ...@@ -39,7 +39,6 @@ import java.util.Map;
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
...@@ -171,7 +170,6 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { ...@@ -171,7 +170,6 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
*/ */
public void releaseAccount(){ public void releaseAccount(){
releaseAccountJni(); releaseAccountJni();
mUnreleasedCount--;
mNativeId = 0; mNativeId = 0;
} }
...@@ -190,12 +188,8 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { ...@@ -190,12 +188,8 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
* @return true if init succeed, false otherwise. * @return true if init succeed, false otherwise.
*/ */
private boolean initNewAccount() { private boolean initNewAccount() {
boolean retCode = false; mNativeId = initNewAccountJni();
if(0 != (mNativeId = initNewAccountJni())){ return (0 != mNativeId);
mUnreleasedCount++;
retCode = true;
}
return retCode;
} }
/** /**
...@@ -213,12 +207,8 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { ...@@ -213,12 +207,8 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
* @return true if init succeed, false otherwise. * @return true if init succeed, false otherwise.
*/ */
private boolean createNewAccount() { private boolean createNewAccount() {
boolean retCode = false; mNativeId = initNewAccountJni();
if(0 != (mNativeId = createNewAccountJni())){ return (0 != mNativeId);
mUnreleasedCount++;
retCode = true;
}
return retCode;
} }
/** /**
...@@ -384,11 +374,11 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { ...@@ -384,11 +374,11 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
private native String signMessageJni(byte[] aMessage); private native String signMessageJni(byte[] aMessage);
/** /**
* Return the number of unreleased OlmAccount instances.<br> * Return true the object resources have been released.<br>
* @return number of unreleased instances * @return true the object resources have been released
*/ */
public int getUnreleasedCount() { public boolean isReleased() {
return mUnreleasedCount; return (0 == mNativeId);
} }
/** /**
......
...@@ -35,7 +35,6 @@ import java.io.Serializable; ...@@ -35,7 +35,6 @@ 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 Id 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.
...@@ -75,7 +74,6 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri ...@@ -75,7 +74,6 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
*/ */
public void releaseSession(){ public void releaseSession(){
releaseSessionJni(); releaseSessionJni();
mUnreleasedCount--;
mNativeId = 0; mNativeId = 0;
} }
...@@ -93,12 +91,8 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri ...@@ -93,12 +91,8 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
* @return true if init succeed, false otherwise. * @return true if init succeed, false otherwise.
*/ */
private boolean createNewSession() { private boolean createNewSession() {
boolean retCode = false; mNativeId = createNewSessionJni();
if(0 != (mNativeId = createNewSessionJni())){ return (0 != mNativeId);
mUnreleasedCount++;
retCode = true;
}
return retCode;
} }
/** /**
...@@ -263,10 +257,10 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri ...@@ -263,10 +257,10 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
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 true the object resources have been released.<br>
* @return number of unreleased instances * @return true the object resources have been released
*/ */
public int getUnreleasedCount() { public boolean isReleased() {
return mUnreleasedCount; return (0 == mNativeId);
} }
} }
...@@ -36,7 +36,6 @@ import java.io.Serializable; ...@@ -36,7 +36,6 @@ 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 Id returned by JNI.<br> /** Session Id returned by JNI.<br>
* This value uniquely identifies the native outbound group session instance. * This value uniquely identifies the native outbound group session instance.
...@@ -156,7 +155,6 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser ...@@ -156,7 +155,6 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
*/ */
public void releaseSession() { public void releaseSession() {
releaseSessionJni(); releaseSessionJni();
mUnreleasedCount--;
mNativeId = 0; mNativeId = 0;
} }
...@@ -175,12 +173,8 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser ...@@ -175,12 +173,8 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
* @return true if init succeed, false otherwise. * @return true if init succeed, false otherwise.
*/ */
private boolean createNewSession() { private boolean createNewSession() {
boolean retCode = false; mNativeId = createNewSessionJni();
if(0 != (mNativeId = createNewSessionJni())){ return (0 != mNativeId);
mUnreleasedCount++;
retCode = true;
}
return retCode;
} }
/** /**
...@@ -204,11 +198,9 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser ...@@ -204,11 +198,9 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
* @return session identifier if operation succeed, null otherwise. * @return session identifier if operation succeed, null otherwise.
*/ */
public String sessionIdentifier() { public String sessionIdentifier() {
String retValue = null; return sessionIdentifierJni();
retValue = sessionIdentifierJni();
return retValue;
} }
private native String sessionIdentifierJni(); private native String sessionIdentifierJni();
/** /**
...@@ -218,10 +210,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser ...@@ -218,10 +210,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
* @return current session index * @return current session index
*/ */
public int messageIndex() { public int messageIndex() {
int retValue =0; return messageIndexJni();
retValue = messageIndexJni();
return retValue;
} }
private native int messageIndexJni(); private native int messageIndexJni();
...@@ -232,10 +221,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser ...@@ -232,10 +221,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
* @return outbound session key * @return outbound session key
*/ */
public String sessionKey() { public String sessionKey() {
String retValue = null; return sessionKeyJni();
retValue = sessionKeyJni();
return retValue;
} }
private native String sessionKeyJni(); private native String sessionKeyJni();
...@@ -257,10 +243,10 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser ...@@ -257,10 +243,10 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
private native String encryptMessageJni(String aClearMsg); private native String encryptMessageJni(String aClearMsg);
/** /**
* Return the number of unreleased OlmOutboundGroupSession instances.<br> * Return true the object resources have been released.<br>
* @return number of unreleased instances * @return true the object resources have been released
*/ */
public int getUnreleasedCount() { public boolean isReleased() {
return mUnreleasedCount; return (0 == mNativeId);
} }
} }
...@@ -36,14 +36,12 @@ import java.io.Serializable; ...@@ -36,14 +36,12 @@ 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 Id 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;
public OlmSession() throws OlmException { public OlmSession() throws OlmException {
if(!initNewSession()) { if(!initNewSession()) {
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_SESSION_CREATION, OlmException.EXCEPTION_MSG_INIT_SESSION_CREATION); 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 { ...@@ -160,7 +158,6 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
*/ */
public void releaseSession(){ public void releaseSession(){
releaseSessionJni(); releaseSessionJni();
mUnreleasedCount--;
mNativeId = 0; mNativeId = 0;
} }
...@@ -171,12 +168,8 @@ public class OlmSession extends CommonSerializeUtils implements Serializable { ...@@ -171,12 +168,8 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
* @return true if init succeed, false otherwise. * @return true if init succeed, false otherwise.
*/ */
private boolean initNewSession() { private boolean initNewSession() {
boolean retCode = false;