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

import android.content.Context;
import androidx.annotation.Nullable;

/* JADX INFO: loaded from: classes2.dex */
public final class dv {

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final String f10530c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final q7.a f10531d;

    @Nullable
    private final nd1 zze;

    @Nullable
    private cv zzh;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Object f10528a = new Object();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f10532e = 1;

    public dv(Context context, q7.a aVar, String str, p7.p pVar, p7.p pVar2, @Nullable nd1 nd1Var) {
        this.f10530c = str;
        this.f10529b = context.getApplicationContext();
        this.f10531d = aVar;
        this.zze = nd1Var;
    }

    public final void a() {
        cv cvVar = this.zzh;
        if (cvVar != null) {
            cvVar.r();
            this.zzh = null;
        }
    }

    public final /* synthetic */ nd1 b() {
        return this.zze;
    }

    public final /* synthetic */ cv c() {
        return this.zzh;
    }

    public final /* synthetic */ void d(cv cvVar) {
        this.zzh = cvVar;
    }

    public final cv zza(@Nullable tg tgVar) {
        id1 id1VarD = id1.d(this.f10529b, 6);
        id1VarD.zza();
        cv cvVar = new cv();
        p7.l0.g("loadJavascriptEngine > Before UI_THREAD_EXECUTOR");
        b30.f9364f.execute(new bv(this, cvVar));
        p7.l0.g("loadNewJavascriptEngine: Promise created");
        cvVar.l(new yu(this, cvVar, id1VarD, 0), new yu(this, cvVar, id1VarD, 1));
        return cvVar;
    }

    public final zu zzb(@Nullable tg tgVar) {
        p7.l0.g("getEngine: Trying to acquire lock");
        Object obj = this.f10528a;
        synchronized (obj) {
            try {
                p7.l0.g("getEngine: Lock acquired");
                p7.l0.g("refreshIfDestroyed: Trying to acquire lock");
                synchronized (obj) {
                    try {
                        p7.l0.g("refreshIfDestroyed: Lock acquired");
                        cv cvVar = this.zzh;
                        if (cvVar != null && this.f10532e == 0) {
                            cvVar.l(new ru(this, 18), w80.f17919k);
                        }
                    } finally {
                    }
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        p7.l0.g("refreshIfDestroyed: Lock released");
        cv cvVar2 = this.zzh;
        if (cvVar2 != null && cvVar2.o() != -1) {
            int i10 = this.f10532e;
            if (i10 == 0) {
                p7.l0.g("getEngine (NO_UPDATE): Lock released");
                return this.zzh.p();
            }
            if (i10 != 1) {
                p7.l0.g("getEngine (UPDATING): Lock released");
                return this.zzh.p();
            }
            this.f10532e = 2;
            zza(null);
            p7.l0.g("getEngine (PENDING_UPDATE): Lock released");
            return this.zzh.p();
        }
        this.f10532e = 2;
        this.zzh = zza(null);
        p7.l0.g("getEngine (NULL or REJECTED): Lock released");
        return this.zzh.p();
    }
}
