118 lines
3.8 KiB
Java
118 lines
3.8 KiB
Java
package io.fabric.sdk.android.services.events;
|
|
|
|
import android.content.Context;
|
|
import io.fabric.sdk.android.services.common.CommonUtils;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.concurrent.RejectedExecutionException;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.ScheduledFuture;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public abstract class EnabledEventsStrategy<T> implements EventsStrategy<T> {
|
|
protected final Context a;
|
|
protected final EventsFilesManager<T> b;
|
|
final ScheduledExecutorService c;
|
|
volatile int e = -1;
|
|
final AtomicReference<ScheduledFuture<?>> d = new AtomicReference<>();
|
|
|
|
public EnabledEventsStrategy(Context context, ScheduledExecutorService scheduledExecutorService, EventsFilesManager<T> eventsFilesManager) {
|
|
this.a = context;
|
|
this.c = scheduledExecutorService;
|
|
this.b = eventsFilesManager;
|
|
}
|
|
|
|
@Override // io.fabric.sdk.android.services.events.EventsManager
|
|
public void a(T t) {
|
|
CommonUtils.b(this.a, t.toString());
|
|
try {
|
|
this.b.a((EventsFilesManager<T>) t);
|
|
} catch (IOException e) {
|
|
CommonUtils.a(this.a, "Failed to write event.", e);
|
|
}
|
|
e();
|
|
}
|
|
|
|
@Override // io.fabric.sdk.android.services.events.EventsManager
|
|
public void b() {
|
|
f();
|
|
}
|
|
|
|
@Override // io.fabric.sdk.android.services.events.FileRollOverManager
|
|
public boolean c() {
|
|
try {
|
|
return this.b.f();
|
|
} catch (IOException e) {
|
|
CommonUtils.a(this.a, "Failed to roll file over.", e);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@Override // io.fabric.sdk.android.services.events.FileRollOverManager
|
|
public void d() {
|
|
if (this.d.get() != null) {
|
|
CommonUtils.b(this.a, "Cancelling time-based rollover because no events are currently being generated.");
|
|
this.d.get().cancel(false);
|
|
this.d.set(null);
|
|
}
|
|
}
|
|
|
|
public void e() {
|
|
if (this.e != -1) {
|
|
a(this.e, this.e);
|
|
}
|
|
}
|
|
|
|
void f() {
|
|
FilesSender a = a();
|
|
if (a == null) {
|
|
CommonUtils.b(this.a, "skipping files send because we don't yet know the target endpoint");
|
|
return;
|
|
}
|
|
CommonUtils.b(this.a, "Sending all files");
|
|
List<File> c = this.b.c();
|
|
int i = 0;
|
|
while (c.size() > 0) {
|
|
try {
|
|
CommonUtils.b(this.a, String.format(Locale.US, "attempt to send batch of %d files", Integer.valueOf(c.size())));
|
|
boolean a2 = a.a(c);
|
|
if (a2) {
|
|
i += c.size();
|
|
this.b.a(c);
|
|
}
|
|
if (!a2) {
|
|
break;
|
|
} else {
|
|
c = this.b.c();
|
|
}
|
|
} catch (Exception e) {
|
|
CommonUtils.a(this.a, "Failed to send batch of analytics files to server: " + e.getMessage(), e);
|
|
}
|
|
}
|
|
if (i == 0) {
|
|
this.b.a();
|
|
}
|
|
}
|
|
|
|
protected void a(int i) {
|
|
this.e = i;
|
|
a(0L, this.e);
|
|
}
|
|
|
|
void a(long j, long j2) {
|
|
if (this.d.get() == null) {
|
|
TimeBasedFileRollOverRunnable timeBasedFileRollOverRunnable = new TimeBasedFileRollOverRunnable(this.a, this);
|
|
CommonUtils.b(this.a, "Scheduling time based file roll over every " + j2 + " seconds");
|
|
try {
|
|
this.d.set(this.c.scheduleAtFixedRate(timeBasedFileRollOverRunnable, j, j2, TimeUnit.SECONDS));
|
|
} catch (RejectedExecutionException e) {
|
|
CommonUtils.a(this.a, "Failed to schedule time based file roll over", e);
|
|
}
|
|
}
|
|
}
|
|
}
|