FairEmail/app/src/main/java/com/bugsnag/android/SessionStore.java

64 lines
1.8 KiB
Java
Raw Normal View History

2021-05-15 20:03:05 +00:00
package com.bugsnag.android;
2021-07-29 19:08:19 +00:00
import com.bugsnag.android.internal.ImmutableConfig;
2021-05-15 20:03:05 +00:00
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.File;
2022-06-23 18:23:15 +00:00
import java.util.Calendar;
2021-05-15 20:03:05 +00:00
import java.util.Comparator;
2022-06-23 18:23:15 +00:00
import java.util.Date;
2021-05-15 20:03:05 +00:00
import java.util.UUID;
/**
* Store and flush Sessions which couldn't be sent immediately due to
* lack of network connectivity.
*/
class SessionStore extends FileStore {
static final Comparator<File> SESSION_COMPARATOR = new Comparator<File>() {
@Override
public int compare(File lhs, File rhs) {
if (lhs == null && rhs == null) {
return 0;
}
if (lhs == null) {
return 1;
}
if (rhs == null) {
return -1;
}
String lhsName = lhs.getName();
String rhsName = rhs.getName();
return lhsName.compareTo(rhsName);
}
};
SessionStore(@NonNull ImmutableConfig config,
@NonNull Logger logger,
@Nullable Delegate delegate) {
2021-08-15 12:40:22 +00:00
super(new File(config.getPersistenceDirectory().getValue(), "bugsnag-sessions"),
2021-05-15 20:03:05 +00:00
config.getMaxPersistedSessions(),
SESSION_COMPARATOR,
logger,
delegate);
}
@NonNull
@Override
String getFilename(Object object) {
2022-06-23 18:23:15 +00:00
return SessionFilenameInfo.defaultFilename();
2021-05-15 20:03:05 +00:00
}
2022-06-23 18:23:15 +00:00
public boolean isTooOld(File file) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -60);
return SessionFilenameInfo.findTimestampInFilename(file) < cal.getTimeInMillis();
}
public Date getCreationDate(File file) {
return new Date(SessionFilenameInfo.findTimestampInFilename(file));
}
2021-05-15 20:03:05 +00:00
}