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

import android.app.ActivityManager;
import android.content.Context;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import androidx.annotation.Nullable;
import com.google.android.gms.ads.internal.util.client.zzr;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final p7.o0 f15956b;

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public q7.a f15960f;

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

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

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final Object f15965k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public com.google.common.util.concurrent.w f15966l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final AtomicBoolean f15967m;

    @Nullable
    private co zzh;

    @Nullable
    private cr0 zzi;

    @Nullable
    private Boolean zzj;

    public r20() {
        p7.o0 o0Var = new p7.o0();
        this.f15956b = o0Var;
        this.f15957c = new v20(n7.x.f31085g.f31091f, o0Var);
        this.f15958d = false;
        this.zzh = null;
        this.zzi = null;
        this.zzj = null;
        this.f15962h = new AtomicInteger(0);
        this.f15963i = new AtomicInteger(0);
        this.f15964j = new q20();
        this.f15965k = new Object();
        this.f15967m = new AtomicBoolean();
    }

    public final /* synthetic */ co a() {
        return this.zzh;
    }

    public final void b(Boolean bool) {
        synchronized (this.f15955a) {
            this.zzj = bool;
        }
    }

    public final Boolean c() {
        Boolean bool;
        synchronized (this.f15955a) {
            bool = this.zzj;
        }
        return bool;
    }

    public final void d(String str, Throwable th) {
        dz.b(this.f15959e, this.f15960f).d(str, th);
    }

    public final void e(String str, Throwable th) {
        dz.b(this.f15959e, this.f15960f).e(th, str, ((Double) xp.f18507f.j()).floatValue());
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0037 A[Catch: all -> 0x0035, TryCatch #0 {all -> 0x0035, blocks: (B:4:0x0007, B:6:0x000b, B:8:0x001d, B:10:0x002d, B:13:0x0037, B:14:0x0040), top: B:19:0x0007 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void f(String str, Throwable th) {
        Context context = this.f15959e;
        q7.a aVar = this.f15960f;
        synchronized (dz.f10569j) {
            try {
                if (dz.zzb == null) {
                    tn tnVar = ao.f9184z8;
                    n7.y yVar = n7.y.f31093e;
                    if (((Boolean) yVar.f31096c.b(tnVar)).booleanValue()) {
                        if (((Boolean) yVar.f31096c.b(ao.f9169y8)).booleanValue()) {
                            dz.zzb = new va2(26);
                        } else {
                            dz.zzb = new dz(context, aVar);
                        }
                    }
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }
        dz.zzb.d(str, th);
    }

    public final p7.o0 g() {
        p7.o0 o0Var;
        synchronized (this.f15955a) {
            o0Var = this.f15956b;
        }
        return o0Var;
    }

    public final com.google.common.util.concurrent.w h() {
        if (this.f15959e != null) {
            if (!((Boolean) n7.y.f31093e.f31096c.b(ao.A3)).booleanValue()) {
                synchronized (this.f15965k) {
                    try {
                        com.google.common.util.concurrent.w wVar = this.f15966l;
                        if (wVar != null) {
                            return wVar;
                        }
                        com.google.common.util.concurrent.w wVarG = b30.f9359a.g(new ug(this, 1));
                        this.f15966l = wVarG;
                        return wVarG;
                    } catch (Throwable th) {
                        throw th;
                    }
                }
            }
        }
        return ih1.k(new ArrayList());
    }

    public final boolean i(Context context) {
        if (com.bumptech.glide.g.l()) {
            if (((Boolean) n7.y.f31093e.f31096c.b(ao.f9170y9)).booleanValue()) {
                return this.f15967m.get();
            }
        }
        NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
        return activeNetworkInfo != null && activeNetworkInfo.isConnected();
    }

    public final cr0 j() {
        return this.zzi;
    }

    @Nullable
    public final co zza() {
        co coVar;
        synchronized (this.f15955a) {
            coVar = this.zzh;
        }
        return coVar;
    }

    public final void zze(Context context, q7.a aVar, @Nullable cr0 cr0Var) {
        co coVar;
        synchronized (this.f15955a) {
            try {
                if (!this.f15958d) {
                    this.f15959e = context.getApplicationContext();
                    this.f15960f = aVar;
                    m7.n.C.f30468g.b(this.f15957c);
                    this.f15956b.m(this.f15959e);
                    dz.b(this.f15959e, this.f15960f);
                    this.zzi = cr0Var;
                    tn tnVar = ao.f9096u2;
                    n7.y yVar = n7.y.f31093e;
                    if (((Boolean) yVar.f31096c.b(tnVar)).booleanValue()) {
                        coVar = new co();
                    } else {
                        p7.l0.g("CsiReporterFactory: CSI is not enabled. No CSI reporter created.");
                        coVar = null;
                    }
                    this.zzh = coVar;
                    if (coVar != null) {
                        ni.k(new p7.f0(this).b(), "AppState.registerCsiReporter");
                    }
                    Context context2 = this.f15959e;
                    if (com.bumptech.glide.g.l()) {
                        if (((Boolean) yVar.f31096c.b(ao.f9170y9)).booleanValue()) {
                            try {
                                ((ConnectivityManager) context2.getSystemService("connectivity")).registerDefaultNetworkCallback(new m4.e(this));
                            } catch (RuntimeException unused) {
                                this.f15967m.set(true);
                            }
                        }
                    }
                    this.f15958d = true;
                    h();
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        if (((Boolean) n7.y.f31093e.f31096c.b(ao.f8861ff)).booleanValue()) {
            return;
        }
        m7.n.C.f30464c.A(context, aVar.f32212a);
    }

    @Nullable
    public final Resources zzf() {
        if (this.f15960f.f32215d) {
            return this.f15959e.getResources();
        }
        try {
        } catch (zzr unused) {
        }
        if (((Boolean) n7.y.f31093e.f31096c.b(ao.f8841ec)).booleanValue()) {
            return hb.a.U0(this.f15959e).f30180a.getResources();
        }
        hb.a.U0(this.f15959e).f30180a.getResources();
        return null;
    }

    @Nullable
    public final Context zzp() {
        return this.f15959e;
    }

    @Nullable
    public final ActivityManager.MemoryInfo zzw() {
        return q7.e.zze(this.f15959e);
    }
}
