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

55 lines
1.4 KiB
Java
Raw Normal View History

2021-05-15 20:03:05 +00:00
package com.bugsnag.android;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.File;
import java.util.Comparator;
import java.util.Locale;
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) {
super(new File(config.getPersistenceDirectory(), "bugsnag-sessions"),
config.getMaxPersistedSessions(),
SESSION_COMPARATOR,
logger,
delegate);
}
@NonNull
@Override
String getFilename(Object object) {
return String.format(Locale.US,
"%s%d_v2.json",
UUID.randomUUID().toString(),
System.currentTimeMillis());
}
}