小红书.apk(点击下载) / k.java


package tb;

import a23.u2;
import android.app.Application;
import android.os.Build;
import com.alipay.sdk.util.f;
import com.google.gson.Gson;
import com.meizu.cloud.pushsdk.notification.model.AdvanceSetting;
import com.uber.autodispose.a0;
import com.uber.autodispose.y;
import com.xingin.advert.report.AdBean;
import com.xingin.advert.report.AdBodyBean;
import com.xingin.advert.report.AdDBConfig;
import com.xingin.advert.report.AdDataBase;
import com.xingin.advert.report.AdServerResponseBean;
import com.xingin.utils.XYUtilsCenter;
import com.xingin.utils.async.run.task.XYRunnable;
import com.xingin.utils.core.o;
import com.xingin.xhs.xhsstorage.XhsDatabase;
import dw2.r;
import dw2.t;
import ja.b1;
import java.util.ArrayList;
import kotlin.Lazy;
import kotlin.LazyKt__LazyJVMKt;
import kotlin.LazyThreadSafetyMode;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.Lambda;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import vt2.d;
import w13.z;

public final class k {

    /* renamed from: d */
    public static final b f132917d = new b(null);

    /* renamed from: e */
    public static final Lazy<k> f132918e = LazyKt__LazyJVMKt.lazy(LazyThreadSafetyMode.SYNCHRONIZED, (Function0) a.f132924a);

    /* renamed from: f */
    public static final OkHttpClient f132919f = ta.b.f132760a.b().a();

    /* renamed from: g */
    public static String f132920g = "";

    /* renamed from: a */
    public final Application f132921a;

    /* renamed from: b */
    public final AdDataBase f132922b;

    /* renamed from: c */
    public final l f132923c;

    public static final class a extends Lambda implements Function0<k> {

        /* renamed from: a */
        public static final a f132924a = new a();

        public a() {
            super(0);
        }

        /* renamed from: a */
        public final k invoke() {
            Application e14 = XYUtilsCenter.e();
            Intrinsics.checkNotNullExpressionValue(e14, "getApp()");
            return new k(e14, null);
        }
    }

    public static final class b {

        public static final class a extends XYRunnable {
            public a() {
                super("AdRepCheck", null, 2, null);
            }

            @Override // com.xingin.utils.async.run.task.XYRunnable
            public void execute() {
                try {
                    k.f132917d.g().f132923c.g();
                } catch (Exception unused) {
                }
            }
        }

        /* renamed from: tb.k$b$b */
        public static final class C2134b extends XYRunnable {

            /* renamed from: a */
            public final /* synthetic */ String f132925a;

            /* renamed from: b */
            public final /* synthetic */ String f132926b;

            /* renamed from: c */
            public final /* synthetic */ ArrayList<String> f132927c;

            /* JADX INFO: super call moved to the top of the method (can break code semantics) */
            public C2134b(String str, String str2, ArrayList<String> arrayList) {
                super("AdReport", null, 2, null);
                this.f132925a = str;
                this.f132926b = str2;
                this.f132927c = arrayList;
            }

            @Override // com.xingin.utils.async.run.task.XYRunnable
            public void execute() {
                b bVar = k.f132917d;
                k g10 = bVar.g();
                String str = this.f132925a;
                String str2 = this.f132926b;
                ArrayList<String> arrayList = this.f132927c;
                AdBean adBean = new AdBean();
                adBean.setTimestamp(System.currentTimeMillis());
                adBean.setMethod(1);
                adBean.setCount(0);
                adBean.setMaxCount(10);
                adBean.setBaseUrl("https://referee.xiaohongshu.com/v1/third/collect");
                Gson gson = new Gson();
                AdBodyBean adBodyBean = new AdBodyBean();
                String e14 = o.e();
                Intrinsics.checkNotNullExpressionValue(e14, "getDeviceId()");
                adBodyBean.setDeviceId(e14);
                String d14 = o.d(XYUtilsCenter.e());
                Intrinsics.checkNotNullExpressionValue(d14, "getAndroidId(XYUtilsCenter.getApp())");
                adBodyBean.setAndroidId(d14);
                String t14 = o.t(XYUtilsCenter.e());
                Intrinsics.checkNotNullExpressionValue(t14, "getSecureIMEI(XYUtilsCenter.getApp())");
                adBodyBean.setImei(t14);
                b1 b1Var = b1.f94179a;
                adBodyBean.setOaid(b1Var.O0());
                adBodyBean.setTrackId(str);
                adBodyBean.setUserId(b1Var.S0().getUserid());
                adBodyBean.setUseragent(bVar.i());
                adBodyBean.setAction("click");
                adBodyBean.setCreateTime(adBean.getTimestamp());
                adBodyBean.setEvent(str2);
                adBodyBean.setSdkUrl(arrayList);
                Unit unit = Unit.INSTANCE;
                String json = gson.toJson(adBodyBean);
                Intrinsics.checkNotNullExpressionValue(json, "Gson().toJson(AdBodyBean…                       })");
                adBean.setBody(json);
                try {
                    g10.f132922b.getAdCatchDao().insert(adBean);
                } catch (Throwable th3) {
                    qb.a.d("AdReportManager", "dbError: insert " + str + " failed: " + th3);
                }
                g10.f132923c.c(adBean);
            }
        }

        public static final class c extends XYRunnable {

            /* renamed from: a */
            public final /* synthetic */ String f132928a;

            /* renamed from: b */
            public final /* synthetic */ String f132929b;

            /* renamed from: c */
            public final /* synthetic */ ArrayList<String> f132930c;

            /* JADX INFO: super call moved to the top of the method (can break code semantics) */
            public c(String str, String str2, ArrayList<String> arrayList) {
                super("AdReport", null, 2, null);
                this.f132928a = str;
                this.f132929b = str2;
                this.f132930c = arrayList;
            }

            @Override // com.xingin.utils.async.run.task.XYRunnable
            public void execute() {
                b bVar = k.f132917d;
                k g10 = bVar.g();
                String str = this.f132928a;
                String str2 = this.f132929b;
                ArrayList<String> arrayList = this.f132930c;
                AdBean adBean = new AdBean();
                adBean.setTimestamp(System.currentTimeMillis());
                adBean.setMethod(1);
                adBean.setCount(0);
                adBean.setMaxCount(10);
                adBean.setBaseUrl("https://referee.xiaohongshu.com/v1/third/collect");
                Gson gson = new Gson();
                AdBodyBean adBodyBean = new AdBodyBean();
                String e14 = o.e();
                Intrinsics.checkNotNullExpressionValue(e14, "getDeviceId()");
                adBodyBean.setDeviceId(e14);
                String d14 = o.d(XYUtilsCenter.e());
                Intrinsics.checkNotNullExpressionValue(d14, "getAndroidId(XYUtilsCenter.getApp())");
                adBodyBean.setAndroidId(d14);
                String t14 = o.t(XYUtilsCenter.e());
                Intrinsics.checkNotNullExpressionValue(t14, "getSecureIMEI(XYUtilsCenter.getApp())");
                adBodyBean.setImei(t14);
                adBodyBean.setTrackId(str);
                b1 b1Var = b1.f94179a;
                adBodyBean.setUserId(b1Var.S0().getUserid());
                adBodyBean.setOaid(b1Var.O0());
                adBodyBean.setUseragent(bVar.i());
                adBodyBean.setAction("impression");
                adBodyBean.setCreateTime(adBean.getTimestamp());
                adBodyBean.setEvent(str2);
                adBodyBean.setSdkUrl(arrayList);
                Unit unit = Unit.INSTANCE;
                String json = gson.toJson(adBodyBean);
                Intrinsics.checkNotNullExpressionValue(json, "Gson().toJson(AdBodyBean…                       })");
                adBean.setBody(json);
                try {
                    g10.f132922b.getAdCatchDao().insert(adBean);
                } catch (Throwable th3) {
                    qb.a.d("AdReportManager", "dbError: insert " + str + " failed: " + th3);
                }
                g10.f132923c.c(adBean);
            }
        }

        public static final class d extends Lambda implements Function1<z.a, Unit> {

            /* renamed from: a */
            public final /* synthetic */ String f132931a;

            /* renamed from: b */
            public final /* synthetic */ int f132932b;

            /* renamed from: c */
            public final /* synthetic */ String f132933c;

            /* JADX INFO: super call moved to the top of the method (can break code semantics) */
            public d(String str, int i10, String str2) {
                super(1);
                this.f132931a = str;
                this.f132932b = i10;
                this.f132933c = str2;
            }

            public final void a(z.a aVar) {
                Intrinsics.checkNotNullParameter(aVar, "$this$withAdvertExternalAppGetLinkFail");
                aVar.s(u2.target_upload_fail_VALUE);
                aVar.u(1.0f);
                aVar.r(this.f132931a);
                aVar.v(this.f132932b);
                String str = this.f132933c;
                if (str == null) {
                    str = "";
                }
                aVar.t(str);
            }

            @Override // kotlin.jvm.functions.Function1
            public /* bridge */ /* synthetic */ Unit invoke(z.a aVar) {
                a(aVar);
                return Unit.INSTANCE;
            }
        }

        public b() {
        }

        public /* synthetic */ b(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        /* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: tb.k$b */
        /* JADX WARN: Multi-variable type inference failed */
        public static /* synthetic */ void k(b bVar, String str, String str2, ArrayList arrayList, int i10, Object obj) {
            if ((i10 & 2) != 0) {
                str2 = "explore";
            }
            if ((i10 & 4) != 0) {
                arrayList = new ArrayList();
            }
            bVar.j(str, str2, arrayList);
        }

        /* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: tb.k$b */
        /* JADX WARN: Multi-variable type inference failed */
        public static /* synthetic */ void m(b bVar, String str, String str2, ArrayList arrayList, int i10, Object obj) {
            if ((i10 & 2) != 0) {
                str2 = "explore";
            }
            if ((i10 & 4) != 0) {
                arrayList = new ArrayList();
            }
            bVar.l(str, str2, arrayList);
        }

        public static final void o(String str, int i10, String str2) {
            Intrinsics.checkNotNullParameter(str, "$id");
            qe2.a.a().p4("advert_external_app_get_link_fail").f(new d(str, i10, str2)).b();
        }

        public static final void q(String str, String str2, t tVar) {
            Intrinsics.checkNotNullParameter(str, "$id");
            Intrinsics.checkNotNullParameter(str2, "$event");
            Intrinsics.checkNotNullParameter(tVar, AdvanceSetting.NETWORK_TYPE);
            b h10 = k.f132917d.h(str, str2);
            if (h10 != null) {
                tVar.a(h10);
            } else {
                tVar.onError(new Throwable("Ext data is null"));
            }
            tVar.onComplete();
        }

        public static final void r(Function1 function1, b bVar) {
            Intrinsics.checkNotNullParameter(function1, "$action");
            function1.invoke(bVar);
        }

        public static final void s(Throwable th3) {
            qb.a.d("AdReportManger", "[requestExtAppInfoFromServer] ext data is null");
        }

        public final void f() {
            mi2.a.m(new a());
        }

        public final k g() {
            return (k) k.f132918e.getValue();
        }

        /* JADX WARNING: Removed duplicated region for block: B:14:0x00b3 A[Catch:{ Exception -> 0x011d }] */
        /* JADX WARNING: Removed duplicated region for block: B:16:0x00bd A[Catch:{ Exception -> 0x011d }] */
        /* JADX WARNING: Removed duplicated region for block: B:28:0x0103 A[Catch:{ Exception -> 0x011d }] */
        public final b h(String str, String str2) {
            boolean z14;
            boolean z15;
            try {
                Gson gson = new Gson();
                AdBodyBean adBodyBean = new AdBodyBean();
                String e14 = o.e();
                Intrinsics.checkNotNullExpressionValue(e14, "getDeviceId()");
                adBodyBean.setDeviceId(e14);
                String d14 = o.d(XYUtilsCenter.e());
                Intrinsics.checkNotNullExpressionValue(d14, "getAndroidId(XYUtilsCenter.getApp())");
                adBodyBean.setAndroidId(d14);
                String t14 = o.t(XYUtilsCenter.e());
                Intrinsics.checkNotNullExpressionValue(t14, "getSecureIMEI(XYUtilsCenter.getApp())");
                adBodyBean.setImei(t14);
                b1 b1Var = b1.f94179a;
                adBodyBean.setUserId(b1Var.S0().getUserid());
                adBodyBean.setTrackId(str);
                adBodyBean.setOaid(b1Var.O0());
                adBodyBean.setUseragent(k.f132917d.i());
                adBodyBean.setAction("extapp");
                adBodyBean.setEvent(str2);
                String json = gson.toJson(adBodyBean);
                Request.Builder url = new Request.Builder().url("https://referee.xiaohongshu.com/v1/third/collect");
                RequestBody create = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
                url.removeHeader("User-Agent");
                url.addHeader("User-Agent", i());
                url.post(create);
                Response execute = k.f132919f.newCall(url.build()).execute();
                ResponseBody body = execute.body();
                String string = body != null ? body.string() : null;
                boolean z16 = false;
                if (string != null) {
                    if (string.length() != 0) {
                        z14 = false;
                        if (!z14) {
                            n(str, str2, execute.code(), "no response");
                            return null;
                        }
                        b extapp = ((AdServerResponseBean) new Gson().fromJson(string, AdServerResponseBean.class)).getExtapp();
                        if (extapp.c() != 1) {
                            int code = execute.code();
                            int c14 = extapp.c();
                            n(str, str2, code, "invalid type: " + c14);
                            return null;
                        }
                        String a14 = extapp.a();
                        if (a14 != null) {
                            if (a14.length() != 0) {
                                z15 = false;
                                if (z15) {
                                    String b14 = extapp.b();
                                    if (b14 == null || b14.length() == 0) {
                                        z16 = true;
                                    }
                                    if (z16) {
                                        n(str, str2, execute.code(), "deeplink and fallback is empty");
                                        return null;
                                    }
                                }
                                return extapp;
                            }
                        }
                        z15 = true;
                        if (z15) {
                        }
                        return extapp;
                    }
                }
                z14 = true;
                if (!z14) {
                }
            } catch (Exception e15) {
                e15.printStackTrace();
                Unit unit = Unit.INSTANCE;
                qb.a.a("requestExtAppInfoFromServer error =" + unit);
                n(str, str2, -1, e15.getMessage());
                return null;
            }
        }

        public final String i() {
            if (k.f132920g.length() == 0) {
                Application e14 = XYUtilsCenter.e();
                String property = System.getProperty("http.agent");
                StringBuilder sb3 = new StringBuilder(property + " ");
                String str = Build.MANUFACTURER;
                String str2 = Build.MODEL;
                sb3.append("Device/(" + str + f.f18324b + str2 + ") ");
                String r14 = com.xingin.utils.core.c.r(e14);
                StringBuilder sb4 = new StringBuilder();
                sb4.append("XHS/");
                sb4.append(r14);
                sb4.append(" ");
                sb3.append(sb4.toString());
                int q14 = com.xingin.utils.core.c.q(e14);
                sb3.append("XHSBUILD/" + q14 + " ");
                String e15 = com.xingin.utils.core.f.e(e14);
                sb3.append("NetType/" + e15 + " ");
                sb3.append("Optimize/true");
                String sb5 = sb3.toString();
                Intrinsics.checkNotNullExpressionValue(sb5, "StringBuilder(\"${System.…ptimize/true\").toString()");
                k.f132920g = sb5;
            }
            return k.f132920g;
        }

        public final void j(String str, String str2, ArrayList<String> arrayList) {
            Intrinsics.checkNotNullParameter(str, "id");
            Intrinsics.checkNotNullParameter(str2, "event");
            Intrinsics.checkNotNullParameter(arrayList, "sdkUrl");
            if (XYUtilsCenter.e() == null) {
                qb.a.d("AdReportManager", "please use it after commonUtils init");
            } else {
                mi2.a.m(new C2134b(str, str2, arrayList));
            }
        }

        public final void l(String str, String str2, ArrayList<String> arrayList) {
            Intrinsics.checkNotNullParameter(str, "id");
            Intrinsics.checkNotNullParameter(str2, "event");
            Intrinsics.checkNotNullParameter(arrayList, "sdkUrl");
            if (XYUtilsCenter.e() == null) {
                qb.a.d("AdReportManager", "please use it after commonUtils init");
            } else {
                mi2.a.m(new c(str, str2, arrayList));
            }
        }

        public final void n(String str, String str2, int i10, String str3) {
            we2.d.c(new j(str, i10, str3));
        }

        public final void p(String str, String str2, Function1<? super b, Unit> function1) {
            Intrinsics.checkNotNullParameter(str, "id");
            Intrinsics.checkNotNullParameter(str2, "event");
            Intrinsics.checkNotNullParameter(function1, "action");
            r W0 = r.O(new g(str, str2)).x1(mi2.a.f()).W0(gw2.a.a());
            Intrinsics.checkNotNullExpressionValue(W0, "create(\n                …dSchedulers.mainThread())");
            a0 a0Var = a0.D;
            Intrinsics.checkNotNullExpressionValue(a0Var, "UNBOUND");
            Object n14 = W0.n(com.uber.autodispose.d.b(a0Var));
            Intrinsics.checkExpressionValueIsNotNull(n14, "this.`as`(AutoDispose.autoDisposable(provider))");
            ((y) n14).a(new h(function1), i.f132913a);
        }
    }

    public k(Application application) {
        this.f132921a = application;
        d.b(application, new AdDBConfig());
        XhsDatabase a14 = d.a(AdDataBase.class);
        Intrinsics.checkNotNullExpressionValue(a14, "getInstance(AdDataBase::class.java)");
        AdDataBase adDataBase = (AdDataBase) a14;
        this.f132922b = adDataBase;
        this.f132923c = l.f132934e.a(adDataBase.getAdCatchDao());
    }

    public /* synthetic */ k(Application application, DefaultConstructorMarker defaultConstructorMarker) {
        this(application);
    }
}