discord-jadx/app/src/main/java/c/m/a/g/d/i.java
2021-07-13 22:23:20 +02:00

164 lines
5.2 KiB
Java

package c.m.a.g.d;
import c.m.a.d;
import c.m.a.e;
import c.m.a.g.d.e;
import com.lyft.kronos.internal.ntp.NTPSyncException;
import d0.z.d.m;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
/* compiled from: SntpService.kt */
public final class i implements h {
public final AtomicReference<a> a = new AtomicReference<>(a.INIT);
public final AtomicLong b = new AtomicLong(0);
/* renamed from: c reason: collision with root package name */
public final ExecutorService f1467c = Executors.newSingleThreadExecutor(b.i);
public final e d;
public final c.m.a.b e;
public final f f;
public final e g;
public final List<String> h;
public final long i;
public final long j;
public final long k;
/* compiled from: SntpService.kt */
public enum a {
INIT,
IDLE,
SYNCING,
STOPPED
}
/* compiled from: SntpService.kt */
public static final class b implements ThreadFactory {
public static final b i = new b();
@Override // java.util.concurrent.ThreadFactory
public final Thread newThread(Runnable runnable) {
return new Thread(runnable, "kronos-android");
}
}
/* compiled from: SntpService.kt */
public static final class c implements Runnable {
public final /* synthetic */ i i;
public c(i iVar) {
this.i = iVar;
}
@Override // java.lang.Runnable
public final void run() {
boolean z2;
i iVar = this.i;
iVar.c();
Iterator<String> it = iVar.h.iterator();
do {
z2 = false;
if (it.hasNext()) {
String next = it.next();
a aVar = a.IDLE;
AtomicReference<a> atomicReference = iVar.a;
a aVar2 = a.SYNCING;
if (atomicReference.getAndSet(aVar2) != aVar2) {
long b = iVar.e.b();
e eVar = iVar.g;
if (eVar != null) {
eVar.a(next);
}
try {
e.b d = iVar.d.d(next, Long.valueOf(iVar.i));
m.checkExpressionValueIsNotNull(d, "response");
if (d.a() >= 0) {
iVar.f.a(d);
long j = d.f1466c;
long b2 = iVar.e.b() - b;
c.m.a.e eVar2 = iVar.g;
if (eVar2 != null) {
eVar2.b(j, b2);
}
iVar.a.set(aVar);
iVar.b.set(iVar.e.b());
z2 = true;
continue;
} else {
throw new NTPSyncException("Invalid time " + d.a() + " received from " + next);
}
} catch (Throwable th) {
iVar.a.set(aVar);
iVar.b.set(iVar.e.b());
throw th;
}
}
} else {
return;
}
} while (!z2);
}
}
public i(e eVar, c.m.a.b bVar, f fVar, c.m.a.e eVar2, List<String> list, long j, long j2, long j3) {
m.checkParameterIsNotNull(eVar, "sntpClient");
m.checkParameterIsNotNull(bVar, "deviceClock");
m.checkParameterIsNotNull(fVar, "responseCache");
m.checkParameterIsNotNull(list, "ntpHosts");
this.d = eVar;
this.e = bVar;
this.f = fVar;
this.g = eVar2;
this.h = list;
this.i = j;
this.j = j2;
this.k = j3;
}
/* JADX WARNING: Code restructure failed: missing block: B:7:0x0039, code lost:
if ((java.lang.Math.abs((r0.a - r0.b) - (r0.d.a() - r0.d.b())) < 1000) == false) goto L_0x003d;
*/
@Override // c.m.a.g.d.h
public d a() {
c();
e.b bVar = this.f.get();
boolean z2 = true;
if (this.a.compareAndSet(a.INIT, a.IDLE) && bVar != null) {
}
z2 = false;
if (z2) {
this.f.clear();
bVar = null;
}
if (bVar == null) {
if (this.e.b() - this.b.get() >= this.j) {
b();
}
return null;
}
long b2 = bVar.d.b() - bVar.b;
if (b2 >= this.k && this.e.b() - this.b.get() >= this.j) {
b();
}
return new d(bVar.a(), Long.valueOf(b2));
}
@Override // c.m.a.g.d.h
public void b() {
c();
if (this.a.get() != a.SYNCING) {
this.f1467c.submit(new c(this));
}
}
public final void c() {
if (this.a.get() == a.STOPPED) {
throw new IllegalStateException("Service already shutdown");
}
}
}