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

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

/* JADX INFO: loaded from: classes2.dex */
public final class sa0 implements rj {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public long f16380c = -1;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public long f16381d = -1;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public Runnable f16382e = null;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public boolean f16383f = false;

    @Nullable
    private ScheduledFuture zzc;

    public sa0(ScheduledExecutorService scheduledExecutorService, i8.d dVar) {
        this.f16378a = scheduledExecutorService;
        this.f16379b = dVar;
        m7.n.C.f30468g.b(this);
    }

    @Override // com.google.android.gms.internal.ads.rj
    public final void G(boolean z10) {
        ScheduledFuture scheduledFuture;
        if (z10) {
            synchronized (this) {
                try {
                    if (this.f16383f) {
                        if (this.f16381d > 0 && (scheduledFuture = this.zzc) != null && scheduledFuture.isCancelled()) {
                            this.zzc = this.f16378a.schedule(this.f16382e, this.f16381d, TimeUnit.MILLISECONDS);
                        }
                        this.f16383f = false;
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
            return;
        }
        synchronized (this) {
            try {
                if (!this.f16383f) {
                    ScheduledFuture scheduledFuture2 = this.zzc;
                    if (scheduledFuture2 == null || scheduledFuture2.isDone()) {
                        this.f16381d = -1L;
                    } else {
                        this.zzc.cancel(true);
                        long j10 = this.f16380c;
                        ((i8.d) this.f16379b).getClass();
                        this.f16381d = j10 - SystemClock.elapsedRealtime();
                    }
                    this.f16383f = true;
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    public final synchronized void a(int i10, u81 u81Var) {
        this.f16382e = u81Var;
        ((i8.d) this.f16379b).getClass();
        long j10 = i10;
        this.f16380c = SystemClock.elapsedRealtime() + j10;
        this.zzc = this.f16378a.schedule(u81Var, j10, TimeUnit.MILLISECONDS);
    }
}
