Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
improve_e2e_thread
Browse files Browse the repository at this point in the history
There is no more CryptoStore thread.
  • Loading branch information
ylecollen committed Jan 11, 2017
1 parent b2e7011 commit 56d8a6d
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 269 deletions.
Expand Up @@ -414,18 +414,6 @@ public void onUnexpectedError(Exception e) {
assertTrue(results.containsKey("setDeviceVerification1"));
assertTrue (aliceDeviceFromBobPOV.mVerified == MXDeviceInfo.DEVICE_VERIFICATION_BLOCKED);

// the device informations are saved in background thread so give a breath to save everything
MXFileCryptoStore bobFileStore = (MXFileCryptoStore)mBobSession.getCrypto().getCryptoStore();

final CountDownLatch lock3b = new CountDownLatch(1);
bobFileStore.getThreadHandler().post(new Runnable() {
@Override
public void run() {
lock3b.countDown();
}
});
lock3b.await(1000, TimeUnit.DAYS.MILLISECONDS);

Credentials bobCredentials = mBobSession.getCredentials();

Uri uri = Uri.parse(CryptoTestHelper.TESTS_HOME_SERVER_URL);
Expand Down Expand Up @@ -3133,31 +3121,6 @@ public void onLiveEvent(Event event, RoomState roomState) {
assertTrue(statuses + "", statuses.containsKey("AliceJoin"));

mBobSession.getDataHandler().removeListener(bobEventListener);

if (cryptedBob) {
// the crypto store data is saved in background thread
// so add a delay to let save the data
MXFileCryptoStore bobFileCryptoStore = (MXFileCryptoStore) mBobSession.getCrypto().getCryptoStore();
MXFileCryptoStore aliceFileCryptoStore = (MXFileCryptoStore) mAliceSession.getCrypto().getCryptoStore();

final CountDownLatch lock3 = new CountDownLatch(2);

bobFileCryptoStore.getThreadHandler().post(new Runnable() {
@Override
public void run() {
lock3.countDown();
}
});

aliceFileCryptoStore.getThreadHandler().post(new Runnable() {
@Override
public void run() {
lock3.countDown();
}
});

lock3.await(1000, TimeUnit.DAYS.MILLISECONDS);
}
}

private void doE2ETestWithAliceAndBobAndSamInARoom() throws Exception {
Expand Down Expand Up @@ -3377,30 +3340,6 @@ public void onToDeviceEvent(Event event) {
roomFromAlicePOV.sendEvent(buildTextEvent(messagesFromAlice.get(1), mAliceSession), callback);
lock.await(1000, TimeUnit.DAYS.MILLISECONDS);
assertTrue(mMessagesCount == 5);

// the crypto store data is saved in background thread
// so add a delay to let save the data

MXFileCryptoStore bobFileCryptoStore = (MXFileCryptoStore)mBobSession.getCrypto().getCryptoStore();
MXFileCryptoStore aliceFileCryptoStore = (MXFileCryptoStore)mAliceSession.getCrypto().getCryptoStore();

final CountDownLatch lock3 = new CountDownLatch(2);

bobFileCryptoStore.getThreadHandler().post(new Runnable() {
@Override
public void run() {
lock3.countDown();
}
});

aliceFileCryptoStore.getThreadHandler().post(new Runnable() {
@Override
public void run() {
lock3.countDown();
}
});

lock3.await(1000, TimeUnit.DAYS.MILLISECONDS);
}

private boolean checkEncryptedEvent(Event event, String roomId, String clearMessage, MXSession senderSession) throws Exception {
Expand Down
101 changes: 53 additions & 48 deletions matrix-sdk/src/main/java/org/matrix/androidsdk/crypto/MXCrypto.java
Expand Up @@ -421,57 +421,62 @@ public void run() {

@Override
public void onSuccess(Void info) {
if (!hasBeenReleased()) {
Log.d(LOG_TAG, "###########################################################");
Log.d(LOG_TAG, "uploadKeys done for " + mSession.getMyUserId());
Log.d(LOG_TAG, " - device id : " + mSession.getCredentials().deviceId);
Log.d(LOG_TAG, " - ed25519 : " + mOlmDevice.getDeviceEd25519Key());
Log.d(LOG_TAG, " - curve25519 : " + mOlmDevice.getDeviceCurve25519Key());
Log.d(LOG_TAG, " - oneTimeKeys: " + mLastPublishedOneTimeKeys); // They are
Log.d(LOG_TAG, "");

checkDeviceAnnounced(new ApiCallback<Void>() {
@Override
public void onSuccess(Void info) {
if (null != mNetworkConnectivityReceiver) {
mNetworkConnectivityReceiver.removeEventListener(mNetworkListener);
}

mIsStarting = false;
mIsStarted = true;
startUploadKeysTimer(true);

for (ApiCallback<Void> callback : mInitializationCallbacks) {
final ApiCallback<Void> fCallback = callback;
getUIHandler().post(new Runnable() {
@Override
public void run() {
fCallback.onSuccess(null);
getEncryptingThreadHandler().post(new Runnable() {
@Override
public void run() {
if (!hasBeenReleased()) {
Log.d(LOG_TAG, "###########################################################");
Log.d(LOG_TAG, "uploadKeys done for " + mSession.getMyUserId());
Log.d(LOG_TAG, " - device id : " + mSession.getCredentials().deviceId);
Log.d(LOG_TAG, " - ed25519 : " + mOlmDevice.getDeviceEd25519Key());
Log.d(LOG_TAG, " - curve25519 : " + mOlmDevice.getDeviceCurve25519Key());
Log.d(LOG_TAG, " - oneTimeKeys: " + mLastPublishedOneTimeKeys); // They are
Log.d(LOG_TAG, "");

checkDeviceAnnounced(new ApiCallback<Void>() {
@Override
public void onSuccess(Void info) {
if (null != mNetworkConnectivityReceiver) {
mNetworkConnectivityReceiver.removeEventListener(mNetworkListener);
}
});
}
mInitializationCallbacks.clear();
}

@Override
public void onNetworkError(Exception e) {
Log.e(LOG_TAG, "## start failed : " + e.getMessage());
onError();
}

@Override
public void onMatrixError(MatrixError e) {
Log.e(LOG_TAG, "## start failed : " + e.getMessage());
onError();
}

@Override
public void onUnexpectedError(Exception e) {
Log.e(LOG_TAG, "## start failed : " + e.getMessage());
onError();
mIsStarting = false;
mIsStarted = true;
startUploadKeysTimer(true);

for (ApiCallback<Void> callback : mInitializationCallbacks) {
final ApiCallback<Void> fCallback = callback;
getUIHandler().post(new Runnable() {
@Override
public void run() {
fCallback.onSuccess(null);
}
});
}
mInitializationCallbacks.clear();
}

@Override
public void onNetworkError(Exception e) {
Log.e(LOG_TAG, "## start failed : " + e.getMessage());
onError();
}

@Override
public void onMatrixError(MatrixError e) {
Log.e(LOG_TAG, "## start failed : " + e.getMessage());
onError();
}

@Override
public void onUnexpectedError(Exception e) {
Log.e(LOG_TAG, "## start failed : " + e.getMessage());
onError();
}
});
}
});
}
}
});
}

@Override
Expand Down

0 comments on commit 56d8a6d

Please sign in to comment.