void buildFreshSessionWithDevice ( XMPPConnection connection , OmemoDevice userDevice , OmemoDevice contactsDevice ) throws CannotEstablishOmemoSessionException , SmackException . NotConnectedException , InterruptedException , SmackException . NoResponseException , CorruptedOmemoKeyException { if ( contactsDevice . equals ( userDevice ) ) { // Do not build a session with yourself. return ; } OmemoBundleElement bundleElement ; try { bundleElement = fetchBundle ( connection , contactsDevice ) ; } catch ( XMPPException . XMPPErrorException | PubSubException . NotALeafNodeException | PubSubException . NotAPubSubNodeException e ) { throw new CannotEstablishOmemoSessionException ( contactsDevice , e ) ; } // Select random Bundle HashMap < Integer , T_Bundle > bundlesList = getOmemoStoreBackend ( ) . keyUtil ( ) . BUNDLE . bundles ( bundleElement , contactsDevice ) ; int randomIndex = new Random ( ) . nextInt ( bundlesList . size ( ) ) ; T_Bundle randomPreKeyBundle = new ArrayList <> ( bundlesList . values ( ) ) . get ( randomIndex ) ; // build the session OmemoManager omemoManager = OmemoManager . getInstanceFor ( connection , userDevice . getDeviceId ( ) ) ; processBundle ( omemoManager , randomPreKeyBundle , contactsDevice ) ; }
Fetch the bundle of a contact and build a fresh OMEMO session with the contacts device . Note that this builds a fresh session regardless if we have had a session before or not .