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

Commit

Permalink
Fix crash in MXCryptoImpl (element-hq/riot-android#3396)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed May 13, 2020
1 parent 5bee2d6 commit b1c9731
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Improvements:

Bugfix:
- Fix issue with identity server (missing access token) (vector-im/riot-android#3404)
- Fix crash in MXCryptoImpl (vector-im/riot-android#3396)

API Change:
- RoomAccountdata.hasTags() has been deprecated. Use .hasRoomTags() instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.text.TextUtils;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -297,6 +298,10 @@ public MXCryptoImpl(@NonNull CryptoSession matrixSession,
myDevices.put(mMyDevice.deviceId, mMyDevice);

mCryptoStore.storeUserDevices(mSession.getMyUserId(), myDevices);

// Create the VerificationManager before setting the CryptoEventsListener, to avoid crash (vector-im/riot-android#3396)
mShortCodeVerificationManager = new VerificationManager(mSession);

mSession.getDataHandler().setCryptoEventsListener(mEventListener);

mEncryptingHandlerThread = new HandlerThread("MXCrypto_encrypting_" + mSession.getMyUserId(), Thread.MIN_PRIORITY);
Expand All @@ -318,7 +323,6 @@ public MXCryptoImpl(@NonNull CryptoSession matrixSession,
mReceivedRoomKeyRequests.addAll(mCryptoStore.getPendingIncomingRoomKeyRequests());

mKeysBackup = new KeysBackup(this, homeServerConnectionConfig);
mShortCodeVerificationManager = new VerificationManager(mSession);
}

/**
Expand Down Expand Up @@ -1610,7 +1614,10 @@ public Map<String, Map<String, String>> signObject(String strToSign) {
* @param event the event
*/
private void onToDeviceEvent(final CryptoEvent event) {
mShortCodeVerificationManager.onToDeviceEvent(event);
// It should not happen anymore
if (mShortCodeVerificationManager != null) {
mShortCodeVerificationManager.onToDeviceEvent(event);
}

if (TextUtils.equals(event.getType(), CryptoEvent.EVENT_TYPE_ROOM_KEY)
|| TextUtils.equals(event.getType(), CryptoEvent.EVENT_TYPE_FORWARDED_ROOM_KEY)) {
Expand Down

0 comments on commit b1c9731

Please sign in to comment.