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

import android.content.Context;
import android.os.IBinder;
import android.os.RemoteException;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.atomic.AtomicReference;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static pb1 f15358d;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final n7.p1 f15360b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final AtomicReference f15361c = new AtomicReference();

    public pb1(Context context, n7.p1 p1Var) {
        this.f15359a = context;
        this.f15360b = p1Var;
    }

    public static pb1 a(Context context) {
        synchronized (pb1.class) {
            try {
                pb1 pb1Var = f15358d;
                if (pb1Var != null) {
                    return pb1Var;
                }
                Context applicationContext = context.getApplicationContext();
                long jLongValue = ((Long) pp.f15481b.j()).longValue();
                n7.p1 p1VarAsInterface = null;
                if (jLongValue > 0 && jLongValue <= 254715000) {
                    try {
                        p1VarAsInterface = n7.o1.asInterface((IBinder) applicationContext.getClassLoader().loadClass("com.google.android.gms.ads.internal.client.LiteSdkInfo").getConstructor(Context.class).newInstance(applicationContext));
                    } catch (ClassCastException | ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException unused) {
                    }
                }
                pb1 pb1Var2 = new pb1(applicationContext, p1VarAsInterface);
                f15358d = pb1Var2;
                return pb1Var2;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void b(wv wvVar) {
        wv adapterCreator;
        boolean zBooleanValue = ((Boolean) pp.f15480a.j()).booleanValue();
        AtomicReference atomicReference = this.f15361c;
        if (!zBooleanValue) {
            while (!atomicReference.compareAndSet(null, wvVar) && atomicReference.get() == null) {
            }
            return;
        }
        n7.p1 p1Var = this.f15360b;
        if (p1Var == null) {
            adapterCreator = null;
        } else {
            try {
                adapterCreator = p1Var.getAdapterCreator();
            } catch (RemoteException unused) {
                adapterCreator = null;
            }
        }
        if (adapterCreator == null) {
            adapterCreator = wvVar;
        }
        while (!atomicReference.compareAndSet(null, adapterCreator) && atomicReference.get() == null) {
        }
    }
}
