During muc OmemoMessage.Sent encrypt process, OmemoServie included its ownDevice in the devices list for TrustState checking. It also incorrectly uses loadOmemoIdentityKey(userDevice, contactsDevice) to fetch identityKeyPairs, leading to CorruptedOmemoKeyException being thrown and always get included in the undecidedDevices and return to upstream app.
With reference to OmemoMessage.Sent#encrypt method:
On further investigation, I found that the loadCachedDeviceList() is being called twice for ownDevice. This leads to two copies of ownDevice get included in contactsDevices.
removeOurDevice(userDevice, contactsDevices) removes only one of the two, hence gives rise to the observed problem.
I did a simple path as below to allow aTalk continue testing
/**
* Remove our device from the collection of devices.
*
* @param userDevice our OmemoDevice
* @param devices collection of OmemoDevices
*/
static void removeOurDevice(OmemoDevice userDevice, Collection<OmemoDevice> devices) {
while (devices.contains(userDevice)) {
devices.remove(userDevice);
}
}