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

import android.app.Activity;
import android.content.Context;
import android.os.RemoteException;
import androidx.annotation.Nullable;
import com.google.android.gms.ads.internal.overlay.AdOverlayInfoParcel;

/* JADX INFO: loaded from: classes2.dex */
public final class ss0 implements com.google.android.gms.ads.internal.overlay.p, w60 {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public ps0 f16567c;

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

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

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

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

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

    @Nullable
    private n7.a2 zzh;

    public ss0(Context context, q7.a aVar) {
        this.f16565a = context;
        this.f16566b = aVar;
    }

    @Override // com.google.android.gms.ads.internal.overlay.p
    public final void B0() {
    }

    @Override // com.google.android.gms.ads.internal.overlay.p
    public final void M() {
    }

    @Override // com.google.android.gms.ads.internal.overlay.p
    public final synchronized void O(int i10) {
        this.f16568d.destroy();
        if (!this.f16572h) {
            p7.l0.g("Inspector closed.");
            n7.a2 a2Var = this.zzh;
            if (a2Var != null) {
                try {
                    a2Var.zze(null);
                } catch (RemoteException unused) {
                }
            }
        }
        this.f16570f = false;
        this.f16569e = false;
        this.f16571g = 0L;
        this.f16572h = false;
        this.zzh = null;
    }

    @Override // com.google.android.gms.ads.internal.overlay.p
    public final void O0() {
    }

    @Override // com.google.android.gms.ads.internal.overlay.p
    public final void W() {
    }

    @Override // com.google.android.gms.ads.internal.overlay.p
    public final void Z1() {
    }

    public final synchronized void a(n7.a2 a2Var, mt mtVar, gt gtVar, zs zsVar) {
        if (c(a2Var)) {
            try {
                m7.n nVar = m7.n.C;
                h60 h60Var = nVar.f30465d;
                x50 x50VarZza = h60.zza(this.f16565a, new d70(0, 0, 0), "", false, false, null, null, this.f16566b, null, null, null, new il(), null, null, null, null, null);
                this.f16568d = x50VarZza;
                c60 c60VarZzP = x50VarZza.zzP();
                if (c60VarZzP == null) {
                    q7.j.d("Failed to obtain a web view for the ad inspector");
                    try {
                        nVar.f30469h.d("InspectorUi.openInspector 2", new NullPointerException("Failed to obtain a web view for the ad inspector"));
                        a2Var.zze(sb1.zzd(17, "Failed to obtain a web view for the ad inspector", null));
                        return;
                    } catch (RemoteException e10) {
                        m7.n.C.f30469h.d("InspectorUi.openInspector 3", e10);
                        return;
                    }
                }
                this.zzh = a2Var;
                Context context = this.f16565a;
                c60VarZzP.zzab(null, null, null, null, null, false, null, null, null, null, null, null, null, mtVar, null, new lt(context), gtVar, zsVar, null, null, null, null);
                c60VarZzP.f9756f = this;
                this.f16568d.loadUrl((String) n7.y.f31093e.f31096c.b(ao.f8872ga));
                com.google.android.gms.ads.internal.overlay.m.zza(context, new AdOverlayInfoParcel(this, this.f16568d, this.f16566b), true, null);
                nVar.f30472k.getClass();
                this.f16571g = System.currentTimeMillis();
            } catch (zzcka e11) {
                try {
                    m7.n.C.f30469h.d("InspectorUi.openInspector 0", e11);
                    a2Var.zze(sb1.zzd(17, "Failed to obtain a web view for the ad inspector", null));
                } catch (RemoteException e12) {
                    m7.n.C.f30469h.d("InspectorUi.openInspector 1", e12);
                }
            }
        }
    }

    public final synchronized void b() {
        if (this.f16569e && this.f16570f) {
            b30.f9364f.execute(new z80(this, 14));
        }
    }

    @Override // com.google.android.gms.ads.internal.overlay.p
    public final void b1() {
    }

    public final synchronized boolean c(n7.a2 a2Var) {
        tn tnVar = ao.f8856fa;
        n7.y yVar = n7.y.f31093e;
        if (!((Boolean) yVar.f31096c.b(tnVar)).booleanValue()) {
            q7.j.d("Ad inspector had an internal error.");
            try {
                a2Var.zze(sb1.zzd(16, null, null));
            } catch (RemoteException unused) {
            }
            return false;
        }
        if (this.f16567c == null) {
            q7.j.d("Ad inspector had an internal error.");
            try {
                m7.n.C.f30469h.d("InspectorUi.shouldOpenUi", new NullPointerException("InspectorManager null"));
                a2Var.zze(sb1.zzd(16, null, null));
            } catch (RemoteException unused2) {
            }
            return false;
        }
        if (!this.f16569e && !this.f16570f) {
            m7.n.C.f30472k.getClass();
            if (System.currentTimeMillis() >= this.f16571g + ((long) ((Integer) yVar.f31096c.b(ao.f8905ia)).intValue())) {
                return true;
            }
        }
        q7.j.d("Ad inspector cannot be opened because it is already open.");
        try {
            a2Var.zze(sb1.zzd(19, null, null));
        } catch (RemoteException unused3) {
        }
        return false;
    }

    @Override // com.google.android.gms.ads.internal.overlay.p
    public final void i1() {
    }

    @Override // com.google.android.gms.ads.internal.overlay.p
    public final void r0() {
    }

    @Override // com.google.android.gms.internal.ads.w60
    public final synchronized void s(String str, int i10, String str2, boolean z10) {
        if (z10) {
            p7.l0.g("Ad inspector loaded.");
            this.f16569e = true;
            b();
            return;
        }
        q7.j.d("Ad inspector failed to load.");
        try {
            r20 r20Var = m7.n.C.f30469h;
            StringBuilder sb = new StringBuilder(String.valueOf(i10).length() + 46 + String.valueOf(str).length() + 15 + String.valueOf(str2).length());
            sb.append("Failed to load UI. Error code: ");
            sb.append(i10);
            sb.append(", Description: ");
            sb.append(str);
            sb.append(", Failing URL: ");
            sb.append(str2);
            r20Var.d("InspectorUi.onAdWebViewFinishedLoading 0", new Exception(sb.toString()));
            n7.a2 a2Var = this.zzh;
            if (a2Var != null) {
                a2Var.zze(sb1.zzd(17, null, null));
            }
        } catch (RemoteException e10) {
            m7.n.C.f30469h.d("InspectorUi.onAdWebViewFinishedLoading 1", e10);
        }
        this.f16572h = true;
        this.f16568d.destroy();
    }

    @Override // com.google.android.gms.ads.internal.overlay.p
    public final void w1() {
    }

    @Override // com.google.android.gms.ads.internal.overlay.p
    public final synchronized void zzh() {
        this.f16570f = true;
        b();
    }

    @Nullable
    public final Activity zzo() {
        x50 x50Var = this.f16568d;
        if (x50Var == null || x50Var.K()) {
            return null;
        }
        return this.f16568d.zzj();
    }
}
