Java Code Examples for org.whispersystems.libsignal.state.SignedPreKeyRecord#getTimestamp()

The following examples show how to use org.whispersystems.libsignal.state.SignedPreKeyRecord#getTimestamp() . 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: CleanPreKeysJob.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRun() throws IOException {
  try {
    Log.i(TAG, "Cleaning prekeys...");

    int                activeSignedPreKeyId = PreKeyUtil.getActiveSignedPreKeyId(context);
    SignedPreKeyStore  signedPreKeyStore    = new SignalProtocolStoreImpl(context);

    if (activeSignedPreKeyId < 0) return;

    SignedPreKeyRecord             currentRecord = signedPreKeyStore.loadSignedPreKey(activeSignedPreKeyId);
    List<SignedPreKeyRecord>       allRecords    = signedPreKeyStore.loadSignedPreKeys();
    LinkedList<SignedPreKeyRecord> oldRecords    = removeRecordFrom(currentRecord, allRecords);

    Collections.sort(oldRecords, new SignedPreKeySorter());

    Log.i(TAG, "Active signed prekey: " + activeSignedPreKeyId);
    Log.i(TAG, "Old signed prekey record count: " + oldRecords.size());

    boolean foundAgedRecord = false;

    for (SignedPreKeyRecord oldRecord : oldRecords) {
      long archiveDuration = System.currentTimeMillis() - oldRecord.getTimestamp();

      if (archiveDuration >= ARCHIVE_AGE) {
        if (!foundAgedRecord) {
          foundAgedRecord = true;
        } else {
          Log.i(TAG, "Removing signed prekey record: " + oldRecord.getId() + " with timestamp: " + oldRecord.getTimestamp());
          signedPreKeyStore.removeSignedPreKey(oldRecord.getId());
        }
      }
    }
  } catch (InvalidKeyIdException e) {
    Log.w(TAG, e);
  }
}
 
Example 2
Source File: CleanPreKeysJob.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRun(MasterSecret masterSecret) throws IOException {
    try {
        Log.w(TAG, "Cleaning prekeys...");

        int activeSignedPreKeyId = PreKeyUtil.getActiveSignedPreKeyId(context, accountContext);
        SignedPreKeyStore signedPreKeyStore = signedPreKeyStoreFactory.create();

        if (activeSignedPreKeyId < 0) return;

        SignedPreKeyRecord currentRecord = signedPreKeyStore.loadSignedPreKey(activeSignedPreKeyId);
        List<SignedPreKeyRecord> allRecords = signedPreKeyStore.loadSignedPreKeys();
        LinkedList<SignedPreKeyRecord> oldRecords = removeRecordFrom(currentRecord, allRecords);

        Collections.sort(oldRecords, new SignedPreKeySorter());

        Log.w(TAG, "Active signed prekey: " + activeSignedPreKeyId);
        Log.w(TAG, "Old signed prekey record count: " + oldRecords.size());

        boolean foundAgedRecord = false;

        for (SignedPreKeyRecord oldRecord : oldRecords) {
            long archiveDuration = System.currentTimeMillis() - oldRecord.getTimestamp();

            if (archiveDuration >= ARCHIVE_AGE) {
                if (!foundAgedRecord) {
                    foundAgedRecord = true;
                } else {
                    Log.w(TAG, "Removing signed prekey record: " + oldRecord.getId() + " with timestamp: " + oldRecord.getTimestamp());
                    signedPreKeyStore.removeSignedPreKey(oldRecord.getId());
                }
            }
        }
    } catch (InvalidKeyIdException e) {
        Log.w(TAG, e);
    }
}
 
Example 3
Source File: CleanPreKeysJob.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int compare(SignedPreKeyRecord lhs, SignedPreKeyRecord rhs) {
  if      (lhs.getTimestamp() > rhs.getTimestamp()) return -1;
  else if (lhs.getTimestamp() < rhs.getTimestamp()) return 1;
  else                                              return 0;
}
 
Example 4
Source File: CleanPreKeysJob.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int compare(SignedPreKeyRecord lhs, SignedPreKeyRecord rhs) {
    if (lhs.getTimestamp() > rhs.getTimestamp()) return -1;
    else if (lhs.getTimestamp() < rhs.getTimestamp()) return 1;
    else return 0;
}