Picsart v24.6版本的 MD5 值为:21a61631d94e54da68d2ad9268b8b9d9

以下内容为反编译后的 VungleApiClient.java 源代码,内容仅作参考


package com.vungle.ads.internal.network;

import android.app.UiModeManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.PowerManager;
import android.security.NetworkSecurityPolicy;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
import android.webkit.URLUtil;
import com.amazon.device.ads.DTBMetricsConfiguration;
import com.amazon.device.ads.DtbConstants;
import com.applovin.sdk.AppLovinEventTypes;
import com.google.android.gms.common.GoogleApiAvailabilityLight;
import com.google.android.gms.vision.barcode.Barcode;
import com.vungle.ads.AnalyticsClient;
import com.vungle.ads.VungleAds;
import com.vungle.ads.internal.load.BaseAdLoader;
import com.vungle.ads.internal.privacy.COPPA;
import com.vungle.ads.internal.protos.Sdk$MetricBatch;
import com.vungle.ads.internal.protos.Sdk$SDKError;
import com.vungle.ads.internal.protos.Sdk$SDKErrorBatch;
import com.vungle.ads.internal.protos.Sdk$SDKMetric;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.SocketAddress;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import myobfuscated.ej2.c0;
import myobfuscated.ej2.k;
import myobfuscated.fo2.c;
import myobfuscated.jk2.n;
import myobfuscated.kj2.e;
import myobfuscated.kj2.g;
import myobfuscated.ko2.m;
import myobfuscated.ko2.n;
import myobfuscated.wj2.i;
import myobfuscated.yo2.e0;
import myobfuscated.yo2.h;
import myobfuscated.yo2.r;
import myobfuscated.yo2.y;
import okhttp3.Protocol;
import okhttp3.h;
import okhttp3.i;
import okhttp3.k;
import okhttp3.o;
import okhttp3.p;
import okhttp3.q;
import org.jetbrains.annotations.NotNull;
public final class VungleApiClient {
    @NotNull
    private static final String BASE_URL;
    @NotNull
    public static final a Companion;
    @NotNull
    private static final String MANUFACTURER_AMAZON = "Amazon";
    @NotNull
    private static final String TAG = "VungleApiClient";
    private static VungleAds.WrapperFramework WRAPPER_FRAMEWORK_SELECTED;
    @NotNull
    private static String headerUa;
    @NotNull
    private static final myobfuscated.fo2.a json;
    @NotNull
    private static final Set<m> logInterceptors;
    @NotNull
    private static final Set<m> networkInterceptors;
    @NotNull
    private VungleApi api;
    private myobfuscated.kj2.c appBody;
    private String appSetId;
    @NotNull
    private final Context applicationContext;
    private g baseDeviceInfo;
    @NotNull
    private final myobfuscated.oj2.a filePreferences;
    @NotNull
    private VungleApi gzipApi;
    private Boolean isGooglePlayServicesAvailable;
    @NotNull
    private final myobfuscated.pj2.b platform;
    @NotNull
    private m responseInterceptor;
    @NotNull
    private Map<String, Long> retryAfterDataMap;
    private String uaString;

    public static final class a {
        private a() {
        }

        public a(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        public final String defaultHeader() {
            return (Intrinsics.c("Amazon", Build.MANUFACTURER) ? "VungleAmazon/" : "VungleDroid/").concat(k.VERSION_NAME);
        }

        @NotNull
        public final String getBASE_URL$vungle_ads_release() {
            return VungleApiClient.BASE_URL;
        }

        @NotNull
        public final String getHeaderUa() {
            return VungleApiClient.headerUa;
        }

        public final VungleAds.WrapperFramework getWRAPPER_FRAMEWORK_SELECTED$vungle_ads_release() {
            return VungleApiClient.WRAPPER_FRAMEWORK_SELECTED;
        }

        public final void reset$vungle_ads_release() {
            setWRAPPER_FRAMEWORK_SELECTED$vungle_ads_release(null);
            setHeaderUa(defaultHeader());
        }

        public final void setHeaderUa(@NotNull String str) {
            Intrinsics.checkNotNullParameter(str, "<set-?>");
            VungleApiClient.headerUa = str;
        }

        public final void setWRAPPER_FRAMEWORK_SELECTED$vungle_ads_release(VungleAds.WrapperFramework wrapperFramework) {
            VungleApiClient.WRAPPER_FRAMEWORK_SELECTED = wrapperFramework;
        }
    }

    public static final class b implements m {
        @NotNull
        private static final String CONTENT_ENCODING = "Content-Encoding";
        @NotNull
        public static final a Companion = new a(null);
        @NotNull
        private static final String GZIP = "gzip";

        public static final class a {
            private a() {
            }

            public a(DefaultConstructorMarker defaultConstructorMarker) {
                this();
            }
        }

        public static final class C0872b extends o {
            final myobfuscated.yo2.f $output;
            final o $requestBody;

            public C0872b(o oVar, myobfuscated.yo2.f fVar) {
                this.$requestBody = oVar;
                this.$output = fVar;
            }

            @Override
            public long contentLength() {
                return this.$output.b;
            }

            @Override
            public i contentType() {
                return this.$requestBody.contentType();
            }

            @Override
            public void writeTo(@NotNull h sink) throws IOException {
                Intrinsics.checkNotNullParameter(sink, "sink");
                sink.y0(this.$output.D());
            }
        }

        private final o gzip(o oVar) throws IOException {
            myobfuscated.yo2.f fVar = new myobfuscated.yo2.f();
            e0 b = y.b(new r(fVar));
            oVar.writeTo(b);
            b.close();
            return new C0872b(oVar, fVar);
        }

        @Override
        @NotNull
        public p intercept(@NotNull m.a chain) throws IOException {
            Intrinsics.checkNotNullParameter(chain, "chain");
            okhttp3.k request = chain.request();
            o oVar = request.d;
            if (oVar == null || request.b(CONTENT_ENCODING) != null) {
                return chain.a(request);
            }
            k.a c = request.c();
            c.d(CONTENT_ENCODING, GZIP);
            c.f(request.b, gzip(oVar));
            return chain.a(c.b());
        }
    }

    public static final class c extends ProxySelector {
        @Override
        public void connectFailed(URI uri, SocketAddress socketAddress, IOException iOException) {
            try {
                ProxySelector.getDefault().connectFailed(uri, socketAddress, iOException);
            } catch (Exception unused) {
            }
        }

        @Override
        @NotNull
        public List<Proxy> select(URI uri) {
            try {
                List<Proxy> select = ProxySelector.getDefault().select(uri);
                Intrinsics.checkNotNullExpressionValue(select, "{\n                      …ri)\n                    }");
                return select;
            } catch (Exception unused) {
                return n.b(Proxy.NO_PROXY);
            }
        }
    }

    public static final class d implements myobfuscated.l3.a<String> {
        final c0 $uaMetric;
        final VungleApiClient this$0;

        public d(c0 c0Var, VungleApiClient vungleApiClient) {
            this.$uaMetric = c0Var;
            this.this$0 = vungleApiClient;
        }

        @Override
        public void accept(String str) {
            if (str == null) {
                Log.e(VungleApiClient.TAG, "Cannot Get UserAgent. Setting Default Device UserAgent");
                AnalyticsClient.INSTANCE.logError$vungle_ads_release(7, "Fail to get user agent.", (r13 & 4) != 0 ? null : null, (r13 & 8) != 0 ? null : null, (r13 & 16) != 0 ? null : null);
                return;
            }
            this.$uaMetric.markEnd();
            AnalyticsClient.INSTANCE.logMetric$vungle_ads_release(this.$uaMetric.getMetricType(), (r15 & 2) != 0 ? 0L : this.$uaMetric.calculateIntervalDuration(), (r15 & 4) != 0 ? null : null, (r15 & 8) != 0 ? null : null, (r15 & 16) != 0 ? null : null, (r15 & 32) == 0 ? null : null);
            this.this$0.uaString = str;
        }
    }

    public static final class e implements myobfuscated.lj2.b<Void> {
        final AnalyticsClient.a $requestListener;

        public e(AnalyticsClient.a aVar) {
            this.$requestListener = aVar;
        }

        @Override
        public void onFailure(myobfuscated.lj2.a<Void> aVar, Throwable th) {
            this.$requestListener.onFailure();
        }

        @Override
        public void onResponse(myobfuscated.lj2.a<Void> aVar, myobfuscated.lj2.d<Void> dVar) {
            this.$requestListener.onSuccess();
        }
    }

    public static final class f implements myobfuscated.lj2.b<Void> {
        final AnalyticsClient.a $requestListener;

        public f(AnalyticsClient.a aVar) {
            this.$requestListener = aVar;
        }

        @Override
        public void onFailure(myobfuscated.lj2.a<Void> aVar, Throwable th) {
            this.$requestListener.onFailure();
        }

        @Override
        public void onResponse(myobfuscated.lj2.a<Void> aVar, myobfuscated.lj2.d<Void> dVar) {
            this.$requestListener.onSuccess();
        }
    }

    static {
        a aVar = new a(null);
        Companion = aVar;
        BASE_URL = "https://config.ads.vungle.com/";
        headerUa = aVar.defaultHeader();
        networkInterceptors = new HashSet();
        logInterceptors = new HashSet();
        json = myobfuscated.fo2.m.a(new Function1<myobfuscated.fo2.c, Unit>() {
            @Override
            public Unit invoke(c cVar) {
                invoke2(cVar);
                return Unit.a;
            }

            public final void invoke2(@NotNull c Json) {
                Intrinsics.checkNotNullParameter(Json, "$this$Json");
                Json.c = true;
                Json.a = true;
                Json.b = false;
            }
        });
    }

    public VungleApiClient(@NotNull Context applicationContext, @NotNull myobfuscated.pj2.b platform, @NotNull myobfuscated.oj2.a filePreferences) {
        Intrinsics.checkNotNullParameter(applicationContext, "applicationContext");
        Intrinsics.checkNotNullParameter(platform, "platform");
        Intrinsics.checkNotNullParameter(filePreferences, "filePreferences");
        this.applicationContext = applicationContext;
        this.platform = platform;
        this.filePreferences = filePreferences;
        this.uaString = System.getProperty("http.agent");
        this.appSetId = "";
        this.retryAfterDataMap = new ConcurrentHashMap();
        this.responseInterceptor = new myobfuscated.ei1.a(this, 1);
        n.a aVar = new n.a();
        aVar.a(this.responseInterceptor);
        c proxySelector = new c();
        Intrinsics.checkNotNullParameter(proxySelector, "proxySelector");
        if (!Intrinsics.c(proxySelector, aVar.n)) {
            aVar.D = null;
        }
        aVar.n = proxySelector;
        myobfuscated.ko2.n nVar = new myobfuscated.ko2.n(aVar);
        aVar.a(new b());
        myobfuscated.ko2.n nVar2 = new myobfuscated.ko2.n(aVar);
        this.api = new VungleApiImpl(nVar);
        this.gzipApi = new VungleApiImpl(nVar2);
    }

    private final String bodyToString(o oVar) {
        try {
            myobfuscated.yo2.f fVar = new myobfuscated.yo2.f();
            if (oVar != null) {
                oVar.writeTo(fVar);
                return fVar.y();
            }
            return "";
        } catch (Exception unused) {
            return "";
        }
    }

    private final p defaultErrorResponse(okhttp3.k request) {
        p.a aVar = new p.a();
        Intrinsics.checkNotNullParameter(request, "request");
        aVar.a = request;
        aVar.c = 500;
        aVar.d(Protocol.HTTP_1_1);
        Intrinsics.checkNotNullParameter("Server is busy", "message");
        aVar.d = "Server is busy";
        q.b bVar = q.Companion;
        Pattern pattern = i.d;
        i b2 = i.a.b("application/json; charset=utf-8");
        bVar.getClass();
        aVar.g = q.b.a("{\"Error\":\"Server is busy\"}", b2);
        return aVar.a();
    }

    public static void getAppBody$vungle_ads_release$annotations() {
    }

    private final g getBasicDeviceBody(Context context) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        Object systemService = context.getSystemService("window");
        Intrinsics.f(systemService, "null cannot be cast to non-null type android.view.WindowManager");
        Display defaultDisplay = ((WindowManager) systemService).getDefaultDisplay();
        if (defaultDisplay != null) {
            defaultDisplay.getMetrics(displayMetrics);
        }
        String MANUFACTURER = Build.MANUFACTURER;
        Intrinsics.checkNotNullExpressionValue(MANUFACTURER, "MANUFACTURER");
        String MODEL = Build.MODEL;
        Intrinsics.checkNotNullExpressionValue(MODEL, "MODEL");
        String RELEASE = Build.VERSION.RELEASE;
        Intrinsics.checkNotNullExpressionValue(RELEASE, "RELEASE");
        Object systemService2 = context.getSystemService("phone");
        Intrinsics.f(systemService2, "null cannot be cast to non-null type android.telephony.TelephonyManager");
        g gVar = new g(MANUFACTURER, MODEL, RELEASE, ((TelephonyManager) systemService2).getNetworkOperatorName(), Intrinsics.c("Amazon", MANUFACTURER) ? "amazon" : DtbConstants.NATIVE_OS_NAME, displayMetrics.widthPixels, displayMetrics.heightPixels, this.uaString, (String) null, (Integer) null, (g.e) null, 1792, (DefaultConstructorMarker) null);
        try {
            String userAgent = this.platform.getUserAgent();
            this.uaString = userAgent;
            gVar.setUa(userAgent);
            initUserAgentLazy();
        } catch (Exception e2) {
            Log.e(TAG, "Cannot Get UserAgent. Setting Default Device UserAgent." + e2.getLocalizedMessage());
        }
        return gVar;
    }

    private final String getConnectionType() {
        if (myobfuscated.b3.d.a(this.applicationContext, "android.permission.ACCESS_NETWORK_STATE") == 0) {
            Object systemService = this.applicationContext.getSystemService("connectivity");
            Intrinsics.f(systemService, "null cannot be cast to non-null type android.net.ConnectivityManager");
            NetworkInfo activeNetworkInfo = ((ConnectivityManager) systemService).getActiveNetworkInfo();
            if (activeNetworkInfo != null) {
                int type = activeNetworkInfo.getType();
                return type != 0 ? (type == 1 || type == 6) ? "WIFI" : type != 7 ? type != 9 ? "UNKNOWN" : "ETHERNET" : "BLUETOOTH" : "MOBILE";
            }
            return "NONE";
        }
        return null;
    }

    private final String getConnectionTypeDetail() {
        if (myobfuscated.b3.d.a(this.applicationContext, "android.permission.ACCESS_NETWORK_STATE") == 0) {
            Object systemService = this.applicationContext.getSystemService("connectivity");
            Intrinsics.f(systemService, "null cannot be cast to non-null type android.net.ConnectivityManager");
            NetworkInfo activeNetworkInfo = ((ConnectivityManager) systemService).getActiveNetworkInfo();
            return activeNetworkInfo != null ? getConnectionTypeDetail(activeNetworkInfo.getSubtype()) : "unknown";
        }
        return null;
    }

    private final String getConnectionTypeDetail(int i) {
        if (i != 0) {
            if (i != 1) {
                if (i != 2) {
                    if (i != 20) {
                        switch (i) {
                            case 4:
                                return "wcdma";
                            case 5:
                                return "cdma_evdo_0";
                            case 6:
                                return "cdma_evdo_a";
                            case 7:
                                return "cdma_1xrtt";
                            case 8:
                                return "hsdpa";
                            case 9:
                                return "hsupa";
                            default:
                                switch (i) {
                                    case 12:
                                        return "cdma_evdo_b";
                                    case 13:
                                        return "LTE";
                                    case 14:
                                        return "hrpd";
                                    default:
                                        return "unknown";
                                }
                        }
                    }
                    return "unknown";
                }
                return "edge";
            }
            return "gprs";
        }
        return "unknown";
    }

    private final g getDeviceBody() throws IllegalStateException {
        return getDeviceBody$vungle_ads_release(false);
    }

    private final e.f getExtBody() {
        String configExtension = myobfuscated.fj2.a.INSTANCE.getConfigExtension();
        if (configExtension != null && configExtension.length() == 0) {
            configExtension = this.filePreferences.getString("config_extension");
        }
        if ((configExtension == null || configExtension.length() == 0) && "".length() == 0) {
            return null;
        }
        return new e.f(configExtension, "");
    }

    public static void getGzipApi$vungle_ads_release$annotations() {
    }

    private final String getPlacementID(o oVar) {
        List<String> placements;
        try {
            myobfuscated.fo2.a aVar = json;
            e.g request = ((myobfuscated.kj2.e) aVar.b(myobfuscated.ao2.g.b(aVar.b, myobfuscated.xk2.q.c(myobfuscated.kj2.e.class)), bodyToString(oVar))).getRequest();
            if (request == null || (placements = request.getPlacements()) == null) {
                return "";
            }
            String str = placements.get(0);
            return str == null ? "" : str;
        } catch (Exception unused) {
            return "";
        }
    }

    public static void getResponseInterceptor$vungle_ads_release$annotations() {
    }

    public static void getRetryAfterDataMap$vungle_ads_release$annotations() {
    }

    private final e.h getUserBody() {
        e.h hVar = new e.h((e.C1243e) null, (e.b) null, (e.c) null, 7, (DefaultConstructorMarker) null);
        myobfuscated.rj2.a aVar = myobfuscated.rj2.a.INSTANCE;
        hVar.setGdpr(new e.C1243e(aVar.getConsentStatus(), aVar.getConsentSource(), aVar.getConsentTimestamp(), aVar.getConsentMessageVersion()));
        hVar.setCcpa(new e.b(aVar.getCcpaStatus()));
        if (aVar.getCoppaStatus() != COPPA.COPPA_NOTSET) {
            hVar.setCoppa(new e.c(aVar.getCoppaStatus().getValue()));
        }
        return hVar;
    }

    private final void initUserAgentLazy() {
        c0 c0Var = new c0(Sdk$SDKMetric.SDKMetricType.USER_AGENT_LOAD_DURATION_MS);
        c0Var.markStart();
        this.platform.getUserAgentLazy(new d(c0Var, this));
    }

    public static final p m274responseInterceptor$lambda0(VungleApiClient this$0, m.a chain) {
        Intrinsics.checkNotNullParameter(this$0, "this$0");
        Intrinsics.checkNotNullParameter(chain, "chain");
        okhttp3.k request = chain.request();
        try {
            try {
                p a2 = chain.a(request);
                String a3 = a2.f.a("Retry-After");
                if (a3 == null || a3.length() == 0) {
                    return a2;
                }
                try {
                    long parseLong = Long.parseLong(a3);
                    if (parseLong > 0) {
                        String b2 = request.a.b();
                        long currentTimeMillis = (parseLong * 1000) + System.currentTimeMillis();
                        if (myobfuscated.mn2.k.m(b2, "ads", false)) {
                            String placementID = this$0.getPlacementID(request.d);
                            if (placementID.length() > 0) {
                                this$0.retryAfterDataMap.put(placementID, Long.valueOf(currentTimeMillis));
                                return a2;
                            }
                            return a2;
                        }
                        return a2;
                    }
                    return a2;
                } catch (Exception unused) {
                    Log.d(TAG, "Retry-After value is not an valid value");
                    return a2;
                }
            } catch (OutOfMemoryError unused2) {
                i.a aVar = myobfuscated.wj2.i.Companion;
                aVar.e(TAG, "OOM for " + request.a);
                return this$0.defaultErrorResponse(request);
            }
        } catch (Exception e2) {
            i.a aVar2 = myobfuscated.wj2.i.Companion;
            aVar2.e(TAG, "Exception: " + e2.getMessage() + " for " + request.a);
            return this$0.defaultErrorResponse(request);
        }
    }

    public final void addPlaySvcAvailabilityInCookie(boolean z) {
        this.filePreferences.put("isPlaySvcAvailable", z).apply();
    }

    public final boolean checkIsRetryAfterActive(@NotNull String placementID) {
        Intrinsics.checkNotNullParameter(placementID, "placementID");
        Long l = this.retryAfterDataMap.get(placementID);
        if ((l != null ? l.longValue() : 0L) > System.currentTimeMillis()) {
            return true;
        }
        this.retryAfterDataMap.remove(placementID);
        return false;
    }

    public final myobfuscated.lj2.a<myobfuscated.kj2.f> config() throws IOException {
        myobfuscated.kj2.c cVar = this.appBody;
        if (cVar == null) {
            return null;
        }
        myobfuscated.kj2.e eVar = new myobfuscated.kj2.e(getDeviceBody$vungle_ads_release(true), cVar, getUserBody(), (e.f) null, (e.g) null, 24, (DefaultConstructorMarker) null);
        e.f extBody = getExtBody();
        if (extBody != null) {
            eVar.setExt(extBody);
        }
        myobfuscated.wj2.e eVar2 = myobfuscated.wj2.e.INSTANCE;
        String str = BASE_URL;
        if (!eVar2.isValidUrl(str)) {
            str = "https://config.ads.vungle.com/";
        }
        if (!myobfuscated.mn2.k.m(str, "/", false)) {
            str = str.concat("/");
        }
        VungleApi vungleApi = this.api;
        String str2 = headerUa;
        return vungleApi.config(str2, str + DTBMetricsConfiguration.CONFIG_DIR, eVar);
    }

    public final myobfuscated.kj2.c getAppBody$vungle_ads_release() {
        return this.appBody;
    }

    @NotNull
    public final synchronized g getDeviceBody$vungle_ads_release(boolean z) throws IllegalStateException {
        g copy;
        String str;
        try {
            g gVar = this.baseDeviceInfo;
            if (gVar == null) {
                gVar = getBasicDeviceBody(this.applicationContext);
                this.baseDeviceInfo = gVar;
            }
            copy = gVar.copy((r24 & 1) != 0 ? gVar.make : null, (r24 & 2) != 0 ? gVar.model : null, (r24 & 4) != 0 ? gVar.osv : null, (r24 & 8) != 0 ? gVar.carrier : null, (r24 & 16) != 0 ? gVar.os : null, (r24 & 32) != 0 ? gVar.w : 0, (r24 & 64) != 0 ? gVar.h : 0, (r24 & 128) != 0 ? gVar.ua : null, (r24 & Barcode.QR_CODE) != 0 ? gVar.ifa : null, (r24 & 512) != 0 ? gVar.lmt : null, (r24 & Barcode.UPC_E) != 0 ? gVar.ext : null);
            g.b bVar = new g.b(null, null, 3, null);
            myobfuscated.kj2.b advertisingInfo = this.platform.getAdvertisingInfo();
            String advertisingId = advertisingInfo != null ? advertisingInfo.getAdvertisingId() : null;
            Boolean valueOf = advertisingInfo != null ? Boolean.valueOf(advertisingInfo.getLimitAdTracking()) : null;
            myobfuscated.rj2.a aVar = myobfuscated.rj2.a.INSTANCE;
            if (aVar.shouldSendAdIds()) {
                if (advertisingId != null) {
                    if (Intrinsics.c("Amazon", Build.MANUFACTURER)) {
                        bVar.setAmazonAdvertisingId(advertisingId);
                    } else {
                        bVar.setGaid(advertisingId);
                    }
                    copy.setIfa(advertisingId);
                } else {
                    String androidId = this.platform.getAndroidId();
                    copy.setIfa(androidId == null ? "" : androidId);
                    if (androidId != null) {
                        bVar.setAndroidId(androidId);
                    }
                }
            }
            if (!aVar.shouldSendAdIds() || z) {
                copy.setIfa(null);
                bVar.setAndroidId(null);
                bVar.setGaid(null);
                bVar.setAmazonAdvertisingId(null);
            }
            Boolean bool = Boolean.TRUE;
            boolean z2 = false;
            copy.setLmt(Intrinsics.c(valueOf, bool) ? 1 : 0);
            bVar.setGooglePlayServicesAvailable(Intrinsics.c(bool, isGooglePlayServicesAvailable()));
            String appSetId = this.platform.getAppSetId();
            this.appSetId = appSetId;
            if (appSetId != null && appSetId.length() != 0) {
                bVar.setAppSetId(this.appSetId);
            }
            Intent registerReceiver = this.applicationContext.registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
            if (registerReceiver != null) {
                int intExtra = registerReceiver.getIntExtra(AppLovinEventTypes.USER_COMPLETED_LEVEL, -1);
                int intExtra2 = registerReceiver.getIntExtra("scale", -1);
                if (intExtra > 0 && intExtra2 > 0) {
                    bVar.setBatteryLevel(intExtra / intExtra2);
                }
                int intExtra3 = registerReceiver.getIntExtra("status", -1);
                if (intExtra3 == -1) {
                    str = "UNKNOWN";
                } else if (intExtra3 == 2 || intExtra3 == 5) {
                    int intExtra4 = registerReceiver.getIntExtra("plugged", -1);
                    str = intExtra4 != 1 ? intExtra4 != 2 ? intExtra4 != 4 ? "BATTERY_PLUGGED_OTHERS" : "BATTERY_PLUGGED_WIRELESS" : "BATTERY_PLUGGED_USB" : "BATTERY_PLUGGED_AC";
                } else {
                    str = "NOT_CHARGING";
                }
            } else {
                str = "UNKNOWN";
            }
            bVar.setBatteryState(str);
            Object systemService = this.applicationContext.getSystemService("power");
            Intrinsics.f(systemService, "null cannot be cast to non-null type android.os.PowerManager");
            bVar.setBatterySaverEnabled(((PowerManager) systemService).isPowerSaveMode() ? 1 : 0);
            String connectionType = getConnectionType();
            if (connectionType != null) {
                bVar.setConnectionType(connectionType);
            }
            String connectionTypeDetail = getConnectionTypeDetail();
            if (connectionTypeDetail != null) {
                bVar.setConnectionTypeDetail(connectionTypeDetail);
            }
            bVar.setLocale(Locale.getDefault().toString());
            bVar.setLanguage(Locale.getDefault().getLanguage());
            bVar.setTimeZone(TimeZone.getDefault().getID());
            bVar.setVolumeLevel(this.platform.getVolumeLevel());
            bVar.setSoundEnabled(this.platform.isSoundEnabled() ? 1 : 0);
            String str2 = Build.MANUFACTURER;
            if (Intrinsics.c("Amazon", str2)) {
                z2 = this.applicationContext.getPackageManager().hasSystemFeature("amazon.hardware.fire_tv");
            } else {
                Object systemService2 = this.applicationContext.getSystemService("uimode");
                Intrinsics.f(systemService2, "null cannot be cast to non-null type android.app.UiModeManager");
                if (((UiModeManager) systemService2).getCurrentModeType() == 4) {
                    z2 = true;
                }
            }
            bVar.setTv(z2);
            bVar.setSideloadEnabled(this.platform.isSideLoaded());
            bVar.setSdCardAvailable(this.platform.isSdCardPresent() ? 1 : 0);
            bVar.setOsName(Build.FINGERPRINT);
            copy.setUa(this.uaString);
            copy.setExt(new g.e(Intrinsics.c("Amazon", str2) ? new g.f((g.b) null, bVar, 1, (DefaultConstructorMarker) null) : new g.f(bVar, (g.b) null, 2, (DefaultConstructorMarker) null)));
        } catch (Throwable th) {
            throw th;
        }
        return copy;
    }

    @NotNull
    public final VungleApi getGzipApi$vungle_ads_release() {
        return this.gzipApi;
    }

    public final Boolean getPlayServicesAvailabilityFromAPI() {
        Boolean bool = null;
        try {
            GoogleApiAvailabilityLight googleApiAvailabilityLight = GoogleApiAvailabilityLight.getInstance();
            Intrinsics.checkNotNullExpressionValue(googleApiAvailabilityLight, "getInstance()");
            bool = Boolean.valueOf(googleApiAvailabilityLight.isGooglePlayServicesAvailable(this.applicationContext) == 0);
            addPlaySvcAvailabilityInCookie(bool.booleanValue());
            return bool;
        } catch (Exception unused) {
            Log.w(TAG, "Unexpected exception from Play services lib.");
            return bool;
        } catch (NoClassDefFoundError unused2) {
            Log.w(TAG, "Play services Not available");
            Boolean bool2 = Boolean.FALSE;
            try {
                addPlaySvcAvailabilityInCookie(false);
                return bool2;
            } catch (Exception unused3) {
                Log.w(TAG, "Failure to write GPS availability to DB");
                return bool2;
            }
        }
    }

    public final Boolean getPlayServicesAvailabilityFromCookie() {
        return this.filePreferences.getBoolean("isPlaySvcAvailable");
    }

    @NotNull
    public final m getResponseInterceptor$vungle_ads_release() {
        return this.responseInterceptor;
    }

    @NotNull
    public final Map<String, Long> getRetryAfterDataMap$vungle_ads_release() {
        return this.retryAfterDataMap;
    }

    public final long getRetryAfterHeaderValue(@NotNull String placementID) {
        Intrinsics.checkNotNullParameter(placementID, "placementID");
        Long l = this.retryAfterDataMap.get(placementID);
        if (l != null) {
            return l.longValue();
        }
        return 0L;
    }

    public final synchronized void initialize(@NotNull String appId) {
        PackageInfo packageInfo;
        PackageManager.PackageInfoFlags of;
        try {
            Intrinsics.checkNotNullParameter(appId, "appId");
            this.api.setAppId(appId);
            this.gzipApi.setAppId(appId);
            String str = "1.0";
            try {
                if (Build.VERSION.SDK_INT >= 33) {
                    PackageManager packageManager = this.applicationContext.getPackageManager();
                    String packageName = this.applicationContext.getPackageName();
                    of = PackageManager.PackageInfoFlags.of(0L);
                    packageInfo = packageManager.getPackageInfo(packageName, of);
                    Intrinsics.checkNotNullExpressionValue(packageInfo, "{\n                    ap…      )\n                }");
                } else {
                    packageInfo = this.applicationContext.getPackageManager().getPackageInfo(this.applicationContext.getPackageName(), 0);
                    Intrinsics.checkNotNullExpressionValue(packageInfo, "{\n                    ap…      )\n                }");
                }
                String str2 = packageInfo.versionName;
                Intrinsics.checkNotNullExpressionValue(str2, "packageInfo.versionName");
                str = str2;
            } catch (Exception unused) {
            }
            this.baseDeviceInfo = getBasicDeviceBody(this.applicationContext);
            String packageName2 = this.applicationContext.getPackageName();
            Intrinsics.checkNotNullExpressionValue(packageName2, "applicationContext.packageName");
            this.appBody = new myobfuscated.kj2.c(packageName2, str, appId);
            this.isGooglePlayServicesAvailable = getPlayServicesAvailabilityFromAPI();
        } catch (Throwable th) {
            throw th;
        }
    }

    public final Boolean isGooglePlayServicesAvailable() {
        if (this.isGooglePlayServicesAvailable == null) {
            this.isGooglePlayServicesAvailable = getPlayServicesAvailabilityFromCookie();
        }
        if (this.isGooglePlayServicesAvailable == null) {
            this.isGooglePlayServicesAvailable = getPlayServicesAvailabilityFromAPI();
        }
        return this.isGooglePlayServicesAvailable;
    }

    public final BaseAdLoader.b pingTPAT(@NotNull String url) {
        okhttp3.h hVar;
        Intrinsics.checkNotNullParameter(url, "url");
        if (url.length() != 0) {
            Intrinsics.checkNotNullParameter(url, "<this>");
            Integer num = null;
            try {
                Intrinsics.checkNotNullParameter(url, "<this>");
                h.a aVar = new h.a();
                aVar.e(null, url);
                hVar = aVar.b();
            } catch (IllegalArgumentException unused) {
                hVar = null;
            }
            if (hVar != null) {
                try {
                    if ((Build.VERSION.SDK_INT >= 24 ? NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted(new URL(url).getHost()) : NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted()) || !URLUtil.isHttpUrl(url)) {
                        try {
                            String str = this.uaString;
                            if (str == null) {
                                str = "";
                            }
                            myobfuscated.lj2.d<Void> execute = this.api.pingTPAT(str, url).execute();
                            if (execute != null && execute.isSuccessful()) {
                                return null;
                            }
                            if (kotlin.collections.c.H(myobfuscated.jk2.o.h(301, 302, 307, 308), num)) {
                                return new BaseAdLoader.b(29, "Tpat ping was redirected with code " + num, null, false, 12, null);
                            }
                            return new BaseAdLoader.b(121, "Tpat ping was not successful", null, false, 12, null);
                        } catch (Exception e2) {
                            String localizedMessage = e2.getLocalizedMessage();
                            if (localizedMessage == null) {
                                localizedMessage = "IOException";
                            }
                            return new BaseAdLoader.b(121, localizedMessage, null, false, 12, null);
                        }
                    }
                    return new BaseAdLoader.b(121, "Clear Text Traffic is blocked", null, false, 12, null);
                } catch (MalformedURLException e3) {
                    String localizedMessage2 = e3.getLocalizedMessage();
                    if (localizedMessage2 == null) {
                        localizedMessage2 = "MalformedURLException";
                    }
                    return new BaseAdLoader.b(121, localizedMessage2, null, true, 4, null);
                }
            }
        }
        return new BaseAdLoader.b(121, "Invalid URL : ".concat(url), null, true, 4, null);
    }

    public final void reportErrors(@NotNull BlockingQueue<Sdk$SDKError.a> errors, @NotNull AnalyticsClient.a requestListener) {
        Intrinsics.checkNotNullParameter(errors, "errors");
        Intrinsics.checkNotNullParameter(requestListener, "requestListener");
        String errorLoggingEndpoint = myobfuscated.fj2.a.INSTANCE.getErrorLoggingEndpoint();
        if (errorLoggingEndpoint == null || errorLoggingEndpoint.length() == 0) {
            requestListener.onFailure();
            return;
        }
        for (Sdk$SDKError.a aVar : errors) {
            String connectionType = getConnectionType();
            if (connectionType != null) {
                aVar.setConnectionType(connectionType);
            }
            String connectionTypeDetail = getConnectionTypeDetail();
            if (connectionTypeDetail != null) {
                aVar.setConnectionTypeDetail(connectionTypeDetail);
                aVar.setConnectionTypeDetailAndroid(connectionTypeDetail);
            }
        }
        ArrayList arrayList = new ArrayList();
        for (Sdk$SDKError.a aVar2 : errors) {
            arrayList.add(aVar2.build());
        }
        Sdk$SDKErrorBatch build = Sdk$SDKErrorBatch.newBuilder().addAllErrors(arrayList).build();
        o.a aVar3 = o.Companion;
        byte[] byteArray = build.toByteArray();
        Intrinsics.checkNotNullExpressionValue(byteArray, "batch.toByteArray()");
        Pattern pattern = okhttp3.i.d;
        okhttp3.i b2 = i.a.b("application/x-protobuf");
        int length = build.toByteArray().length;
        aVar3.getClass();
        this.api.sendErrors(headerUa, errorLoggingEndpoint, o.a.c(byteArray, b2, 0, length)).enqueue(new e(requestListener));
    }

    public final void reportMetrics(@NotNull BlockingQueue<Sdk$SDKMetric.a> metrics, @NotNull AnalyticsClient.a requestListener) {
        Intrinsics.checkNotNullParameter(metrics, "metrics");
        Intrinsics.checkNotNullParameter(requestListener, "requestListener");
        String metricsEndpoint = myobfuscated.fj2.a.INSTANCE.getMetricsEndpoint();
        if (metricsEndpoint == null || metricsEndpoint.length() == 0) {
            requestListener.onFailure();
            return;
        }
        for (Sdk$SDKMetric.a aVar : metrics) {
            String connectionType = getConnectionType();
            if (connectionType != null) {
                aVar.setConnectionType(connectionType);
            }
            String connectionTypeDetail = getConnectionTypeDetail();
            if (connectionTypeDetail != null) {
                aVar.setConnectionTypeDetail(connectionTypeDetail);
            }
        }
        ArrayList arrayList = new ArrayList();
        for (Sdk$SDKMetric.a aVar2 : metrics) {
            arrayList.add(aVar2.build());
        }
        o.a aVar3 = o.Companion;
        Pattern pattern = okhttp3.i.d;
        okhttp3.i b2 = i.a.b("application/x-protobuf");
        byte[] byteArray = Sdk$MetricBatch.newBuilder().addAllMetrics(arrayList).build().toByteArray();
        Intrinsics.checkNotNullExpressionValue(byteArray, "batch.toByteArray()");
        this.api.sendMetrics(headerUa, metricsEndpoint, o.a.d(aVar3, b2, byteArray, 0, 12)).enqueue(new f(requestListener));
    }

    public final myobfuscated.lj2.a<myobfuscated.kj2.a> requestAd(@NotNull String placement, String str, boolean z) throws IllegalStateException {
        Intrinsics.checkNotNullParameter(placement, "placement");
        String adsEndpoint = myobfuscated.fj2.a.INSTANCE.getAdsEndpoint();
        if (adsEndpoint == null || adsEndpoint.length() == 0) {
            return null;
        }
        myobfuscated.kj2.e requestBody = requestBody();
        e.g gVar = new e.g(myobfuscated.jk2.n.b(placement), Boolean.valueOf(z), (String) null, (Long) null, (String) null, (String) null, (String) null, 124, (DefaultConstructorMarker) null);
        if (str != null && str.length() != 0) {
            gVar.setAdSize(str);
        }
        requestBody.setRequest(gVar);
        return this.gzipApi.ads(headerUa, adsEndpoint, requestBody);
    }

    @NotNull
    public final myobfuscated.kj2.e requestBody() throws IllegalStateException {
        myobfuscated.kj2.e eVar = new myobfuscated.kj2.e(getDeviceBody(), this.appBody, getUserBody(), (e.f) null, (e.g) null, 24, (DefaultConstructorMarker) null);
        e.f extBody = getExtBody();
        if (extBody != null) {
            eVar.setExt(extBody);
        }
        return eVar;
    }

    public final myobfuscated.lj2.a<Void> ri(@NotNull e.g request) {
        myobfuscated.kj2.c cVar;
        Intrinsics.checkNotNullParameter(request, "request");
        String riEndpoint = myobfuscated.fj2.a.INSTANCE.getRiEndpoint();
        if (riEndpoint == null || riEndpoint.length() == 0 || (cVar = this.appBody) == null) {
            return null;
        }
        myobfuscated.kj2.e eVar = new myobfuscated.kj2.e(getDeviceBody(), cVar, getUserBody(), (e.f) null, (e.g) null, 24, (DefaultConstructorMarker) null);
        eVar.setRequest(request);
        e.f extBody = getExtBody();
        if (extBody != null) {
            eVar.setExt(extBody);
        }
        return this.api.ri(headerUa, riEndpoint, eVar);
    }

    public final void setAppBody$vungle_ads_release(myobfuscated.kj2.c cVar) {
        this.appBody = cVar;
    }

    public final void setGzipApi$vungle_ads_release(@NotNull VungleApi vungleApi) {
        Intrinsics.checkNotNullParameter(vungleApi, "<set-?>");
        this.gzipApi = vungleApi;
    }

    public final void setResponseInterceptor$vungle_ads_release(@NotNull m mVar) {
        Intrinsics.checkNotNullParameter(mVar, "<set-?>");
        this.responseInterceptor = mVar;
    }

    public final void setRetryAfterDataMap$vungle_ads_release(@NotNull Map<String, Long> map) {
        Intrinsics.checkNotNullParameter(map, "<set-?>");
        this.retryAfterDataMap = map;
    }
}