Java Code Examples for org.whispersystems.libsignal.state.SessionStore#containsSession()

The following examples show how to use org.whispersystems.libsignal.state.SessionStore#containsSession() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IdentityUtil.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public static void saveIdentity(Context context, String user, IdentityKey identityKey) {
  synchronized (SESSION_LOCK) {
    IdentityKeyStore      identityKeyStore = new TextSecureIdentityKeyStore(context);
    SessionStore          sessionStore     = new TextSecureSessionStore(context);
    SignalProtocolAddress address          = new SignalProtocolAddress(user, 1);

    if (identityKeyStore.saveIdentity(address, identityKey)) {
      if (sessionStore.containsSession(address)) {
        SessionRecord sessionRecord = sessionStore.loadSession(address);
        sessionRecord.archiveCurrentState();

        sessionStore.storeSession(address, sessionRecord);
      }
    }
  }
}
 
Example 2
Source File: IdentityUtil.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public static void saveIdentity(Context context, AccountContext accountContext, String number, IdentityKey identityKey, boolean nonBlockingApproval) {
    synchronized (SESSION_LOCK) {
        TextSecureIdentityKeyStore identityKeyStore = new TextSecureIdentityKeyStore(context, accountContext);
        SessionStore sessionStore = new TextSecureSessionStore(context, accountContext);
        SignalProtocolAddress address = new SignalProtocolAddress(number, 1);

        if (identityKeyStore.saveIdentity(address, identityKey, nonBlockingApproval)) {
            if (sessionStore.containsSession(address)) {
                SessionRecord sessionRecord = sessionStore.loadSession(address);
                sessionRecord.archiveCurrentState();

                sessionStore.storeSession(address, sessionRecord);
            }
        }
    }
}
 
Example 3
Source File: IdentityUtil.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public static void saveIdentity(Context context, AccountContext accountContext, String number, IdentityKey identityKey) {
    synchronized (SESSION_LOCK) {
        IdentityKeyStore identityKeyStore = new TextSecureIdentityKeyStore(context, accountContext);
        SessionStore sessionStore = new TextSecureSessionStore(context, accountContext);
        SignalProtocolAddress address = new SignalProtocolAddress(number, 1);

        if (identityKeyStore.saveIdentity(address, identityKey)) {
            if (sessionStore.containsSession(address)) {
                SessionRecord sessionRecord = sessionStore.loadSession(address);
                sessionRecord.archiveCurrentState();

                sessionStore.storeSession(address, sessionRecord);
            }
        }
    }
}
 
Example 4
Source File: SessionUtil.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public static void archiveSiblingSessions(Context context, AccountContext accountContext, SignalProtocolAddress address) {
    SessionStore sessionStore = new TextSecureSessionStore(context, accountContext);
    List<Integer> devices = sessionStore.getSubDeviceSessions(address.getName());
    devices.add(1);

    for (int device : devices) {
        if (device != address.getDeviceId()) {
            SignalProtocolAddress sibling = new SignalProtocolAddress(address.getName(), device);

            if (sessionStore.containsSession(sibling)) {
                SessionRecord sessionRecord = sessionStore.loadSession(sibling);
                sessionRecord.archiveCurrentState();
                sessionStore.storeSession(sibling, sessionRecord);
            }
        }
    }
}
 
Example 5
Source File: SessionUtil.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public static boolean hasSession(@NonNull Context context, @NonNull RecipientId id) {
  SessionStore          sessionStore   = new TextSecureSessionStore(context);
  SignalProtocolAddress axolotlAddress = new SignalProtocolAddress(Recipient.resolved(id).requireServiceId(), SignalServiceAddress.DEFAULT_DEVICE_ID);

  return sessionStore.containsSession(axolotlAddress);
}
 
Example 6
Source File: SessionUtil.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
public static boolean hasSession(Context context, MasterSecret masterSecret, @NonNull Address address) {
    SessionStore sessionStore = new TextSecureSessionStore(context, address.context(), masterSecret);
    SignalProtocolAddress axolotlAddress = new SignalProtocolAddress(address.serialize(), SignalServiceAddress.DEFAULT_DEVICE_ID);

    return sessionStore.containsSession(axolotlAddress);
}
 
Example 7
Source File: SessionUtil.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
public static boolean hasSession(Context context, MasterSecret masterSecret, @NonNull String number, int subscriptionId) {
  SessionStore   sessionStore   = new SilenceSessionStore(context, masterSecret, subscriptionId);
  SignalProtocolAddress axolotlAddress = new SignalProtocolAddress(number, 1);

  return sessionStore.containsSession(axolotlAddress);
}