package m4;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/* JADX INFO: loaded from: classes3.dex */
public final class A0 {

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public static final long f20555k = TimeUnit.SECONDS.toNanos(10);

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final ScheduledExecutorService f20556a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final E3.p f20557b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final l2.c f20558c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f20559d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public ScheduledFuture f20560e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public ScheduledFuture f20561f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final B0 f20562g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final B0 f20563h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final long f20564i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final long f20565j;

    static {
        TimeUnit.MILLISECONDS.toNanos(10L);
    }

    public A0(l2.c cVar, ScheduledExecutorService scheduledExecutorService, long j4, long j6) {
        E3.p pVar = new E3.p(0);
        this.f20559d = 1;
        this.f20562g = new B0(new RunnableC2560y0(this, 0));
        this.f20563h = new B0(new RunnableC2560y0(this, 1));
        this.f20558c = cVar;
        A4.g.o(scheduledExecutorService, "scheduler");
        this.f20556a = scheduledExecutorService;
        this.f20557b = pVar;
        this.f20564i = j4;
        this.f20565j = j6;
        pVar.f1167b = false;
        pVar.c();
    }

    public final synchronized void a() {
        try {
            E3.p pVar = this.f20557b;
            pVar.f1167b = false;
            pVar.c();
            int i6 = this.f20559d;
            if (i6 == 2) {
                this.f20559d = 3;
            } else if (i6 == 4 || i6 == 5) {
                ScheduledFuture scheduledFuture = this.f20560e;
                if (scheduledFuture != null) {
                    scheduledFuture.cancel(false);
                }
                if (this.f20559d == 5) {
                    this.f20559d = 1;
                } else {
                    this.f20559d = 2;
                    A4.g.t(this.f20561f == null, "There should be no outstanding pingFuture");
                    this.f20561f = this.f20556a.schedule(this.f20563h, this.f20564i, TimeUnit.NANOSECONDS);
                }
            }
        } catch (Throwable th) {
            throw th;
        }
    }

    public final synchronized void b() {
        try {
            int i6 = this.f20559d;
            if (i6 == 1) {
                this.f20559d = 2;
                if (this.f20561f == null) {
                    ScheduledExecutorService scheduledExecutorService = this.f20556a;
                    B0 b02 = this.f20563h;
                    long j4 = this.f20564i;
                    E3.p pVar = this.f20557b;
                    this.f20561f = scheduledExecutorService.schedule(b02, j4 - pVar.b(), TimeUnit.NANOSECONDS);
                }
            } else if (i6 == 5) {
                this.f20559d = 4;
            }
        } catch (Throwable th) {
            throw th;
        }
    }
}
