package com.google.ads.mediation;

import android.content.Context;
import android.os.Bundle;
import android.os.RemoteException;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.mediation.MediationBannerAdapter;
import com.google.android.gms.ads.mediation.MediationInterstitialAdapter;
import com.google.android.gms.ads.mediation.MediationNativeAdapter;
import com.google.android.gms.internal.ads.ao;
import com.google.android.gms.internal.ads.gy;
import com.google.android.gms.internal.ads.kq;
import com.google.android.gms.internal.ads.mp;
import com.google.android.gms.internal.ads.nu;
import com.google.android.gms.internal.ads.qw;
import g7.a0;
import g7.f;
import g7.g;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import n7.n0;
import n7.p2;
import n7.r0;
import n7.t2;
import n7.t3;
import n7.u3;
import n7.x;
import n7.y;
import q7.j;
import s7.i;
import s7.l;
import s7.n;
import s7.p;

/* JADX INFO: loaded from: classes2.dex */
public abstract class AbstractAdViewAdapter implements MediationBannerAdapter, MediationInterstitialAdapter, MediationNativeAdapter {

    @NonNull
    public static final String AD_UNIT_ID_PARAMETER = "pubid";
    private g7.d adLoader;

    @NonNull
    protected AdView mAdView;

    @NonNull
    protected r7.a mInterstitialAd;

    public f buildAdRequest(Context context, s7.e eVar, Bundle bundle, Bundle bundle2) {
        g7.e eVar2 = new g7.e();
        Set setD = eVar.d();
        if (setD != null) {
            Iterator it = setD.iterator();
            while (it.hasNext()) {
                eVar2.c((String) it.next());
            }
        }
        boolean zC = eVar.c();
        Object obj = eVar2.f31277a;
        if (zC) {
            q7.e eVar3 = x.f31085g.f31086a;
            ((t2) obj).f31029d.add(q7.e.zzD(context));
        }
        if (eVar.a() != -1) {
            ((t2) obj).f31036k = eVar.a() != 1 ? 0 : 1;
        }
        ((t2) obj).f31037l = eVar.b();
        eVar2.d(buildExtrasBundle(bundle, bundle2));
        return new f(eVar2);
    }

    public abstract Bundle buildExtrasBundle(Bundle bundle, Bundle bundle2);

    @NonNull
    public String getAdUnitId(@NonNull Bundle bundle) {
        return bundle.getString(AD_UNIT_ID_PARAMETER);
    }

    @Override // com.google.android.gms.ads.mediation.MediationBannerAdapter
    @NonNull
    public View getBannerView() {
        return this.mAdView;
    }

    @VisibleForTesting
    public r7.a getInterstitialAd() {
        return this.mInterstitialAd;
    }

    @Nullable
    public p2 getVideoController() {
        AdView adView = this.mAdView;
        if (adView != null) {
            return adView.f7866a.f31075c.zzb();
        }
        return null;
    }

    @VisibleForTesting
    public g7.c newAdLoader(Context context, String str) {
        return new g7.c(context, str);
    }

    /* JADX WARN: Removed duplicated region for block: B:9:0x0038  */
    @Override // com.google.android.gms.ads.mediation.MediationBannerAdapter, s7.f, com.google.android.gms.ads.mediation.MediationInterstitialAdapter, com.google.android.gms.ads.mediation.MediationNativeAdapter
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void onDestroy() {
        AdView adView = this.mAdView;
        if (adView != null) {
            ao.a(adView.getContext());
            if (((Boolean) mp.f14329e.j()).booleanValue()) {
                if (((Boolean) y.f31093e.f31096c.b(ao.f9040qc)).booleanValue()) {
                    q7.b.f32218b.execute(new a0(adView, 2));
                } else {
                    adView.f7866a.c();
                }
                this.mAdView = null;
            }
        }
        if (this.mInterstitialAd != null) {
            this.mInterstitialAd = null;
        }
        if (this.adLoader != null) {
            this.adLoader = null;
        }
    }

    public void onImmersiveModeUpdated(boolean z10) {
        r7.a aVar = this.mInterstitialAd;
        if (aVar != null) {
            try {
                r0 r0Var = ((nu) aVar).f14735c;
                if (r0Var != null) {
                    r0Var.e0(z10);
                }
            } catch (RemoteException e10) {
                j.zzl("#007 Could not call remote method.", e10);
            }
        }
    }

    @Override // com.google.android.gms.ads.mediation.MediationBannerAdapter, s7.f, com.google.android.gms.ads.mediation.MediationInterstitialAdapter, com.google.android.gms.ads.mediation.MediationNativeAdapter
    public void onPause() {
        AdView adView = this.mAdView;
        if (adView != null) {
            ao.a(adView.getContext());
            if (((Boolean) mp.f14331g.j()).booleanValue()) {
                if (((Boolean) y.f31093e.f31096c.b(ao.f9057rc)).booleanValue()) {
                    q7.b.f32218b.execute(new a0(adView, 0));
                    return;
                }
            }
            adView.f7866a.f();
        }
    }

    @Override // com.google.android.gms.ads.mediation.MediationBannerAdapter, s7.f, com.google.android.gms.ads.mediation.MediationInterstitialAdapter, com.google.android.gms.ads.mediation.MediationNativeAdapter
    public void onResume() {
        AdView adView = this.mAdView;
        if (adView != null) {
            ao.a(adView.getContext());
            if (((Boolean) mp.f14332h.j()).booleanValue()) {
                if (((Boolean) y.f31093e.f31096c.b(ao.f9023pc)).booleanValue()) {
                    q7.b.f32218b.execute(new a0(adView, 1));
                    return;
                }
            }
            adView.f7866a.g();
        }
    }

    @Override // com.google.android.gms.ads.mediation.MediationBannerAdapter
    public void requestBannerAd(@NonNull Context context, @NonNull i iVar, @NonNull Bundle bundle, @NonNull g gVar, @NonNull s7.e eVar, @NonNull Bundle bundle2) {
        AdView adView = new AdView(context);
        this.mAdView = adView;
        adView.setAdSize(new g(gVar.f26290a, gVar.f26291b));
        this.mAdView.setAdUnitId(getAdUnitId(bundle));
        this.mAdView.setAdListener(new b(this, iVar));
        this.mAdView.a(buildAdRequest(context, eVar, bundle2, bundle));
    }

    @Override // com.google.android.gms.ads.mediation.MediationInterstitialAdapter
    public void requestInterstitialAd(@NonNull Context context, @NonNull l lVar, @NonNull Bundle bundle, @NonNull s7.e eVar, @NonNull Bundle bundle2) {
        r7.a.a(context, getAdUnitId(bundle), buildAdRequest(context, eVar, bundle2, bundle), new c(this, lVar));
    }

    @Override // com.google.android.gms.ads.mediation.MediationNativeAdapter
    public void requestNativeAd(@NonNull Context context, @NonNull n nVar, @NonNull Bundle bundle, @NonNull p pVar, @NonNull Bundle bundle2) {
        j7.c cVar;
        e eVar = new e(this, nVar);
        g7.c cVarNewAdLoader = newAdLoader(context, bundle.getString(AD_UNIT_ID_PARAMETER));
        cVarNewAdLoader.getClass();
        n0 n0Var = cVarNewAdLoader.f26276b;
        try {
            n0Var.T(new t3(eVar));
        } catch (RemoteException unused) {
        }
        qw qwVar = (qw) pVar;
        qwVar.getClass();
        j7.b bVar = new j7.b();
        kq kqVar = qwVar.f15870d;
        if (kqVar == null) {
            cVar = new j7.c(bVar);
        } else {
            int i10 = kqVar.f13369a;
            if (i10 == 2) {
                bVar.f28710f = kqVar.f13373e;
                bVar.f28705a = kqVar.f13370b;
                bVar.f28706b = kqVar.f13371c;
                bVar.f28708d = kqVar.f13372d;
                cVar = new j7.c(bVar);
            } else {
                if (i10 != 3) {
                    if (i10 == 4) {
                        bVar.f28711g = kqVar.f13374f;
                        bVar.f28707c = kqVar.f13375g;
                    }
                    bVar.f28705a = kqVar.f13370b;
                    bVar.f28706b = kqVar.f13371c;
                    bVar.f28708d = kqVar.f13372d;
                    cVar = new j7.c(bVar);
                }
                u3 u3Var = kqVar.zzf;
                if (u3Var != null) {
                    bVar.f28709e = new g7.y(u3Var);
                }
                bVar.f28710f = kqVar.f13373e;
                bVar.f28705a = kqVar.f13370b;
                bVar.f28706b = kqVar.f13371c;
                bVar.f28708d = kqVar.f13372d;
                cVar = new j7.c(bVar);
            }
        }
        try {
            n0Var.z1(new kq(cVar));
        } catch (RemoteException unused2) {
        }
        cVarNewAdLoader.b(kq.zza(qwVar.f15870d));
        ArrayList arrayList = qwVar.f15871e;
        if (arrayList.contains("6")) {
            try {
                n0Var.V(new gy(eVar, 1));
            } catch (RemoteException unused3) {
            }
        }
        if (arrayList.contains("3")) {
            HashMap map = qwVar.f15873g;
            for (String str : map.keySet()) {
                cVarNewAdLoader.zzb(str, eVar, true != ((Boolean) map.get(str)).booleanValue() ? null : eVar);
            }
        }
        g7.d dVarA = cVarNewAdLoader.a();
        this.adLoader = dVarA;
        dVarA.a(buildAdRequest(context, pVar, bundle2, bundle));
    }

    @Override // com.google.android.gms.ads.mediation.MediationInterstitialAdapter
    public void showInterstitial() {
        r7.a aVar = this.mInterstitialAd;
        if (aVar != null) {
            aVar.b(null);
        }
    }
}
