package com.google.android.gms.internal.ads;

import android.os.SystemClock;
import androidx.annotation.Nullable;
import java.util.Collections;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/* JADX INFO: loaded from: classes2.dex */
public final class bh0 extends rc2 {

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final cr0 f9531d;

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public long f9534g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public long f9535h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public boolean f9536i;

    @Nullable
    private ScheduledFuture zzj;

    @Nullable
    private ScheduledFuture zzk;

    public bh0(ScheduledExecutorService scheduledExecutorService, i8.c cVar, cr0 cr0Var) {
        super(Collections.emptySet());
        this.f9532e = -1L;
        this.f9533f = -1L;
        this.f9534g = -1L;
        this.f9535h = -1L;
        this.f9536i = false;
        this.f9529b = scheduledExecutorService;
        this.f9530c = cVar;
        this.f9531d = cr0Var;
    }

    public final synchronized void I0() {
        ScheduledFuture scheduledFuture;
        ScheduledFuture scheduledFuture2;
        try {
            if (this.f9536i) {
                if (this.f9534g > 0 && (scheduledFuture2 = this.zzj) != null && scheduledFuture2.isCancelled()) {
                    L0(this.f9534g);
                }
                if (this.f9535h > 0 && (scheduledFuture = this.zzk) != null && scheduledFuture.isCancelled()) {
                    M0(this.f9535h);
                }
                this.f9536i = false;
            }
        } catch (Throwable th) {
            throw th;
        }
    }

    public final synchronized void J0(int i10) {
        StringBuilder sb = new StringBuilder(String.valueOf(i10).length() + 20);
        sb.append("In scheduleRefresh: ");
        sb.append(i10);
        p7.l0.g(sb.toString());
        if (i10 > 0) {
            long millis = TimeUnit.SECONDS.toMillis(i10);
            if (this.f9536i) {
                long j10 = this.f9534g;
                if (j10 <= 0 || millis >= j10) {
                    millis = j10;
                }
                this.f9534g = millis;
                return;
            }
            ((i8.d) this.f9530c).getClass();
            long jElapsedRealtime = SystemClock.elapsedRealtime();
            tn tnVar = ao.f9158xe;
            n7.y yVar = n7.y.f31093e;
            if (((Boolean) yVar.f31096c.b(tnVar)).booleanValue()) {
                long j11 = this.f9532e;
                if (jElapsedRealtime >= j11 || j11 - jElapsedRealtime > millis) {
                    L0(millis);
                    if (((Boolean) yVar.f31096c.b(ao.Ue)).booleanValue()) {
                        br0 br0VarA = this.f9531d.a();
                        br0VarA.zzc("action", "rtnc");
                        br0VarA.d();
                    }
                }
            } else {
                long j12 = this.f9532e;
                if (jElapsedRealtime > j12 || j12 - jElapsedRealtime > millis) {
                    L0(millis);
                }
            }
        }
    }

    public final synchronized void K0(int i10) {
        StringBuilder sb = new StringBuilder(String.valueOf(i10).length() + 28);
        sb.append("In scheduleShowRefreshedAd: ");
        sb.append(i10);
        p7.l0.g(sb.toString());
        if (i10 > 0) {
            long millis = TimeUnit.SECONDS.toMillis(i10);
            if (this.f9536i) {
                long j10 = this.f9535h;
                if (j10 <= 0 || millis >= j10) {
                    millis = j10;
                }
                this.f9535h = millis;
                return;
            }
            ((i8.d) this.f9530c).getClass();
            long jElapsedRealtime = SystemClock.elapsedRealtime();
            if (((Boolean) n7.y.f31093e.f31096c.b(ao.f9158xe)).booleanValue()) {
                if (jElapsedRealtime == this.f9533f) {
                    p7.l0.g("In scheduleShowRefreshedAd: currentTimeMs = scheduledShowTimeMs");
                }
                long j11 = this.f9533f;
                if (jElapsedRealtime >= j11 || j11 - jElapsedRealtime > millis) {
                    M0(millis);
                }
            } else {
                long j12 = this.f9533f;
                if (jElapsedRealtime > j12 || j12 - jElapsedRealtime > millis) {
                    M0(millis);
                }
            }
        }
    }

    public final synchronized void L0(long j10) {
        try {
            ScheduledFuture scheduledFuture = this.zzj;
            int i10 = 0;
            if (scheduledFuture != null && !scheduledFuture.isDone()) {
                this.zzj.cancel(false);
            }
            ((i8.d) this.f9530c).getClass();
            this.f9532e = SystemClock.elapsedRealtime() + j10;
            this.zzj = this.f9529b.schedule(new ah0(this, i10), j10, TimeUnit.MILLISECONDS);
        } catch (Throwable th) {
            throw th;
        }
    }

    public final synchronized void M0(long j10) {
        try {
            ScheduledFuture scheduledFuture = this.zzk;
            if (scheduledFuture != null && !scheduledFuture.isDone()) {
                this.zzk.cancel(false);
            }
            ((i8.d) this.f9530c).getClass();
            this.f9533f = SystemClock.elapsedRealtime() + j10;
            this.zzk = this.f9529b.schedule(new ah0(this, 1), j10, TimeUnit.MILLISECONDS);
        } catch (Throwable th) {
            throw th;
        }
    }

    public final synchronized void zza() {
        try {
            if (this.f9536i) {
                return;
            }
            ScheduledFuture scheduledFuture = this.zzj;
            if (scheduledFuture == null || scheduledFuture.isCancelled()) {
                this.f9534g = -1L;
            } else {
                this.zzj.cancel(false);
                long j10 = this.f9532e;
                ((i8.d) this.f9530c).getClass();
                this.f9534g = j10 - SystemClock.elapsedRealtime();
            }
            ScheduledFuture scheduledFuture2 = this.zzk;
            if (scheduledFuture2 == null || scheduledFuture2.isCancelled()) {
                this.f9535h = -1L;
            } else {
                this.zzk.cancel(false);
                long j11 = this.f9533f;
                ((i8.d) this.f9530c).getClass();
                this.f9535h = j11 - SystemClock.elapsedRealtime();
            }
            this.f9536i = true;
        } catch (Throwable th) {
            throw th;
        }
    }

    public final synchronized void zzc() {
        this.f9536i = false;
        L0(0L);
    }
}
