导航菜单

页面标题

页面副标题

MX Player v1.97.8 - MediationServiceImpl.java 源代码

正在查看: MX Player v1.97.8 应用的 MediationServiceImpl.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.applovin.impl.mediation;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
import android.view.ViewGroup;
import com.amazon.identity.auth.device.api.MAPActorManager;
import com.applovin.impl.an;
import com.applovin.impl.ca;
import com.applovin.impl.fi;
import com.applovin.impl.fn;
import com.applovin.impl.gc;
import com.applovin.impl.ge;
import com.applovin.impl.ie;
import com.applovin.impl.la;
import com.applovin.impl.ln;
import com.applovin.impl.ma;
import com.applovin.impl.mediation.MediationServiceImpl;
import com.applovin.impl.mediation.ads.a;
import com.applovin.impl.mediation.d;
import com.applovin.impl.mediation.g;
import com.applovin.impl.ne;
import com.applovin.impl.pe;
import com.applovin.impl.rm;
import com.applovin.impl.sdk.AppLovinBroadcastManager;
import com.applovin.impl.sdk.e;
import com.applovin.impl.sdk.m;
import com.applovin.impl.sdk.utils.CollectionUtils;
import com.applovin.impl.sdk.utils.StringUtils;
import com.applovin.impl.sj;
import com.applovin.impl.tm;
import com.applovin.impl.ve;
import com.applovin.impl.we;
import com.applovin.impl.xe;
import com.applovin.impl.xj;
import com.applovin.impl.yj;
import com.applovin.impl.yl;
import com.applovin.impl.yp;
import com.applovin.impl.zj;
import com.applovin.mediation.MaxAd;
import com.applovin.mediation.MaxAdFormat;
import com.applovin.mediation.MaxAdListener;
import com.applovin.mediation.MaxAdRequestListener;
import com.applovin.mediation.MaxAdRevenueListener;
import com.applovin.mediation.MaxAdViewAdListener;
import com.applovin.mediation.MaxError;
import com.applovin.mediation.MaxMediatedNetworkInfo;
import com.applovin.mediation.MaxNetworkResponseInfo;
import com.applovin.mediation.MaxReward;
import com.applovin.mediation.MaxRewardedAdListener;
import com.applovin.mediation.adapter.MaxAdapter;
import com.applovin.mediation.adapter.MaxAdapterError;
import com.applovin.sdk.AppLovinSdkUtils;
import defpackage.fba;
import defpackage.lg;
import defpackage.vkb;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import org.json.JSONObject;

public class MediationServiceImpl implements AppLovinBroadcastManager.Receiver {
    private final com.applovin.impl.sdk.j a;
    private final com.applovin.impl.sdk.n b;
    private final xj c;
    private final AtomicReference d = new AtomicReference();

    public class a implements g.b {
        final g a;
        final String b;
        final long c;
        final zj d;
        final MaxAdFormat e;
        final yj.a f;

        public a(g gVar, String str, long j, zj zjVar, MaxAdFormat maxAdFormat, yj.a aVar) {
            this.a = gVar;
            this.b = str;
            this.c = j;
            this.d = zjVar;
            this.e = maxAdFormat;
            this.f = aVar;
        }

        @Override
        public void a(MaxError maxError) {
            com.applovin.impl.sdk.n unused = MediationServiceImpl.this.b;
            if (com.applovin.impl.sdk.n.a()) {
                MediationServiceImpl.this.b.b("MediationService", "Signal collection failed from: " + this.a.g() + " for Ad Unit ID: " + this.b + " with error message: \"" + maxError.getMessage() + "\"");
            }
            long elapsedRealtime = SystemClock.elapsedRealtime();
            long j = this.c;
            yj a = yj.a(this.d, this.a, maxError, j, elapsedRealtime - j);
            MediationServiceImpl.this.a(a, this.d, this.a);
            this.f.a(a);
            this.a.a();
        }

        @Override
        public void onSignalCollected(String str) {
            com.applovin.impl.sdk.n unused = MediationServiceImpl.this.b;
            if (com.applovin.impl.sdk.n.a()) {
                com.applovin.impl.sdk.n nVar = MediationServiceImpl.this.b;
                StringBuilder sb = new StringBuilder("Signal collection successful from: ");
                sb.append(this.a.g());
                sb.append(" for Ad Unit ID: ");
                nVar.a("MediationService", my1.i(sb, this.b, " with signal: \"", str, "\""));
            }
            long elapsedRealtime = SystemClock.elapsedRealtime();
            long j = this.c;
            long j2 = elapsedRealtime - j;
            yj a = yj.a(this.d, this.a, str, j, j2);
            MediationServiceImpl.this.c.a(a, this.d, this.b, this.e);
            HashMap hashMap = new HashMap();
            CollectionUtils.putStringIfValid("network_name", this.d.c(), hashMap);
            CollectionUtils.putStringIfValid("adapter_class", this.d.b(), hashMap);
            CollectionUtils.putStringIfValid("adapter_version", this.a.b(), hashMap);
            CollectionUtils.putStringIfValid("duration_ms", String.valueOf(j2), hashMap);
            CollectionUtils.putStringIfValid("ad_format", String.valueOf(this.e.getLabel()), hashMap);
            CollectionUtils.putStringIfValid("ad_unit_id", this.b, hashMap);
            MediationServiceImpl.this.a.E().a(la.p, (Map) hashMap);
            this.f.a(a);
            this.a.a();
        }
    }

    public class b implements g.b {
        final fi a;

        public b(fi fiVar) {
            this.a = fiVar;
        }

        @Override
        public void a(MaxError maxError) {
            this.a.a(maxError);
        }

        @Override
        public void onSignalCollected(String str) {
            this.a.b(str);
        }
    }

    public static class c {
        static final int[] a;

        static {
            int[] iArr = new int[MaxAdapter.InitializationStatus.values().length];
            a = iArr;
            try {
                iArr[MaxAdapter.InitializationStatus.DOES_NOT_APPLY.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                a[MaxAdapter.InitializationStatus.INITIALIZED_SUCCESS.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                a[MaxAdapter.InitializationStatus.INITIALIZED_UNKNOWN.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                a[MaxAdapter.InitializationStatus.INITIALIZED_FAILURE.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                a[MaxAdapter.InitializationStatus.NOT_INITIALIZED.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                a[MaxAdapter.InitializationStatus.INITIALIZING.ordinal()] = 6;
            } catch (NoSuchFieldError unused6) {
            }
        }
    }

    public class d implements MaxAdListener, MaxRewardedAdListener, MaxAdViewAdListener, MaxAdRevenueListener, a.InterfaceC0105a {
        private final ge a;
        private a.InterfaceC0105a b;

        public d(ge geVar, a.InterfaceC0105a interfaceC0105a) {
            this.a = geVar;
            this.b = interfaceC0105a;
        }

        public void b(MaxAd maxAd, Bundle bundle) {
            this.a.a(bundle);
            gc.b(this.b, maxAd);
        }

        public void c(MaxAd maxAd, Bundle bundle) {
            this.a.a(bundle);
            com.applovin.impl.sdk.n unused = MediationServiceImpl.this.b;
            if (com.applovin.impl.sdk.n.a()) {
                MediationServiceImpl.this.b.a("MediationService", "Scheduling impression for ad via callback...");
            }
            MediationServiceImpl.this.processCallbackAdImpressionPostback(this.a, this.b);
            if (!((Boolean) MediationServiceImpl.this.a.a(ve.Q7)).booleanValue() || this.a.v().compareAndSet(false, true)) {
                MediationServiceImpl.this.a.j().a(this.a, e.c.SHOW);
                MediationServiceImpl.this.a.D().c(ca.f);
                MediationServiceImpl.this.a.D().c(ca.i);
                if (!maxAd.getFormat().isFullscreenAd()) {
                    MediationServiceImpl.this.a.p().b(this.a, "DID_DISPLAY");
                    gc.c(this.b, maxAd);
                    return;
                }
                ie ieVar = (ie) maxAd;
                if (ieVar.t0()) {
                    MediationServiceImpl.this.a.p().b(this.a, "DID_DISPLAY");
                    MediationServiceImpl.this.a.C().a(this.a);
                    gc.c(this.b, maxAd);
                } else {
                    com.applovin.impl.sdk.n unused2 = MediationServiceImpl.this.b;
                    if (com.applovin.impl.sdk.n.a()) {
                        MediationServiceImpl.this.b.k("MediationService", "Received ad display callback before attempting show".concat(ieVar.b0() ? " for hybrid ad" : ""));
                    }
                }
            }
        }

        public void d(MaxAd maxAd, Bundle bundle) {
            this.a.a(bundle);
            gc.d(this.b, maxAd);
        }

        public void e(MaxAd maxAd, Bundle bundle) {
            this.a.a(bundle);
            MediationServiceImpl.this.a.E().a(la.A, this.a);
            MediationServiceImpl.this.a.j().a(this.a, e.c.HIDE);
            MediationServiceImpl.this.a.p().b((ge) maxAd, "DID_HIDE");
            AppLovinSdkUtils.runOnUiThreadDelayed(new x98(4, this, maxAd), maxAd instanceof ie ? ((ie) maxAd).k0() : 0L);
        }

        public void f(MaxAd maxAd, Bundle bundle) {
            this.a.a(bundle);
            this.a.g0();
            MediationServiceImpl.this.a.j().a(this.a, e.c.LOAD);
            MediationServiceImpl.this.a(this.a);
            gc.f(this.b, maxAd);
        }

        @Override
        public void onAdClicked(MaxAd maxAd) {
            a(maxAd, (Bundle) null);
        }

        @Override
        public void onAdCollapsed(MaxAd maxAd) {
            b(maxAd, null);
        }

        @Override
        public void onAdDisplayFailed(MaxAd maxAd, MaxError maxError) {
            a(maxAd, maxError, (Bundle) null);
        }

        @Override
        public void onAdDisplayed(MaxAd maxAd) {
            c(maxAd, null);
        }

        @Override
        public void onAdExpanded(MaxAd maxAd) {
            d(maxAd, null);
        }

        @Override
        public void onAdHidden(MaxAd maxAd) {
            e(maxAd, null);
        }

        @Override
        public void onAdLoadFailed(String str, MaxError maxError) {
            this.a.g0();
            MediationServiceImpl.this.b(this.a, maxError, this.b);
        }

        @Override
        public void onAdLoaded(MaxAd maxAd) {
            f(maxAd, null);
        }

        @Override
        public void onRewardedVideoCompleted(MaxAd maxAd) {
            gc.g(this.b, maxAd);
        }

        @Override
        public void onRewardedVideoStarted(MaxAd maxAd) {
            gc.h(this.b, maxAd);
        }

        @Override
        public void onUserRewarded(MaxAd maxAd, MaxReward maxReward) {
            a(maxAd, maxReward, (Bundle) null);
        }

        public void a(a.InterfaceC0105a interfaceC0105a) {
            this.b = interfaceC0105a;
        }

        public void a(MaxAd maxAd) {
            if (maxAd.getFormat().isFullscreenAd()) {
                MediationServiceImpl.this.a.C().b(maxAd);
            }
            gc.e(this.b, maxAd);
        }

        public void a(MaxAd maxAd, Bundle bundle) {
            this.a.a(bundle);
            MediationServiceImpl.this.a.j().a(this.a, e.c.CLICK);
            MediationServiceImpl.this.a(this.a, this.b);
            gc.a((MaxAdListener) this.b, maxAd);
        }

        public void a(MaxAd maxAd, MaxError maxError, Bundle bundle) {
            this.a.a(bundle);
            MediationServiceImpl.this.a(this.a, maxError, this.b);
            if ((maxAd.getFormat() == MaxAdFormat.REWARDED || maxAd.getFormat() == MaxAdFormat.REWARDED_INTERSTITIAL) && (maxAd instanceof ie)) {
                ((ie) maxAd).i0();
            }
        }

        public void a(MaxAd maxAd, MaxReward maxReward, Bundle bundle) {
            this.a.a(bundle);
            gc.a(this.b, maxAd, maxReward);
            MediationServiceImpl.this.a.j0().a((yl) new fn((ie) maxAd, MediationServiceImpl.this.a), tm.b.OTHER);
        }

        @Override
        public void onAdRequestStarted(String str) {
        }

        @Override
        public void onAdRevenuePaid(MaxAd maxAd) {
        }
    }

    public MediationServiceImpl(com.applovin.impl.sdk.j jVar) {
        this.a = jVar;
        this.b = jVar.J();
        this.c = new xj(jVar);
        AppLovinBroadcastManager.registerReceiver(this, new IntentFilter("com.applovin.render_process_gone"));
    }

    public void collectSignal(String str, MaxAdFormat maxAdFormat, zj zjVar, Context context, yj.a aVar) {
        if (zjVar == null) {
            throw new IllegalArgumentException("No spec specified");
        }
        if (context == null) {
            throw new IllegalArgumentException("No context specified");
        }
        if (aVar == null) {
            throw new IllegalArgumentException("No callback specified");
        }
        yj b2 = this.c.b(zjVar, str, maxAdFormat);
        if (b2 != null) {
            aVar.a(yj.a(b2));
            return;
        }
        g a2 = this.a.M().a(zjVar, zjVar.A());
        if (a2 == null) {
            aVar.a(yj.a(zjVar, new MaxErrorImpl("Could not load adapter")));
            return;
        }
        if (((Boolean) this.a.a(ve.P7)).booleanValue()) {
            a(str, maxAdFormat, zjVar, context, aVar, a2);
            return;
        }
        Activity n0 = context instanceof Activity ? (Activity) context : this.a.n0();
        MaxAdapterParametersImpl a3 = MaxAdapterParametersImpl.a(zjVar, str, maxAdFormat);
        if (zjVar.z()) {
            this.a.L().b(zjVar, n0);
        }
        a aVar2 = new a(a2, str, SystemClock.elapsedRealtime(), zjVar, maxAdFormat, aVar);
        if (!zjVar.w()) {
            if (com.applovin.impl.sdk.n.a()) {
                this.b.a("MediationService", "Collecting signal for adapter: " + a2.g());
            }
            a2.a(a3, zjVar, n0, aVar2);
            return;
        }
        if (this.a.L().b(zjVar)) {
            if (com.applovin.impl.sdk.n.a()) {
                this.b.a("MediationService", "Collecting signal for now-initialized adapter: " + a2.g());
            }
            a2.a(a3, zjVar, n0, aVar2);
            return;
        }
        if (com.applovin.impl.sdk.n.a()) {
            this.b.b("MediationService", "Skip collecting signal for not-initialized adapter: " + a2.g());
        }
        aVar.a(yj.a(zjVar, new MaxErrorImpl("Adapter not initialized yet")));
    }

    public void destroyAd(MaxAd maxAd) {
        if (maxAd instanceof ge) {
            if (com.applovin.impl.sdk.n.a()) {
                this.b.d("MediationService", "Destroying " + maxAd);
            }
            ge geVar = (ge) maxAd;
            g B = geVar.B();
            if (B != null) {
                B.a();
                geVar.u();
            }
            this.a.h().c(geVar.T());
            this.a.j().a(geVar, e.c.DESTROY);
        }
    }

    public JSONObject getAndResetCustomPostBodyData() {
        return (JSONObject) this.d.getAndSet(null);
    }

    public void loadAd(String str, String str2, MaxAdFormat maxAdFormat, d.b bVar, Map<String, Object> map, Map<String, Object> map2, Context context, a.InterfaceC0105a interfaceC0105a) {
        if (TextUtils.isEmpty(str)) {
            throw new IllegalArgumentException("No Ad Unit ID specified");
        }
        if (context == null) {
            throw new IllegalArgumentException("No context specified");
        }
        if (interfaceC0105a == null) {
            throw new IllegalArgumentException("No listener specified");
        }
        if (TextUtils.isEmpty(this.a.O())) {
            com.applovin.impl.sdk.n.h("AppLovinSdk", "Mediation provider is null. Please set AppLovin SDK mediation provider via AppLovinSdk.getInstance(context).setMediationProvider()");
        }
        if (!this.a.u0()) {
            com.applovin.impl.sdk.n.j("AppLovinSdk", "Attempted to load ad before SDK initialization. Please wait until after the SDK has initialized, e.g. AppLovinSdk.initializeSdk(Context, SdkInitializationListener).");
        }
        List<String> initializationAdUnitIds = this.a.z0().get() ? this.a.g0().getInitializationAdUnitIds() : this.a.H() != null ? this.a.H().getAdUnitIds() : null;
        boolean startsWith = str.startsWith("test_mode");
        if (initializationAdUnitIds != null && initializationAdUnitIds.size() > 0 && !initializationAdUnitIds.contains(str) && !startsWith) {
            if (yp.c(this.a)) {
                String e = lg0.e("Ad Unit ID ", str, " has not been initialized. When you use selective init, any ad units that you do not explicitly specify are excluded from serving ads for the current session. For more information visit our docs: https://developers.applovin.com/en/android/overview/terms-and-privacy-policy-flow");
                if (((Boolean) this.a.a(sj.m6)).booleanValue()) {
                    throw new RuntimeException(e);
                }
                if (com.applovin.impl.sdk.n.a()) {
                    this.b.b("MediationService", e);
                }
            }
            this.a.E().a(la.L, "uninitialized_ad_unit_id", CollectionUtils.hashMap("ad_unit_id", str), "uninitialized_ad_unit_id".concat(str));
        }
        this.a.c();
        if (str.length() != 16 && !startsWith && !this.a.b0().startsWith("05TMD")) {
            StringBuilder c2 = lg.c("Please double-check the ad unit ", str, " for ");
            c2.append(maxAdFormat.getLabel());
            c2.append(" : ");
            c2.append(Log.getStackTraceString(new Throwable("")));
            com.applovin.impl.sdk.n.h("MediationService", c2.toString());
        }
        if (!this.a.a(maxAdFormat)) {
            this.a.S0();
            gc.a((MaxAdRequestListener) interfaceC0105a, str, true);
            this.a.K().a(str, str2, maxAdFormat, bVar, map, map2, context, interfaceC0105a);
        } else {
            com.applovin.impl.sdk.n.h("MediationService", "Ad load failed due to disabled ad format " + maxAdFormat.getLabel());
            gc.a(interfaceC0105a, str, new MaxErrorImpl(-1, "Disabled ad format " + maxAdFormat.getLabel()));
        }
    }

    public void loadThirdPartyMediatedAd(final String str, ge geVar, boolean z, final Activity activity, final a.InterfaceC0105a interfaceC0105a) {
        fi fiVar;
        if (geVar == null) {
            throw new IllegalArgumentException("No mediated ad specified");
        }
        if (com.applovin.impl.sdk.n.a()) {
            this.b.a("MediationService", "Loading " + geVar + "...");
        }
        if (!z) {
            this.a.E().a(la.u, geVar);
            this.a.p().b(geVar, "WILL_LOAD");
        }
        final g a2 = this.a.M().a(geVar);
        if (a2 == null) {
            String str2 = "Failed to load " + geVar + ": adapter not loaded";
            com.applovin.impl.sdk.n.h("MediationService", str2);
            b(geVar, new MaxErrorImpl(-5001, str2), interfaceC0105a);
            return;
        }
        final MaxAdapterParametersImpl a3 = MaxAdapterParametersImpl.a(geVar);
        if (geVar.e0()) {
            fiVar = this.a.L().a(geVar, activity);
        } else {
            if (geVar.f0()) {
                this.a.L().b(geVar, activity);
            }
            fiVar = null;
        }
        final ge a4 = geVar.a(a2);
        a2.a(str, a4);
        a4.h0();
        if (fiVar == null) {
            a2.a(str, a3, a4, activity, new d(a4, interfaceC0105a));
        } else {
            fiVar.a((fi.a) new ra6(this, geVar, interfaceC0105a));
            fiVar.a(new Runnable() {
                @Override
                public final void run() {
                    MediationServiceImpl.this.a(a2, str, a3, a4, activity, interfaceC0105a);
                }
            });
        }
    }

    @Override
    public void onReceive(Intent intent, Map<String, Object> map) {
        if ("com.applovin.render_process_gone".equals(intent.getAction())) {
            Object a2 = this.a.C().a();
            if (a2 instanceof ge) {
                a((MaxError) MaxAdapterError.WEBVIEW_ERROR, (ge) a2, true);
            }
        }
    }

    public void processAdDisplayErrorPostbackForUserError(MaxError maxError, ge geVar) {
        a(maxError, geVar, false);
    }

    public void processAdapterInitializationPostback(pe peVar, long j, MaxAdapter.InitializationStatus initializationStatus, String str) {
        HashMap hashMap = new HashMap(2);
        hashMap.put("{INIT_STATUS}", String.valueOf(initializationStatus.getCode()));
        hashMap.put("{INIT_TIME_MS}", String.valueOf(j));
        a("minit", hashMap, new MaxErrorImpl(str), peVar);
        Map a2 = ma.a(peVar);
        CollectionUtils.putStringIfValid("adapter_init_status", String.valueOf(initializationStatus.getCode()), a2);
        CollectionUtils.putStringIfValid(MAPActorManager.KEY_ERROR_MESSAGE, str, a2);
        CollectionUtils.putStringIfValid("duration_ms", String.valueOf(j), a2);
        switch (c.a[initializationStatus.ordinal()]) {
            case 1:
            case 2:
            case 3:
                this.a.E().a(la.n, a2);
                break;
            case 4:
                this.a.E().a(la.o, a2);
                break;
            case 5:
            case 6:
                this.a.J();
                if (com.applovin.impl.sdk.n.a()) {
                    this.a.J().k("MediationService", "Adapter init postback called while the adapter is not fully initialized.");
                }
                this.a.E().a(la.d, "adapterNotInitializedForPostback", a2);
                break;
        }
    }

    public void processCallbackAdImpressionPostback(ge geVar, a.InterfaceC0105a interfaceC0105a) {
        if (geVar.R().endsWith("cimp")) {
            this.a.p().b(geVar);
            gc.a((MaxAdRevenueListener) interfaceC0105a, (MaxAd) geVar);
        }
        HashMap hashMap = new HashMap(1);
        String emptyIfNull = StringUtils.emptyIfNull(this.a.q0().c());
        if (!((Boolean) this.a.a(sj.R3)).booleanValue()) {
            emptyIfNull = "";
        }
        hashMap.put("{CUID}", emptyIfNull);
        a("mcimp", hashMap, geVar);
        this.a.E().a(la.y, geVar);
    }

    public void processRawAdImpression(ge geVar, a.InterfaceC0105a interfaceC0105a) {
        this.a.p().b(geVar, "WILL_DISPLAY");
        if (geVar.R().endsWith("mimp")) {
            this.a.p().b(geVar);
            gc.a((MaxAdRevenueListener) interfaceC0105a, (MaxAd) geVar);
        }
        if (((Boolean) this.a.a(sj.J4)).booleanValue()) {
            this.a.R().a(we.d, xe.a(geVar), Long.valueOf(System.currentTimeMillis() - this.a.I()));
        }
        HashMap hashMap = new HashMap(2);
        if (geVar instanceof ie) {
            hashMap.put("{TIME_TO_SHOW_MS}", String.valueOf(((ie) geVar).o0()));
        }
        String emptyIfNull = StringUtils.emptyIfNull(this.a.q0().c());
        if (!((Boolean) this.a.a(sj.R3)).booleanValue()) {
            emptyIfNull = "";
        }
        hashMap.put("{CUID}", emptyIfNull);
        a("mimp", hashMap, geVar);
    }

    public void processViewabilityAdImpressionPostback(ne neVar, long j, a.InterfaceC0105a interfaceC0105a) {
        if (neVar.R().endsWith("vimp")) {
            this.a.p().b(neVar);
            gc.a((MaxAdRevenueListener) interfaceC0105a, (MaxAd) neVar);
        }
        HashMap hashMap = new HashMap(3);
        hashMap.put("{VIEWABILITY_FLAGS}", String.valueOf(j));
        hashMap.put("{USED_VIEWABILITY_TIMER}", String.valueOf(neVar.p0()));
        String emptyIfNull = StringUtils.emptyIfNull(this.a.q0().c());
        if (!((Boolean) this.a.a(sj.R3)).booleanValue()) {
            emptyIfNull = "";
        }
        hashMap.put("{CUID}", emptyIfNull);
        a("mvimp", hashMap, neVar);
    }

    public void processWaterfallInfoPostback(String str, MaxAdFormat maxAdFormat, MaxAdWaterfallInfoImpl maxAdWaterfallInfoImpl, MaxError maxError, long j, long j2) {
        HashMap hashMap = new HashMap();
        CollectionUtils.putStringIfValid("ad_format", maxAdFormat.getLabel(), hashMap);
        CollectionUtils.putStringIfValid("ad_unit_id", str, hashMap);
        CollectionUtils.putStringIfValid("duration_ms", String.valueOf(j2), hashMap);
        if (maxError != null) {
            hashMap.putAll(ma.a(maxError));
        }
        this.a.E().a(la.x, (Map) hashMap);
        if (CollectionUtils.isEmpty(maxAdWaterfallInfoImpl.getPostbackUrls())) {
            return;
        }
        HashMap hashMap2 = new HashMap(8);
        CollectionUtils.putStringIfValid("mcode", maxAdWaterfallInfoImpl.getMCode(), hashMap2);
        CollectionUtils.putStringIfValid("ad_unit_id", str, hashMap2);
        CollectionUtils.putStringIfValid("ad_format", maxAdFormat.getLabel(), hashMap2);
        CollectionUtils.putStringIfValid("name", maxAdWaterfallInfoImpl.getName(), hashMap2);
        CollectionUtils.putLongIfValid("request_latency_ms", Long.valueOf(j2), hashMap2);
        CollectionUtils.putLongIfValid("request_start_timestamp_ms", Long.valueOf(j), hashMap2);
        CollectionUtils.putLongIfValid("wf_latency_ms", Long.valueOf(maxAdWaterfallInfoImpl.getLatencyMillis()), hashMap2);
        List<MaxNetworkResponseInfo> networkResponses = maxAdWaterfallInfoImpl.getNetworkResponses();
        ArrayList arrayList = new ArrayList(networkResponses.size());
        for (MaxNetworkResponseInfo maxNetworkResponseInfo : networkResponses) {
            MaxMediatedNetworkInfo mediatedNetwork = maxNetworkResponseInfo.getMediatedNetwork();
            HashMap hashMap3 = new HashMap(5);
            CollectionUtils.putStringIfValid("bcode", ((MaxNetworkResponseInfoImpl) maxNetworkResponseInfo).getBCode(), hashMap3);
            hashMap3.put("name", mediatedNetwork.getName());
            CollectionUtils.putLongIfValid("latency_ms", Long.valueOf(maxNetworkResponseInfo.getLatencyMillis()), hashMap3);
            hashMap3.put("load_state", Integer.valueOf(maxNetworkResponseInfo.getAdLoadState().ordinal()));
            MaxErrorImpl maxErrorImpl = (MaxErrorImpl) maxNetworkResponseInfo.getError();
            if (maxErrorImpl != null) {
                HashMap hashMap4 = new HashMap(4);
                hashMap4.put("error_code", Integer.valueOf(maxErrorImpl.getCode()));
                hashMap4.put(MAPActorManager.KEY_ERROR_MESSAGE, maxErrorImpl.getMessage());
                hashMap4.put("third_party_sdk_error_code", Integer.valueOf(maxErrorImpl.getMediatedNetworkErrorCode()));
                hashMap4.put("third_party_sdk_error_message", maxErrorImpl.getMediatedNetworkErrorMessage());
                hashMap3.put("error_info", hashMap4);
            }
            arrayList.add(hashMap3);
        }
        hashMap2.put("ads_info", arrayList);
        a("mwf_info", maxAdWaterfallInfoImpl.getPostbackUrls(), Collections.EMPTY_MAP, hashMap2, null, null, false);
    }

    public void setCustomPostBodyData(JSONObject jSONObject) {
        this.d.set(jSONObject);
    }

    public void showFullscreenAd(final ie ieVar, final Activity activity, final a.InterfaceC0105a interfaceC0105a) {
        if (ieVar == null) {
            throw new IllegalArgumentException("No ad specified");
        }
        if (activity == null && MaxAdFormat.APP_OPEN != ieVar.getFormat()) {
            throw new IllegalArgumentException("No activity specified");
        }
        this.a.C().a(true);
        final g b2 = b(ieVar);
        long q0 = ieVar.q0();
        if (com.applovin.impl.sdk.n.a()) {
            this.b.d("MediationService", "Showing ad " + ieVar.getAdUnitId() + " with delay of " + q0 + "ms...");
        }
        AppLovinSdkUtils.runOnUiThreadDelayed(new Runnable() {
            @Override
            public final void run() {
                MediationServiceImpl.this.a(ieVar, b2, activity, interfaceC0105a);
            }
        }, q0);
    }

    public void b(ge geVar, MaxError maxError, MaxAdListener maxAdListener) {
        a(maxError, geVar);
        destroyAd(geVar);
        gc.a(maxAdListener, geVar.getAdUnitId(), maxError);
    }

    private void a(final String str, final MaxAdFormat maxAdFormat, final zj zjVar, Context context, final yj.a aVar, final g gVar) {
        final fi fiVar = new fi();
        final long elapsedRealtime = SystemClock.elapsedRealtime();
        fiVar.a(new fi.b() {
            @Override
            public final void a(boolean z, Object obj, Object obj2) {
                MaxAdFormat maxAdFormat2 = maxAdFormat;
                yj.a aVar2 = aVar;
                MediationServiceImpl.this.a(elapsedRealtime, gVar, str, zjVar, maxAdFormat2, aVar2, z, (String) obj, (MaxError) obj2);
            }
        });
        an.a(zjVar.m(), fiVar, new MaxErrorImpl(MaxAdapterError.ERROR_CODE_SIGNAL_COLLECTION_TIMEOUT, "The adapter (" + zjVar.c() + ") timed out collecting signal"), "MediationService", this.a);
        final g.b bVar = new b(fiVar);
        final Activity n0 = context instanceof Activity ? (Activity) context : this.a.n0();
        final MaxAdapterParametersImpl a2 = MaxAdapterParametersImpl.a(zjVar, str, maxAdFormat);
        if (zjVar.w()) {
            fi a3 = this.a.L().a(zjVar, n0);
            a3.a(new Runnable() {
                @Override
                public final void run() {
                    g.b bVar2 = bVar;
                    MediationServiceImpl.this.a(fiVar, gVar, a2, zjVar, n0, bVar2);
                }
            });
            a3.a((fi.a) new vkb(this, gVar, fiVar));
            return;
        }
        if (zjVar.x()) {
            fi a4 = this.a.L().a(zjVar, n0);
            if (a4.d()) {
                if (com.applovin.impl.sdk.n.a()) {
                    this.b.b("MediationService", "Skip collecting signal for failed-initialized adapter: " + gVar.g());
                }
                fiVar.a(new MaxErrorImpl("Could not initialize adapter: " + ((String) a4.a())));
                return;
            }
        }
        if (com.applovin.impl.sdk.n.a()) {
            this.b.a("MediationService", "Collecting signal for adapter: " + gVar.g());
        }
        gVar.a(a2, zjVar, n0, bVar);
    }

    private g b(ie ieVar) {
        g B = ieVar.B();
        if (B != null) {
            return B;
        }
        this.a.C().a(false);
        if (com.applovin.impl.sdk.n.a()) {
            this.b.k("MediationService", "Failed to show " + ieVar + ": adapter not found");
        }
        com.applovin.impl.sdk.n.h("MediationService", "There may be an integration problem with the adapter for Ad Unit ID '" + ieVar.getAdUnitId() + "'. Please check if you have a supported version of that SDK integrated into your project.");
        throw new IllegalStateException("Could not find adapter for provided ad");
    }

    public void showFullscreenAd(final ie ieVar, final ViewGroup viewGroup, final fba fbaVar, final Activity activity, final a.InterfaceC0105a interfaceC0105a) {
        if (ieVar == null) {
            throw new IllegalArgumentException("No ad specified");
        }
        if (activity != null) {
            this.a.C().a(true);
            final g b2 = b(ieVar);
            long q0 = ieVar.q0();
            if (com.applovin.impl.sdk.n.a()) {
                this.b.d("MediationService", "Showing ad " + ieVar.getAdUnitId() + " with delay of " + q0 + "ms...");
            }
            AppLovinSdkUtils.runOnUiThreadDelayed(new Runnable() {
                @Override
                public final void run() {
                    MediationServiceImpl.this.a(ieVar, b2, viewGroup, fbaVar, activity, interfaceC0105a);
                }
            }, q0);
            return;
        }
        throw new IllegalArgumentException("No activity specified");
    }

    private void a(ie ieVar, a.InterfaceC0105a interfaceC0105a) {
        this.a.C().a(false);
        a(ieVar, (MaxAdListener) interfaceC0105a);
        if (com.applovin.impl.sdk.n.a()) {
            this.b.a("MediationService", "Scheduling impression for ad manually...");
        }
        processRawAdImpression(ieVar, interfaceC0105a);
    }

    public void a(long j, g gVar, String str, zj zjVar, MaxAdFormat maxAdFormat, yj.a aVar, boolean z, String str2, MaxError maxError) {
        yj a2;
        long elapsedRealtime = SystemClock.elapsedRealtime() - j;
        if (z) {
            if (com.applovin.impl.sdk.n.a()) {
                this.b.a("MediationService", "Signal collection successful from: " + gVar.g() + " for Ad Unit ID: " + str + " with signal: \"" + str2 + "\"");
            }
            a2 = yj.a(zjVar, gVar, str2, j, elapsedRealtime);
            this.c.a(a2, zjVar, str, maxAdFormat);
            HashMap hashMap = new HashMap();
            CollectionUtils.putStringIfValid("network_name", zjVar.c(), hashMap);
            CollectionUtils.putStringIfValid("adapter_class", zjVar.b(), hashMap);
            CollectionUtils.putStringIfValid("adapter_version", gVar.b(), hashMap);
            CollectionUtils.putStringIfValid("duration_ms", String.valueOf(elapsedRealtime), hashMap);
            CollectionUtils.putStringIfValid("ad_format", String.valueOf(maxAdFormat.getLabel()), hashMap);
            CollectionUtils.putStringIfValid("ad_unit_id", str, hashMap);
            this.a.E().a(la.p, (Map) hashMap);
        } else {
            if (com.applovin.impl.sdk.n.a()) {
                this.b.b("MediationService", "Signal collection failed from: " + gVar.g() + " for Ad Unit ID: " + str + " with error message: \"" + maxError.getMessage() + "\"");
            }
            a2 = yj.a(zjVar, gVar, maxError, j, elapsedRealtime);
            a(a2, zjVar, gVar);
        }
        aVar.a(a2);
        gVar.a();
    }

    public void a(fi fiVar, g gVar, MaxAdapterParametersImpl maxAdapterParametersImpl, zj zjVar, Activity activity, g.b bVar) {
        if (fiVar.c()) {
            return;
        }
        if (com.applovin.impl.sdk.n.a()) {
            this.b.a("MediationService", "Collecting signal for now-initialized adapter: " + gVar.g());
        }
        gVar.a(maxAdapterParametersImpl, zjVar, activity, bVar);
    }

    public void a(g gVar, String str, MaxAdapterParametersImpl maxAdapterParametersImpl, ge geVar, Activity activity, a.InterfaceC0105a interfaceC0105a) {
        gVar.a(str, maxAdapterParametersImpl, geVar, activity, new d(geVar, interfaceC0105a));
    }

    public void a(ie ieVar, Long l, MaxAdListener maxAdListener) {
        if (ieVar.v().get()) {
            return;
        }
        String str = "Ad (" + ieVar.k() + ") has not been displayed after " + l + "ms. Failing ad display...";
        com.applovin.impl.sdk.n.h("MediationService", str);
        a(ieVar, new MaxErrorImpl(-1, str), maxAdListener);
        this.a.C().b(ieVar);
    }

    public void a(ie ieVar, g gVar, Activity activity, a.InterfaceC0105a interfaceC0105a) {
        ieVar.a(true);
        a(ieVar);
        gVar.c(ieVar, activity);
        a(ieVar, interfaceC0105a);
    }

    public void a(ie ieVar, g gVar, ViewGroup viewGroup, fba fbaVar, Activity activity, a.InterfaceC0105a interfaceC0105a) {
        ieVar.a(true);
        a(ieVar);
        gVar.a(ieVar, viewGroup, fbaVar, activity);
        a(ieVar, interfaceC0105a);
    }

    private void a(final ie ieVar, final MaxAdListener maxAdListener) {
        final Long l = (Long) this.a.a(ve.m7);
        if (l.longValue() <= 0) {
            return;
        }
        AppLovinSdkUtils.runOnUiThreadDelayed(new Runnable() {
            @Override
            public final void run() {
                MediationServiceImpl.this.a(ieVar, l, maxAdListener);
            }
        }, l.longValue());
    }

    private void a(ie ieVar) {
        if (ieVar.getFormat() == MaxAdFormat.REWARDED || ieVar.getFormat() == MaxAdFormat.REWARDED_INTERSTITIAL) {
            this.a.j0().a((yl) new ln(ieVar, this.a), tm.b.OTHER);
        }
    }

    public void a(ge geVar, MaxError maxError, MaxAdListener maxAdListener) {
        this.a.j().a(geVar, e.c.SHOW_ERROR);
        this.a.p().b(geVar, "DID_FAIL_DISPLAY");
        a(maxError, geVar, true);
        if (geVar.v().compareAndSet(false, true)) {
            gc.a(maxAdListener, geVar, maxError);
        }
    }

    public void a(ge geVar, a.InterfaceC0105a interfaceC0105a) {
        this.a.p().b(geVar, "DID_CLICKED");
        this.a.p().b(geVar, "DID_CLICK");
        if (geVar.R().endsWith("click")) {
            this.a.p().b(geVar);
            gc.a((MaxAdRevenueListener) interfaceC0105a, (MaxAd) geVar);
        }
        HashMap hashMap = new HashMap(1);
        String emptyIfNull = StringUtils.emptyIfNull(this.a.q0().c());
        if (!((Boolean) this.a.a(sj.R3)).booleanValue()) {
            emptyIfNull = "";
        }
        hashMap.put("{CUID}", emptyIfNull);
        a("mclick", hashMap, geVar);
    }

    private void a(MaxError maxError, ge geVar, boolean z) {
        a("mierr", Collections.EMPTY_MAP, maxError, geVar, z);
        if (!z || geVar == null) {
            return;
        }
        this.a.E().a(la.z, geVar, maxError);
    }

    private void a(MaxError maxError, ge geVar) {
        HashMap hashMap = new HashMap(3);
        long H = geVar.H();
        hashMap.put("{LOAD_TIME_MS}", String.valueOf(H));
        if (geVar.getFormat().isFullscreenAd()) {
            m.a b2 = this.a.C().b(geVar.getAdUnitId());
            hashMap.put("{SHOW_ATTEMPT_COUNT}", String.valueOf(b2.a()));
            hashMap.put("{SHOW_ATTEMPT_TIMESTAMP_MS}", String.valueOf(b2.b()));
        }
        a("mlerr", hashMap, maxError, geVar);
        Map a2 = ma.a(geVar);
        a2.putAll(ma.a(maxError));
        a2.put("duration_ms", String.valueOf(H));
        this.a.E().a(la.w, a2);
    }

    public void a(ge geVar) {
        this.a.p().b(geVar, "DID_LOAD");
        if (geVar.R().endsWith("load")) {
            this.a.p().b(geVar);
        }
        HashMap hashMap = new HashMap(3);
        long H = geVar.H();
        hashMap.put("{LOAD_TIME_MS}", String.valueOf(H));
        if (geVar.getFormat().isFullscreenAd()) {
            m.a b2 = this.a.C().b(geVar.getAdUnitId());
            hashMap.put("{SHOW_ATTEMPT_COUNT}", String.valueOf(b2.a()));
            hashMap.put("{SHOW_ATTEMPT_TIMESTAMP_MS}", String.valueOf(b2.b()));
        }
        a("load", hashMap, geVar);
        Map a2 = ma.a(geVar);
        a2.put("duration_ms", String.valueOf(H));
        this.a.E().a(la.v, a2);
    }

    public void a(yj yjVar, zj zjVar, g gVar) {
        long b2 = yjVar.b();
        HashMap hashMap = new HashMap(3);
        hashMap.put("{LOAD_TIME_MS}", String.valueOf(b2));
        CollectionUtils.putStringIfValid("{ADAPTER_VERSION}", gVar.b(), hashMap);
        CollectionUtils.putStringIfValid("{SDK_VERSION}", gVar.i(), hashMap);
        a("serr", hashMap, yjVar.c(), zjVar);
        HashMap hashMap2 = new HashMap();
        CollectionUtils.putStringIfValid("network_name", zjVar.c(), hashMap2);
        CollectionUtils.putStringIfValid("adapter_class", zjVar.b(), hashMap2);
        CollectionUtils.putStringIfValid("adapter_version", gVar.b(), hashMap2);
        CollectionUtils.putStringIfValid("duration_ms", String.valueOf(b2), hashMap2);
        this.a.E().a(la.q, (Map) hashMap2);
    }

    private void a(String str, List list, Map map, Map map2, MaxError maxError, pe peVar, boolean z) {
        this.a.j0().a((yl) new rm(str, list, map, map2, maxError, peVar, this.a, z), tm.b.OTHER);
    }

    private void a(String str, Map map, pe peVar) {
        a(str, map, (MaxError) null, peVar);
    }

    private void a(String str, Map map, MaxError maxError, pe peVar) {
        a(str, map, maxError, peVar, true);
    }

    private void a(String str, Map map, MaxError maxError, pe peVar, boolean z) {
        String str2;
        Map map2 = CollectionUtils.map(map);
        String str3 = "";
        map2.put("{PLACEMENT}", z ? StringUtils.emptyIfNull(peVar.getPlacement()) : "");
        if (!z) {
            str2 = "";
        } else {
            str2 = StringUtils.emptyIfNull(peVar.e());
        }
        map2.put("{CUSTOM_DATA}", str2);
        if (peVar instanceof ge) {
            ge geVar = (ge) peVar;
            if (z) {
                str3 = StringUtils.emptyIfNull(geVar.getCreativeId());
            }
            map2.put("{CREATIVE_ID}", str3);
        }
        a(str, null, map2, null, maxError, peVar, z);
    }

    public void a(ge geVar, a.InterfaceC0105a interfaceC0105a, String str) {
        String str2 = "Failed to load " + geVar + ": adapter init failed with error: " + str;
        if (com.applovin.impl.sdk.n.a()) {
            this.b.k("MediationService", str2);
        }
        b(geVar, new MaxErrorImpl(MaxAdapterError.NOT_INITIALIZED.getErrorCode(), "Adapter initialization failed"), interfaceC0105a);
    }

    public void a(g gVar, fi fiVar, String str) {
        if (com.applovin.impl.sdk.n.a()) {
            this.b.b("MediationService", "Skip collecting signal for failed-initialized adapter: " + gVar.g());
        }
        fiVar.a(new MaxErrorImpl(MaxAdapterError.ERROR_CODE_NOT_INITIALIZED, bl0.c("Could not initialize adapter: ", str)));
    }
}