Please refer to the discussion on Smack OmemoManager.purgeDevices() throws NoResponseException prior to sending the stanza
aTalk with smack version 4.2.2 integrated still facing the same problem on slow android device e.g. Samsung SII. The reason is traced to the fact that it takes almost 90 seconds for omemoService to publish the 100 prekeys to the server on SII via PubSubManager#tryToPublishAndPossibleAutoCreate(deviceId, playLoad). On trying, I have to setReplyTimeout() to 120 seconds for the publish to work properly, but not practical in normal operation.
To overcome the problem I have included a patch in OmemoService#publishBundle() as attached i.e. to ignore the publish response timeout, so the OmemoManager can proceed to complete its omemo initialization upon user authentication. The Omemo prekeys publish process actually continues to completion in background. Not sure if the 90s long process time is because the publish process is executed in async mode after the smack timeout timer has started; as I see Smack throws response timeout even before the publish stanza is being send…
I have included this patch in the latest aTalk version 0.9.1 release. The patch is not a final solution, but at least Omemo message is now working on SII.
/**
* Publish a fresh bundle to the server.
*
* @param omemoManager OmemoManager
* @throws SmackException.NotConnectedException
* @throws InterruptedException
* @throws SmackException.NoResponseException
* @throws CorruptedOmemoKeyException
* @throws XMPPException.XMPPErrorException
*/
void publishBundle(OmemoManager omemoManager)
throws SmackException.NotConnectedException, InterruptedException,
SmackException.NoResponseException, CorruptedOmemoKeyException, XMPPException.XMPPErrorException {
Date lastSignedPreKeyRenewal = getOmemoStoreBackend().getDateOfLastSignedPreKeyRenewal(omemoManager);
if (OmemoConfiguration.getRenewOldSignedPreKeys() && lastSignedPreKeyRenewal != null) {
if (System.currentTimeMillis() - lastSignedPreKeyRenewal.getTime()
> 1000L * 60 * 60 * OmemoConfiguration.getRenewOldSignedPreKeysAfterHours()) {
LOGGER.log(Level.INFO, "Renewing signedPreKey");
getOmemoStoreBackend().changeSignedPreKey(omemoManager);
}
} else {
getOmemoStoreBackend().setDateOfLastSignedPreKeyRenewal(omemoManager);
}
// publish
// PubSubManager.getInstance(omemoManager.getConnection(), omemoManager.getOwnJid())
// .tryToPublishAndPossibleAutoCreate(OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(omemoManager.getDeviceId()),
// new PayloadItem<>(getOmemoStoreBackend().packOmemoBundle(omemoManager)));
PubSubManager pubSubMgr = PubSubManager.getInstance(omemoManager.getConnection(), omemoManager.getOwnJid());
String deviceId = OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(omemoManager.getDeviceId());
PayloadItem<OmemoBundleVAxolotlElement> playLoad = new PayloadItem<>(getOmemoStoreBackend().packOmemoBundle(omemoManager));
try {
pubSubMgr.tryToPublishAndPossibleAutoCreate(deviceId, playLoad);
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
LOGGER.log(Level.WARNING, "Ignore OmemoManager publish response timeout ~90S on SII"
+ e.getMessage());
}
}