导航菜单

页面标题

页面副标题

Handling Master v2 - MediationServiceImpl.java 源代码

正在查看: Handling Master v2 应用的 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 androidx.annotation.Nullable;
import androidx.lifecycle.Lifecycle;
import com.applovin.impl.a2;
import com.applovin.impl.a3;
import com.applovin.impl.b6;
import com.applovin.impl.g3;
import com.applovin.impl.g4;
import com.applovin.impl.h3;
import com.applovin.impl.h6;
import com.applovin.impl.i3;
import com.applovin.impl.l2;
import com.applovin.impl.l4;
import com.applovin.impl.mediation.ads.a;
import com.applovin.impl.mediation.d;
import com.applovin.impl.p4;
import com.applovin.impl.p5;
import com.applovin.impl.q2;
import com.applovin.impl.q4;
import com.applovin.impl.r4;
import com.applovin.impl.r5;
import com.applovin.impl.sdk.AppLovinBroadcastManager;
import com.applovin.impl.sdk.g;
import com.applovin.impl.sdk.j;
import com.applovin.impl.sdk.m;
import com.applovin.impl.sdk.n;
import com.applovin.impl.sdk.utils.CollectionUtils;
import com.applovin.impl.sdk.utils.StringUtils;
import com.applovin.impl.t2;
import com.applovin.impl.v1;
import com.applovin.impl.w5;
import com.applovin.impl.y1;
import com.applovin.impl.y2;
import com.applovin.impl.z6;
import com.applovin.mediation.MaxAd;
import com.applovin.mediation.MaxAdFormat;
import com.applovin.mediation.MaxAdListener;
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.mediation.adapter.parameters.MaxAdapterResponseParameters;
import com.applovin.mediation.adapter.parameters.MaxAdapterSignalCollectionParameters;
import com.applovin.sdk.AppLovinSdkUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicReference;
import org.json.JSONObject;

public class MediationServiceImpl implements AppLovinBroadcastManager.Receiver {
    private final j a;
    private final n b;
    private final p4 c;
    private final AtomicReference d = new AtomicReference();

    public static class a {
        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 b implements MaxAdListener, MaxRewardedAdListener, MaxAdViewAdListener, MaxAdRevenueListener, a.InterfaceC0056a {
        private final q2 a;
        private a.InterfaceC0056a b;

        public b(q2 q2Var, a.InterfaceC0056a interfaceC0056a) {
            this.a = q2Var;
            this.b = interfaceC0056a;
        }

        public void a(a.InterfaceC0056a interfaceC0056a) {
            this.b = interfaceC0056a;
        }

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

        public void c(MaxAd maxAd, Bundle bundle) {
            this.a.a(bundle);
            n unused = MediationServiceImpl.this.b;
            if (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(g3.y7)).booleanValue() || this.a.u().compareAndSet(false, true)) {
                MediationServiceImpl.this.a.l().a(this.a, g.c.SHOW);
                MediationServiceImpl.this.a.E().c(v1.f);
                MediationServiceImpl.this.a.E().c(v1.i);
                MediationServiceImpl.this.a.r().b(this.a, "DID_DISPLAY");
                MediationServiceImpl.this.a.o().maybeSendAdEvent(this.a, "DID_DISPLAY");
                if (maxAd.getFormat().isFullscreenAd()) {
                    MediationServiceImpl.this.a.D().a(this.a);
                }
                l2.c(this.b, maxAd);
            }
        }

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

        public void e(MaxAd maxAd, Bundle bundle) {
            this.a.a(bundle);
            MediationServiceImpl.this.a.J().a(y1.W, this.a);
            MediationServiceImpl.this.a.l().a(this.a, g.c.HIDE);
            q2 q2Var = (q2) maxAd;
            MediationServiceImpl.this.a.r().b(q2Var, "DID_HIDE");
            MediationServiceImpl.this.a.o().maybeSendAdEvent(q2Var, "DID_HIDE");
            AppLovinSdkUtils.runOnUiThreadDelayed(new I1IILIil1lLlL(this, maxAd), maxAd instanceof t2 ? ((t2) maxAd).d0() : 0L);
        }

        public void f(MaxAd maxAd, Bundle bundle) {
            this.a.a(bundle);
            this.a.W();
            MediationServiceImpl.this.a.l().a(this.a, g.c.LOAD);
            MediationServiceImpl.this.a(this.a);
            l2.f(this.b, maxAd);
        }

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

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

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

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

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

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

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

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

        @Override
        public void onAdRequestStarted(String str) {
        }

        public void onAdRevenuePaid(MaxAd maxAd) {
        }

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

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

        public void a(MaxAd maxAd, Bundle bundle) {
            this.a.a(bundle);
            MediationServiceImpl.this.a.l().a(this.a, g.c.CLICK);
            MediationServiceImpl.this.a(this.a, this.b);
            l2.a(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 instanceof t2)) {
                ((t2) maxAd).b0();
            }
        }

        public void a(MaxAd maxAd, MaxReward maxReward, Bundle bundle) {
            this.a.a(bundle);
            l2.a(this.b, maxAd, maxReward);
            MediationServiceImpl.this.a.j0().a(new b6((t2) maxAd, MediationServiceImpl.this.a), r5.b.OTHER);
        }
    }

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

    public void collectSignal(final String str, final MaxAdFormat maxAdFormat, final r4 r4Var, Context context, final q4.a aVar) {
        if (r4Var == 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");
        }
        q4 b2 = this.c.b(r4Var, str, maxAdFormat);
        if (b2 != null) {
            aVar.a(q4.a(b2));
            return;
        }
        final g a2 = this.a.M().a(r4Var, r4Var.z());
        if (a2 == null) {
            aVar.a(q4.a(r4Var, new MaxErrorImpl("Could not load adapter")));
            return;
        }
        g4 g4Var = new g4("SignalCollection:" + r4Var.c());
        final long elapsedRealtime = SystemClock.elapsedRealtime();
        Executor executor = g4.i;
        g4Var.a(executor, new g4.b() {
            public final void a(boolean z, Object obj, Object obj2) {
                MediationServiceImpl.this.a(elapsedRealtime, a2, str, r4Var, maxAdFormat, aVar, z, (String) obj, (MaxError) obj2);
            }
        });
        w5.a(r4Var.m(), g4Var, new MaxErrorImpl(MaxAdapterError.ERROR_CODE_SIGNAL_COLLECTION_TIMEOUT, "The adapter (" + r4Var.c() + ") timed out collecting signal"), "MediationService", this.a);
        Activity n0 = context instanceof Activity ? (Activity) context : this.a.n0();
        MaxAdapterParametersImpl a3 = MaxAdapterParametersImpl.a(r4Var, str, maxAdFormat);
        if (r4Var.v()) {
            g4 a4 = this.a.L().a(r4Var, n0);
            a4.a(executor, new ILIlil1Lii(this, g4Var, a2, a3, r4Var, n0));
            a4.a(executor, new Ii1ILILlilI(this, a2, g4Var));
            return;
        }
        if (r4Var.w()) {
            g4 a5 = this.a.L().a(r4Var, n0);
            if (a5.d() && !r4Var.y()) {
                if (n.a()) {
                    this.b.b("MediationService", "Skip collecting signal for failed-initialized adapter: " + a2.g());
                }
                g4Var.a(new MaxErrorImpl("Could not initialize adapter: " + ((String) a5.a())));
                return;
            }
        }
        if (n.a()) {
            this.b.a("MediationService", "Collecting signal for adapter: " + a2.g());
        }
        a2.a((MaxAdapterSignalCollectionParameters) a3, r4Var, n0, g4Var);
    }

    public void destroyAd(MaxAd maxAd) {
        if (maxAd instanceof q2) {
            if (n.a()) {
                this.b.d("MediationService", "Destroying " + maxAd);
            }
            q2 q2Var = (q2) maxAd;
            g A = q2Var.A();
            if (A != null) {
                A.a();
                q2Var.t();
            }
            this.a.j().c(q2Var.N());
            this.a.l().a(q2Var, g.c.DESTROY);
        }
    }

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

    public void loadAd(String str, @Nullable String str2, MaxAdFormat maxAdFormat, d.b bVar, Map<String, Object> map, Map<String, Object> map2, Context context, a.InterfaceC0056a interfaceC0056a) {
        if (TextUtils.isEmpty(str)) {
            throw new IllegalArgumentException("No Ad Unit ID specified");
        }
        if (context == null) {
            throw new IllegalArgumentException("No context specified");
        }
        if (interfaceC0056a == null) {
            throw new IllegalArgumentException("No listener specified");
        }
        if (TextUtils.isEmpty(this.a.O())) {
            n.h("AppLovinSdk", "Mediation provider is null. Please set the mediation provider in the AppLovinSdkInitializationConfiguration.Builder when initializing the AppLovinSDK.");
        }
        if (!this.a.u0()) {
            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> adUnitIds = this.a.G() != null ? this.a.G().getAdUnitIds() : null;
        boolean startsWith = str.startsWith("test_mode");
        if (adUnitIds != null && adUnitIds.size() > 0 && !adUnitIds.contains(str) && !startsWith) {
            if (z6.c(this.a)) {
                String str3 = "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/max/android/overview/advanced-settings#selective-init";
                if (((Boolean) this.a.a(l4.P5)).booleanValue()) {
                    throw new RuntimeException(str3);
                }
                if (n.a()) {
                    this.b.b("MediationService", str3);
                }
            }
            this.a.A().a(y1.o0, "uninitialized_ad_unit_id", CollectionUtils.hashMap("ad_unit_id", str), "uninitialized_ad_unit_id" + str);
        }
        this.a.c();
        if (str.length() != 16 && !startsWith && !this.a.b0().startsWith("05TMD")) {
            n.h("MediationService", "Ad unit ID provided for " + maxAdFormat.getLabel() + " is invalid (" + str + "). Expected length: 16 characters.\n\nStack trace:\n" + Log.getStackTraceString(new Throwable()));
        }
        if (!this.a.a(maxAdFormat)) {
            this.a.O0();
            l2.a(interfaceC0056a, str, true);
            this.a.K().a(str, str2, maxAdFormat, bVar, map, map2, context, interfaceC0056a);
            return;
        }
        n.h("MediationService", "Ad load failed due to disabled ad format " + maxAdFormat.getLabel());
        l2.a(interfaceC0056a, str, new MaxErrorImpl(-1, "Disabled ad format " + maxAdFormat.getLabel()));
    }

    public void loadThirdPartyMediatedAd(String str, q2 q2Var, Activity activity, a.InterfaceC0056a interfaceC0056a) {
        g4 g4Var;
        if (q2Var == null) {
            throw new IllegalArgumentException("No mediated ad specified");
        }
        if (n.a()) {
            this.b.a("MediationService", "Loading " + q2Var + "...");
        }
        this.a.J().a(y1.O, q2Var);
        this.a.l().a(q2Var, g.c.LOADING);
        this.a.r().b(q2Var, "WILL_LOAD");
        this.a.o().maybeSendAdEvent(q2Var, "WILL_LOAD");
        g a2 = this.a.M().a(q2Var);
        if (a2 == null) {
            String str2 = "Failed to load " + q2Var + ": adapter not loaded";
            n.h("MediationService", str2);
            b(q2Var, new MaxErrorImpl(-5001, str2), interfaceC0056a);
            return;
        }
        MaxAdapterParametersImpl a3 = MaxAdapterParametersImpl.a(q2Var);
        if (q2Var.U()) {
            g4Var = this.a.L().a(q2Var, activity);
        } else {
            if (q2Var.V()) {
                this.a.L().a(q2Var, activity);
            }
            g4Var = null;
        }
        g4 g4Var2 = g4Var;
        q2 a4 = q2Var.a(a2);
        a2.a(str, a4);
        a4.X();
        if (g4Var2 == null) {
            a2.a(str, (MaxAdapterResponseParameters) a3, a4, activity, new b(a4, interfaceC0056a));
            return;
        }
        Executor executor = g4.i;
        g4Var2.a(executor, new I11lllll1ILI1(this, q2Var, interfaceC0056a));
        g4Var2.a(executor, new I1IIiIII(this, a2, str, a3, a4, activity, interfaceC0056a));
    }

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

    public void processAdDisplayErrorPostbackForUserError(MaxError maxError, q2 q2Var) {
        a(maxError, q2Var, false);
    }

    public void processAdapterInitializationPostback(a3 a3Var, 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), a3Var);
        Map a2 = a2.a(a3Var);
        CollectionUtils.putStringIfValid("adapter_init_status", String.valueOf(initializationStatus.getCode()), a2);
        CollectionUtils.putStringIfValid("error_message", str, a2);
        CollectionUtils.putStringIfValid("duration_ms", String.valueOf(j), a2);
        switch (a.a[initializationStatus.ordinal()]) {
            case 1:
            case 2:
            case 3:
                this.a.J().d(y1.H, a2);
                break;
            case 4:
                this.a.J().d(y1.I, a2);
                break;
            case 5:
            case 6:
                this.a.I();
                if (n.a()) {
                    this.a.I().k("MediationService", "Adapter init postback called while the adapter is not fully initialized.");
                }
                this.a.A().a(y1.d, "adapterNotInitializedForPostback", a2);
                break;
        }
    }

    public void processCallbackAdImpressionPostback(q2 q2Var, a.InterfaceC0056a interfaceC0056a) {
        if (q2Var.L().endsWith("cimp")) {
            this.a.r().b(q2Var);
            l2.a(interfaceC0056a, q2Var);
        }
        HashMap hashMap = new HashMap(1);
        String emptyIfNull = StringUtils.emptyIfNull(this.a.p0().c());
        if (!((Boolean) this.a.a(l4.t3)).booleanValue()) {
            emptyIfNull = "";
        }
        hashMap.put("{CUID}", emptyIfNull);
        a("mcimp", hashMap, q2Var);
        this.a.J().a(y1.T, q2Var);
    }

    public void processRawAdImpression(q2 q2Var, a.InterfaceC0056a interfaceC0056a) {
        this.a.r().b(q2Var, "WILL_DISPLAY");
        this.a.o().maybeSendAdEvent(q2Var, "WILL_DISPLAY");
        if (q2Var.L().endsWith("mimp")) {
            this.a.r().b(q2Var);
            l2.a(interfaceC0056a, q2Var);
        }
        if (((Boolean) this.a.a(l4.h4)).booleanValue()) {
            this.a.R().a(h3.d, i3.a(q2Var), Long.valueOf(System.currentTimeMillis() - this.a.H()));
        }
        HashMap hashMap = new HashMap(2);
        if (q2Var instanceof t2) {
            hashMap.put("{TIME_TO_SHOW_MS}", String.valueOf(((t2) q2Var).h0()));
        }
        String emptyIfNull = StringUtils.emptyIfNull(this.a.p0().c());
        if (!((Boolean) this.a.a(l4.t3)).booleanValue()) {
            emptyIfNull = "";
        }
        hashMap.put("{CUID}", emptyIfNull);
        a("mimp", hashMap, q2Var);
        this.a.J().a(y1.S, q2Var);
    }

    public void processViewabilityAdImpressionPostback(y2 y2Var, long j, a.InterfaceC0056a interfaceC0056a) {
        if (y2Var.L().endsWith("vimp")) {
            this.a.r().b(y2Var);
            l2.a(interfaceC0056a, y2Var);
        }
        HashMap hashMap = new HashMap(3);
        hashMap.put("{VIEWABILITY_FLAGS}", String.valueOf(j));
        hashMap.put("{USED_VIEWABILITY_TIMER}", String.valueOf(y2Var.i0()));
        String emptyIfNull = StringUtils.emptyIfNull(this.a.p0().c());
        if (!((Boolean) this.a.a(l4.t3)).booleanValue()) {
            emptyIfNull = "";
        }
        hashMap.put("{CUID}", emptyIfNull);
        a("mvimp", hashMap, y2Var);
        this.a.J().a(y1.U, y2Var);
    }

    public void processWaterfallInfoPostback(String str, MaxAdFormat maxAdFormat, MaxAdWaterfallInfoImpl maxAdWaterfallInfoImpl, @Nullable 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(a2.a(maxError));
        }
        this.a.J().d(y1.R, 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 error = maxNetworkResponseInfo.getError();
            if (error != null) {
                HashMap hashMap4 = new HashMap(4);
                hashMap4.put("error_code", Integer.valueOf(error.getCode()));
                hashMap4.put("error_message", error.getMessage());
                hashMap4.put("third_party_sdk_error_code", Integer.valueOf(error.getMediatedNetworkErrorCode()));
                hashMap4.put("third_party_sdk_error_message", error.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 t2 t2Var, final Activity activity, final a.InterfaceC0056a interfaceC0056a) {
        if (t2Var == null) {
            throw new IllegalArgumentException("No ad specified");
        }
        if (activity == null && MaxAdFormat.APP_OPEN != t2Var.getFormat()) {
            throw new IllegalArgumentException("No activity specified");
        }
        this.a.D().a(true);
        final g b2 = b(t2Var);
        long j0 = t2Var.j0();
        if (n.a()) {
            this.b.d("MediationService", "Showing ad " + t2Var.getAdUnitId() + " with delay of " + j0 + "ms...");
        }
        AppLovinSdkUtils.runOnUiThreadDelayed(new Runnable() {
            @Override
            public final void run() {
                MediationServiceImpl.this.a(t2Var, b2, activity, interfaceC0056a);
            }
        }, j0);
    }

    private g b(t2 t2Var) {
        g A = t2Var.A();
        if (A != null) {
            return A;
        }
        this.a.D().a(false);
        if (n.a()) {
            this.b.k("MediationService", "Failed to show " + t2Var + ": adapter not found");
        }
        n.h("MediationService", "There may be an integration problem with the adapter for Ad Unit ID '" + t2Var.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 a(t2 t2Var, g gVar, Activity activity, a.InterfaceC0056a interfaceC0056a) {
        a(t2Var);
        gVar.b(t2Var, activity);
        a(t2Var, interfaceC0056a);
    }

    public void a(t2 t2Var, g gVar, ViewGroup viewGroup, Lifecycle lifecycle, Activity activity, a.InterfaceC0056a interfaceC0056a) {
        a(t2Var);
        gVar.a(t2Var, viewGroup, lifecycle, activity);
        a(t2Var, interfaceC0056a);
    }

    public void b(q2 q2Var, MaxError maxError, MaxAdListener maxAdListener) {
        a(maxError, q2Var);
        destroyAd(q2Var);
        l2.a(maxAdListener, q2Var.getAdUnitId(), maxError);
    }

    public void showFullscreenAd(final t2 t2Var, final ViewGroup viewGroup, final Lifecycle lifecycle, final Activity activity, final a.InterfaceC0056a interfaceC0056a) {
        if (t2Var == null) {
            throw new IllegalArgumentException("No ad specified");
        }
        if (activity != null) {
            this.a.D().a(true);
            final g b2 = b(t2Var);
            long j0 = t2Var.j0();
            if (n.a()) {
                this.b.d("MediationService", "Showing ad " + t2Var.getAdUnitId() + " with delay of " + j0 + "ms...");
            }
            AppLovinSdkUtils.runOnUiThreadDelayed(new Runnable() {
                @Override
                public final void run() {
                    MediationServiceImpl.this.a(t2Var, b2, viewGroup, lifecycle, activity, interfaceC0056a);
                }
            }, j0);
            return;
        }
        throw new IllegalArgumentException("No activity specified");
    }

    private void a(t2 t2Var) {
        if (t2Var.getFormat() == MaxAdFormat.REWARDED) {
            this.a.j0().a(new h6(t2Var, this.a), r5.b.OTHER);
        }
    }

    private void a(t2 t2Var, a.InterfaceC0056a interfaceC0056a) {
        this.a.D().a(false);
        a(t2Var, (MaxAdListener) interfaceC0056a);
        if (n.a()) {
            this.b.a("MediationService", "Scheduling impression for ad manually...");
        }
        processRawAdImpression(t2Var, interfaceC0056a);
    }

    public void a(q2 q2Var, a.InterfaceC0056a interfaceC0056a, String str) {
        String str2 = "Failed to load " + q2Var + ": adapter init failed with error: " + str;
        if (n.a()) {
            this.b.k("MediationService", str2);
        }
        b(q2Var, new MaxErrorImpl(MaxAdapterError.NOT_INITIALIZED.getErrorCode(), "Adapter initialization failed"), interfaceC0056a);
    }

    public void a(g gVar, String str, MaxAdapterParametersImpl maxAdapterParametersImpl, q2 q2Var, Activity activity, a.InterfaceC0056a interfaceC0056a) {
        gVar.a(str, (MaxAdapterResponseParameters) maxAdapterParametersImpl, q2Var, activity, new b(q2Var, interfaceC0056a));
    }

    public void a(long j, g gVar, String str, r4 r4Var, MaxAdFormat maxAdFormat, q4.a aVar, boolean z, String str2, MaxError maxError) {
        q4 a2;
        long elapsedRealtime = SystemClock.elapsedRealtime() - j;
        if (z) {
            if (n.a()) {
                this.b.a("MediationService", "Signal collection successful from: " + gVar.g() + " for Ad Unit ID: " + str + " with signal: \"" + str2 + "\"");
            }
            a2 = q4.a(r4Var, gVar, str2, j, elapsedRealtime);
            this.c.a(a2, r4Var, str, maxAdFormat);
            HashMap hashMap = new HashMap();
            CollectionUtils.putStringIfValid("network_name", r4Var.c(), hashMap);
            CollectionUtils.putStringIfValid("adapter_class", r4Var.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.J().d(y1.J, hashMap);
        } else {
            if (n.a()) {
                this.b.b("MediationService", "Signal collection failed from: " + gVar.g() + " for Ad Unit ID: " + str + " with error message: \"" + maxError.getMessage() + "\"");
            }
            a2 = q4.a(r4Var, gVar, maxError, j, elapsedRealtime);
            a(a2, r4Var, gVar);
        }
        aVar.a(a2);
        gVar.a();
    }

    public void a(g4 g4Var, g gVar, MaxAdapterParametersImpl maxAdapterParametersImpl, r4 r4Var, Activity activity) {
        if (g4Var.c()) {
            return;
        }
        if (n.a()) {
            this.b.a("MediationService", "Collecting signal for now-initialized adapter: " + gVar.g());
        }
        gVar.a((MaxAdapterSignalCollectionParameters) maxAdapterParametersImpl, r4Var, activity, g4Var);
    }

    public void a(g gVar, g4 g4Var, String str) {
        if (n.a()) {
            this.b.b("MediationService", "Skip collecting signal for failed-initialized adapter: " + gVar.g());
        }
        g4Var.a(new MaxErrorImpl(MaxAdapterError.ERROR_CODE_NOT_INITIALIZED, "Could not initialize adapter: " + str));
    }

    private void a(t2 t2Var, MaxAdListener maxAdListener) {
        Long l = (Long) this.a.a(g3.c7);
        if (l.longValue() <= 0) {
            return;
        }
        AppLovinSdkUtils.runOnUiThreadDelayed(new IL1lI11I(this, t2Var, l, maxAdListener), l.longValue());
    }

    public void a(t2 t2Var, Long l, MaxAdListener maxAdListener) {
        if (t2Var.u().get()) {
            return;
        }
        String str = "Ad (" + t2Var.k() + ") has not been displayed after " + l + "ms. Failing ad display...";
        n.h("MediationService", str);
        a((q2) t2Var, (MaxError) new MaxErrorImpl(-1, str), maxAdListener);
        this.a.D().b(t2Var);
    }

    public void a(q2 q2Var, MaxError maxError, MaxAdListener maxAdListener) {
        this.a.l().a(q2Var, g.c.SHOW_ERROR);
        this.a.r().b(q2Var, "DID_FAIL_DISPLAY");
        this.a.o().maybeSendAdEvent(q2Var, "DID_FAIL_DISPLAY");
        a(maxError, q2Var, true);
        if (q2Var.u().compareAndSet(false, true)) {
            l2.a(maxAdListener, q2Var, maxError);
        }
    }

    public void a(q2 q2Var) {
        this.a.r().b(q2Var, "DID_LOAD");
        this.a.o().maybeSendAdEvent(q2Var, "DID_LOAD");
        if (q2Var.L().endsWith("load")) {
            this.a.r().b(q2Var);
        }
        HashMap hashMap = new HashMap(3);
        long G = q2Var.G();
        hashMap.put("{LOAD_TIME_MS}", String.valueOf(G));
        if (q2Var.getFormat().isFullscreenAd()) {
            m.a b2 = this.a.D().b(q2Var.getAdUnitId());
            hashMap.put("{SHOW_ATTEMPT_COUNT}", String.valueOf(b2.a()));
            hashMap.put("{SHOW_ATTEMPT_TIMESTAMP_MS}", String.valueOf(b2.b()));
        }
        a("load", hashMap, q2Var);
        Map a2 = a2.a(q2Var);
        a2.put("duration_ms", String.valueOf(G));
        this.a.J().d(y1.P, a2);
    }

    private void a(MaxError maxError, q2 q2Var) {
        HashMap hashMap = new HashMap(3);
        long G = q2Var.G();
        hashMap.put("{LOAD_TIME_MS}", String.valueOf(G));
        if (q2Var.getFormat().isFullscreenAd()) {
            m.a b2 = this.a.D().b(q2Var.getAdUnitId());
            hashMap.put("{SHOW_ATTEMPT_COUNT}", String.valueOf(b2.a()));
            hashMap.put("{SHOW_ATTEMPT_TIMESTAMP_MS}", String.valueOf(b2.b()));
        }
        a("mlerr", hashMap, maxError, q2Var);
        Map a2 = a2.a(q2Var);
        a2.putAll(a2.a(maxError));
        a2.put("duration_ms", String.valueOf(G));
        this.a.J().d(y1.Q, a2);
    }

    public void a(q2 q2Var, a.InterfaceC0056a interfaceC0056a) {
        this.a.r().b(q2Var, "DID_CLICKED");
        this.a.r().b(q2Var, "DID_CLICK");
        this.a.o().maybeSendAdEvent(q2Var, "DID_CLICK");
        if (q2Var.L().endsWith("click")) {
            this.a.r().b(q2Var);
            l2.a(interfaceC0056a, q2Var);
        }
        HashMap hashMap = new HashMap(1);
        String emptyIfNull = StringUtils.emptyIfNull(this.a.p0().c());
        if (!((Boolean) this.a.a(l4.t3)).booleanValue()) {
            emptyIfNull = "";
        }
        hashMap.put("{CUID}", emptyIfNull);
        a("mclick", hashMap, q2Var);
    }

    private void a(MaxError maxError, q2 q2Var, boolean z) {
        a("mierr", Collections.EMPTY_MAP, maxError, q2Var, z);
        if (!z || q2Var == null) {
            return;
        }
        this.a.J().a(y1.V, q2Var, maxError);
    }

    private void a(q4 q4Var, r4 r4Var, g gVar) {
        long b2 = q4Var.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, q4Var.c(), r4Var);
        Map a2 = a2.a(q4Var.c());
        CollectionUtils.putStringIfValid("network_name", r4Var.c(), a2);
        CollectionUtils.putStringIfValid("adapter_class", r4Var.b(), a2);
        CollectionUtils.putStringIfValid("adapter_version", gVar.b(), a2);
        CollectionUtils.putStringIfValid("duration_ms", String.valueOf(b2), a2);
        this.a.J().d(y1.K, a2);
    }

    private void a(String str, Map map, a3 a3Var) {
        a(str, map, (MaxError) null, a3Var);
    }

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

    private void a(String str, Map map, MaxError maxError, a3 a3Var, boolean z) {
        Map map2 = CollectionUtils.map(map);
        map2.put("{PLACEMENT}", z ? StringUtils.emptyIfNull(a3Var.getPlacement()) : "");
        map2.put("{CUSTOM_DATA}", z ? StringUtils.emptyIfNull(a3Var.e()) : "");
        if (a3Var instanceof q2) {
            map2.put("{CREATIVE_ID}", z ? StringUtils.emptyIfNull(((q2) a3Var).getCreativeId()) : "");
        }
        a(str, null, map2, null, maxError, a3Var, z);
    }

    private void a(String str, List list, Map map, Map map2, MaxError maxError, a3 a3Var, boolean z) {
        this.a.j0().a(new p5(str, list, map, map2, maxError, a3Var, this.a, z), r5.b.OTHER);
    }
}