b0.java 源代码


package com.applovin.impl.sdk;

import android.content.Intent;
import android.webkit.RenderProcessGoneDetail;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.annotation.Nullable;
import com.applovin.sdk.AppLovinSdkUtils;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import l0.p;

public class b0 {

    @Nullable
    private static WebView f7565a;

    private static volatile String f7566b;

    private static volatile Map<String, String> f7567c;

    public static class a implements Runnable {

        final k f7568q;

        a(k kVar) {
            this.f7568q = kVar;
        }

        @Override
        public void run() {
            try {
                String unused = b0.f7566b = WebSettings.getDefaultUserAgent(this.f7568q.j());
            } catch (Throwable th) {
                this.f7568q.U0().h("WebViewDataCollector", "Failed to collect user agent", th);
            }
        }
    }

    public static class b implements Runnable {

        final k f7569q;

        b(k kVar) {
            this.f7569q = kVar;
        }

        @Override
        public void run() {
            try {
                b0.d(this.f7569q);
                String unused = b0.f7566b = b0.f7565a.getSettings().getUserAgentString();
            } catch (Throwable th) {
                this.f7569q.U0().h("WebViewDataCollector", "Failed to collect user agent", th);
            }
        }
    }

    public static class c implements Runnable {

        final k f7570q;

        class a extends d {
            a(k kVar) {
                super(kVar, null);
            }

            @Override
            public WebResourceResponse shouldInterceptRequest(WebView webView, WebResourceRequest webResourceRequest) {
                HashMap hashMap = new HashMap();
                for (Map.Entry<String, String> entry : webResourceRequest.getRequestHeaders().entrySet()) {
                    hashMap.put("AppLovin-WebView-" + entry.getKey(), entry.getValue());
                }
                Map unused = b0.f7567c = hashMap;
                return super.shouldInterceptRequest(webView, webResourceRequest);
            }
        }

        c(k kVar) {
            this.f7570q = kVar;
        }

        @Override
        public void run() {
            try {
                b0.d(this.f7570q);
                b0.f7565a.setWebViewClient(new a(this.f7570q));
                b0.f7565a.loadUrl("https://blank");
            } catch (Throwable th) {
                this.f7570q.U0().h("WebViewDataCollector", "Failed to collect WebView HTTP headers", th);
            }
        }
    }

    public static class d extends WebViewClient {

        private final k f7572a;

        private d(k kVar) {
            this.f7572a = kVar;
        }

        @Override
        public boolean onRenderProcessGone(WebView webView, RenderProcessGoneDetail renderProcessGoneDetail) {
            this.f7572a.d0().sendBroadcast(new Intent("com.applovin.render_process_gone"), null);
            return true;
        }

        d(k kVar, a aVar) {
            this(kVar);
        }
    }

    public static String a() {
        return f7566b;
    }

    public static void d(k kVar) {
        if (f7565a == null) {
            try {
                WebView webView = new WebView(kVar.j());
                f7565a = webView;
                webView.setWebViewClient(new d(kVar, null));
            } catch (Throwable th) {
                kVar.U0().h("WebViewDataCollector", "Failed to initialize WebView for data collection.", th);
            }
        }
    }

    public static Map<String, String> e() {
        if (f7567c != null) {
            return f7567c;
        }
        return Collections.emptyMap();
    }

    public static void f(k kVar) {
        if (f7566b != null) {
            return;
        }
        f7566b = "";
        if (n0.f.d()) {
            kVar.q().h(new l0.z(kVar, true, new a(kVar)), p.b.BACKGROUND);
        } else {
            AppLovinSdkUtils.runOnUiThread(new b(kVar));
        }
    }

    public static void h(k kVar) {
        if (f7567c != null) {
            return;
        }
        f7567c = Collections.emptyMap();
        if (n0.f.f()) {
            AppLovinSdkUtils.runOnUiThread(new c(kVar));
        }
    }
}