private void fillMap(SQLiteAxolotlStore store) {
   List<Integer> deviceIds = store.getSubDeviceSessions(account.getJid().toBareJid().toString());
   putDevicesForJid(account.getJid().toBareJid().toString(), deviceIds, store);
   for (Contact contact : account.getRoster().getContacts()) {
     Jid bareJid = contact.getJid().toBareJid();
     if (bareJid == null) {
       continue; // FIXME: handle this?
     }
     String address = bareJid.toString();
     deviceIds = store.getSubDeviceSessions(address);
     putDevicesForJid(address, deviceIds, store);
   }
 }
 public void regenerateKeys() {
   axolotlStore.regenerate();
   sessions.clear();
   fetchStatusMap.clear();
   publishBundlesIfNeeded();
   publishOwnDeviceIdIfNeeded();
 }
 private XmppAxolotlSession recreateUncachedSession(AxolotlAddress address) {
   IdentityKey identityKey =
       axolotlStore.loadSession(address).getSessionState().getRemoteIdentityKey();
   return (identityKey != null)
       ? new XmppAxolotlSession(
           account, axolotlStore, address, identityKey.getFingerprint().replaceAll("\\s", ""))
       : null;
 }
 public void registerDevices(final Jid jid, @NonNull final Set<Integer> deviceIds) {
   if (jid.toBareJid().equals(account.getJid().toBareJid())) {
     if (deviceIds.contains(getOwnDeviceId())) {
       deviceIds.remove(getOwnDeviceId());
     }
     for (Integer deviceId : deviceIds) {
       AxolotlAddress ownDeviceAddress = new AxolotlAddress(jid.toBareJid().toString(), deviceId);
       if (sessions.get(ownDeviceAddress) == null) {
         buildSessionFromPEP(ownDeviceAddress);
       }
     }
   }
   Set<Integer> expiredDevices =
       new HashSet<>(axolotlStore.getSubDeviceSessions(jid.toBareJid().toString()));
   expiredDevices.removeAll(deviceIds);
   setTrustOnSessions(
       jid,
       expiredDevices,
       XmppAxolotlSession.Trust.TRUSTED,
       XmppAxolotlSession.Trust.INACTIVE_TRUSTED);
   setTrustOnSessions(
       jid,
       expiredDevices,
       XmppAxolotlSession.Trust.UNDECIDED,
       XmppAxolotlSession.Trust.INACTIVE_UNDECIDED);
   setTrustOnSessions(
       jid,
       expiredDevices,
       XmppAxolotlSession.Trust.UNTRUSTED,
       XmppAxolotlSession.Trust.INACTIVE_UNTRUSTED);
   Set<Integer> newDevices = new HashSet<>(deviceIds);
   setTrustOnSessions(
       jid,
       newDevices,
       XmppAxolotlSession.Trust.INACTIVE_TRUSTED,
       XmppAxolotlSession.Trust.TRUSTED);
   setTrustOnSessions(
       jid,
       newDevices,
       XmppAxolotlSession.Trust.INACTIVE_UNDECIDED,
       XmppAxolotlSession.Trust.UNDECIDED);
   setTrustOnSessions(
       jid,
       newDevices,
       XmppAxolotlSession.Trust.INACTIVE_UNTRUSTED,
       XmppAxolotlSession.Trust.UNTRUSTED);
   this.deviceIds.put(jid, deviceIds);
   mXmppConnectionService.keyStatusUpdated();
   publishOwnDeviceIdIfNeeded();
 }
 private void putDevicesForJid(
     String bareJid, List<Integer> deviceIds, SQLiteAxolotlStore store) {
   for (Integer deviceId : deviceIds) {
     AxolotlAddress axolotlAddress = new AxolotlAddress(bareJid, deviceId);
     Log.d(
         Config.LOGTAG,
         AxolotlService.getLogprefix(account)
             + "Building session for remote address: "
             + axolotlAddress.toString());
     String fingerprint =
         store
             .loadSession(axolotlAddress)
             .getSessionState()
             .getRemoteIdentityKey()
             .getFingerprint()
             .replaceAll("\\s", "");
     this.put(
         axolotlAddress, new XmppAxolotlSession(account, store, axolotlAddress, fingerprint));
   }
 }
  public Set<AxolotlAddress> findDevicesWithoutSession(final Conversation conversation) {
    Log.d(
        Config.LOGTAG,
        AxolotlService.getLogprefix(account)
            + "Finding devices without session for "
            + conversation.getContact().getJid().toBareJid());
    Jid contactJid = conversation.getContact().getJid().toBareJid();
    Set<AxolotlAddress> addresses = new HashSet<>();
    if (deviceIds.get(contactJid) != null) {
      for (Integer foreignId : this.deviceIds.get(contactJid)) {
        AxolotlAddress address = new AxolotlAddress(contactJid.toString(), foreignId);
        if (sessions.get(address) == null) {
          IdentityKey identityKey =
              axolotlStore.loadSession(address).getSessionState().getRemoteIdentityKey();
          if (identityKey != null) {
            Log.d(
                Config.LOGTAG,
                AxolotlService.getLogprefix(account)
                    + "Already have session for "
                    + address.toString()
                    + ", adding to cache...");
            XmppAxolotlSession session =
                new XmppAxolotlSession(
                    account,
                    axolotlStore,
                    address,
                    identityKey.getFingerprint().replaceAll("\\s", ""));
            sessions.put(address, session);
          } else {
            Log.d(
                Config.LOGTAG,
                AxolotlService.getLogprefix(account)
                    + "Found device "
                    + account.getJid().toBareJid()
                    + ":"
                    + foreignId);
            addresses.add(new AxolotlAddress(contactJid.toString(), foreignId));
          }
        }
      }
    } else {
      Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Have no target devices in PEP!");
    }
    if (deviceIds.get(account.getJid().toBareJid()) != null) {
      for (Integer ownId : this.deviceIds.get(account.getJid().toBareJid())) {
        AxolotlAddress address = new AxolotlAddress(account.getJid().toBareJid().toString(), ownId);
        if (sessions.get(address) == null) {
          IdentityKey identityKey =
              axolotlStore.loadSession(address).getSessionState().getRemoteIdentityKey();
          if (identityKey != null) {
            Log.d(
                Config.LOGTAG,
                AxolotlService.getLogprefix(account)
                    + "Already have session for "
                    + address.toString()
                    + ", adding to cache...");
            XmppAxolotlSession session =
                new XmppAxolotlSession(
                    account,
                    axolotlStore,
                    address,
                    identityKey.getFingerprint().replaceAll("\\s", ""));
            sessions.put(address, session);
          } else {
            Log.d(
                Config.LOGTAG,
                AxolotlService.getLogprefix(account)
                    + "Found device "
                    + account.getJid().toBareJid()
                    + ":"
                    + ownId);
            addresses.add(new AxolotlAddress(account.getJid().toBareJid().toString(), ownId));
          }
        }
      }
    }

    return addresses;
  }
 public void setFingerprintTrust(String fingerprint, XmppAxolotlSession.Trust trust) {
   axolotlStore.setFingerprintTrust(fingerprint, trust);
 }
 public XmppAxolotlSession.Trust getFingerprintTrust(String fingerprint) {
   return axolotlStore.getFingerprintTrust(fingerprint);
 }
 public void purgeKey(IdentityKey identityKey) {
   axolotlStore.setFingerprintTrust(
       identityKey.getFingerprint().replaceAll("\\s", ""), XmppAxolotlSession.Trust.COMPROMISED);
 }
 public int getOwnDeviceId() {
   return axolotlStore.getLocalRegistrationId();
 }
 public long getNumTrustedKeys(Contact contact) {
   return axolotlStore.getContactNumTrustedKeys(contact.getJid().toBareJid().toString());
 }
 public Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust, Contact contact) {
   return axolotlStore.getContactKeysWithTrust(contact.getJid().toBareJid().toString(), trust);
 }
 public IdentityKey getOwnPublicKey() {
   return axolotlStore.getIdentityKeyPair().getPublicKey();
 }