AnsweredAssumed Answered

Smack OMEMO Support

Question asked by cmeng on Jun 18, 2017
Latest reply on Jul 8, 2017 by cmeng

Start implementing OMEMO for aTalk, needs some advice on the following:

 

During aTalk OMEMO implementation, found that the following method;

OmemoManager getInstanceFor(XMPPConnection connection);

has to be called when XMPPConnection is connected i.e. callback connected(XMPPConnection connection) and not when authenticated(XMPPConnection connection, boolean resumed)

 

 

In the above getInstanceFor() method, it needs to retrieve the BareJid user; However in aTalk implementation, the connection and login occurs in two different processes, and user is not defined during connection process. Moving the execution of the above method when user is authenticated has conflict with OmemoManager#initialize() where it is also being called during authenticated();

 

Currently to overcome the above limitation, I have to create a private method as below:

private OmemoManager initOMemoManager(ProtocolProviderService pps) {
   BareJid user;
   XMPPTCPConnection connection = pps.getConnection();

   if (connection.getUser() != null) {
   user = connection.getUser().asBareJid();
   } else {
   user = pps.getAccountID().getFullJid().asBareJid();
   }

   int defaultDeviceId = OmemoService.getInstance().getOmemoStoreBackend().getDefaultDeviceId(user);

   if (defaultDeviceId < 1) {
   defaultDeviceId = OmemoManager.randomDeviceId();
   OmemoService.getInstance().getOmemoStoreBackend().setDefaultDeviceId(user, defaultDeviceId);
   }

   return OmemoManager.getInstanceFor(connection, defaultDeviceId);
}

 

Is there other alternative to overcome the problem instead of the above private method approach.

Outcomes