I noticed, that the getInstanceFor(XMPPConnection) method of the OmemoManager is currently broken, which is quite annoying.
Until its fixed I'd suggest, that your client takes care of generating, storing and providing the deviceId of user accounts, since OmemoManager.getInstanceFor(XMPPConnection, deviceId) should work as intended. Calling getInstanceFor(XMPPConnection) should be avoided for now.
I think your method looks quite good to overcome the issue for now. I'll see if I can push a fix during the week.
I hope this helps you