Search in sources :

Example 1 with OlmManager

use of org.matrix.olm.OlmManager 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);
    }
}
Also used : MXFileCryptoStore(org.matrix.androidsdk.data.cryptostore.MXFileCryptoStore) OlmManager(org.matrix.olm.OlmManager) MXCrypto(org.matrix.androidsdk.crypto.MXCrypto)

Aggregations

MXCrypto (org.matrix.androidsdk.crypto.MXCrypto)1 MXFileCryptoStore (org.matrix.androidsdk.data.cryptostore.MXFileCryptoStore)1 OlmManager (org.matrix.olm.OlmManager)1