use of org.matrix.androidsdk.data.cryptostore.MXFileCryptoStore in project matrix-android-sdk by matrix-org.
the class MXSession method checkCrypto.
/**
* Check if the crypto engine is properly initialized.
* Launch it it is was not yet done.
*/
public void checkCrypto() {
MXFileCryptoStore fileCryptoStore = new MXFileCryptoStore();
fileCryptoStore.initWithCredentials(mAppContent, mCredentials);
if ((fileCryptoStore.hasData() || mEnableCryptoWhenStartingMXSession) && (null == mCrypto)) {
boolean isStoreLoaded = false;
try {
// open the store
fileCryptoStore.open();
isStoreLoaded = true;
} catch (UnsatisfiedLinkError e) {
Log.e(LOG_TAG, "## checkCrypto() failed " + e.getMessage());
}
if (!isStoreLoaded) {
// load again the olm manager
// reported by rageshake, it seems that the olm lib is unloaded.
mOlmManager = new OlmManager();
try {
// open the store
fileCryptoStore.open();
isStoreLoaded = true;
} catch (UnsatisfiedLinkError e) {
Log.e(LOG_TAG, "## checkCrypto() failed 2 " + e.getMessage());
}
}
if (!isStoreLoaded) {
Log.e(LOG_TAG, "## checkCrypto() : cannot enable the crypto because of olm lib");
return;
}
mCrypto = new MXCrypto(MXSession.this, fileCryptoStore);
mDataHandler.setCrypto(mCrypto);
// the room summaries are not stored with decrypted content
decryptRoomSummaries();
Log.d(LOG_TAG, "## checkCrypto() : the crypto engine is ready");
} else if (mDataHandler.getCrypto() != mCrypto) {
Log.e(LOG_TAG, "## checkCrypto() : the data handler crypto was not initialized");
mDataHandler.setCrypto(mCrypto);
}
}
use of org.matrix.androidsdk.data.cryptostore.MXFileCryptoStore in project matrix-android-sdk by matrix-org.
the class MXSession method enableCrypto.
/**
* Enable / disable the crypto.
*
* @param cryptoEnabled true to enable the crypto
* @param callback the asynchronous callback called when the action has been done
*/
public void enableCrypto(boolean cryptoEnabled, final ApiCallback<Void> callback) {
if (cryptoEnabled != isCryptoEnabled()) {
if (cryptoEnabled) {
Log.d(LOG_TAG, "Crypto is enabled");
MXFileCryptoStore fileCryptoStore = new MXFileCryptoStore();
fileCryptoStore.initWithCredentials(mAppContent, mCredentials);
fileCryptoStore.open();
mCrypto = new MXCrypto(this, fileCryptoStore);
mCrypto.start(true, new ApiCallback<Void>() {
@Override
public void onSuccess(Void info) {
decryptRoomSummaries();
if (null != callback) {
callback.onSuccess(null);
}
}
@Override
public void onNetworkError(Exception e) {
if (null != callback) {
callback.onNetworkError(e);
}
}
@Override
public void onMatrixError(MatrixError e) {
if (null != callback) {
callback.onMatrixError(e);
}
}
@Override
public void onUnexpectedError(Exception e) {
if (null != callback) {
callback.onUnexpectedError(e);
}
}
});
} else if (null != mCrypto) {
Log.d(LOG_TAG, "Crypto is disabled");
IMXCryptoStore store = mCrypto.mCryptoStore;
mCrypto.close();
store.deleteStore();
mCrypto = null;
mDataHandler.setCrypto(null);
decryptRoomSummaries();
if (null != callback) {
callback.onSuccess(null);
}
}
mDataHandler.setCrypto(mCrypto);
} else {
if (null != callback) {
callback.onSuccess(null);
}
}
}
Aggregations