jimu-decompiled/sources/io/fabric/sdk/android/services/events/EventsFilesManager.java
2025-05-13 19:24:51 +02:00

150 lines
4.6 KiB
Java

package io.fabric.sdk.android.services.events;
import android.content.Context;
import io.fabric.sdk.android.services.common.CommonUtils;
import io.fabric.sdk.android.services.common.CurrentTimeProvider;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.TreeSet;
import java.util.concurrent.CopyOnWriteArrayList;
/* loaded from: classes2.dex */
public abstract class EventsFilesManager<T> {
protected final Context a;
protected final EventTransform<T> b;
protected final CurrentTimeProvider c;
protected final EventsStorage d;
private final int e;
protected final List<EventsStorageListener> f = new CopyOnWriteArrayList();
static class FileWithTimestamp {
final File a;
final long b;
public FileWithTimestamp(File file, long j) {
this.a = file;
this.b = j;
}
}
public EventsFilesManager(Context context, EventTransform<T> eventTransform, CurrentTimeProvider currentTimeProvider, EventsStorage eventsStorage, int i) throws IOException {
this.a = context.getApplicationContext();
this.b = eventTransform;
this.d = eventsStorage;
this.c = currentTimeProvider;
this.c.a();
this.e = i;
}
private void b(String str) {
Iterator<EventsStorageListener> it = this.f.iterator();
while (it.hasNext()) {
try {
it.next().a(str);
} catch (Exception e) {
CommonUtils.a(this.a, "One of the roll over listeners threw an exception", e);
}
}
}
public void a(T t) throws IOException {
byte[] a = this.b.a(t);
a(a.length);
this.d.a(a);
}
protected abstract String b();
public List<File> c() {
return this.d.a(1);
}
protected int d() {
return 8000;
}
protected int e() {
return this.e;
}
public boolean f() throws IOException {
String str;
boolean z = true;
if (this.d.b()) {
str = null;
z = false;
} else {
str = b();
this.d.a(str);
CommonUtils.a(this.a, 4, "Fabric", String.format(Locale.US, "generated new file %s", str));
this.c.a();
}
b(str);
return z;
}
public void a(EventsStorageListener eventsStorageListener) {
if (eventsStorageListener != null) {
this.f.add(eventsStorageListener);
}
}
private void a(int i) throws IOException {
if (this.d.a(i, d())) {
return;
}
CommonUtils.a(this.a, 4, "Fabric", String.format(Locale.US, "session analytics events file is %d bytes, new event is %d bytes, this is over flush limit of %d, rolling it over", Integer.valueOf(this.d.a()), Integer.valueOf(i), Integer.valueOf(d())));
f();
}
public void a(List<File> list) {
this.d.a(list);
}
public void a() {
List<File> c = this.d.c();
int e = e();
if (c.size() <= e) {
return;
}
int size = c.size() - e;
CommonUtils.b(this.a, String.format(Locale.US, "Found %d files in roll over directory, this is greater than %d, deleting %d oldest files", Integer.valueOf(c.size()), Integer.valueOf(e), Integer.valueOf(size)));
TreeSet treeSet = new TreeSet(new Comparator<FileWithTimestamp>(this) { // from class: io.fabric.sdk.android.services.events.EventsFilesManager.1
@Override // java.util.Comparator
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public int compare(FileWithTimestamp fileWithTimestamp, FileWithTimestamp fileWithTimestamp2) {
return (int) (fileWithTimestamp.b - fileWithTimestamp2.b);
}
});
for (File file : c) {
treeSet.add(new FileWithTimestamp(file, a(file.getName())));
}
ArrayList arrayList = new ArrayList();
Iterator it = treeSet.iterator();
while (it.hasNext()) {
arrayList.add(((FileWithTimestamp) it.next()).a);
if (arrayList.size() == size) {
break;
}
}
this.d.a(arrayList);
}
public long a(String str) {
String[] split = str.split("_");
if (split.length != 3) {
return 0L;
}
try {
return Long.valueOf(split[2]).longValue();
} catch (NumberFormatException unused) {
return 0L;
}
}
}