package tb; import android.annotation.SuppressLint; import com.google.android.gms.common.GoogleApiAvailabilityLight; import com.tencent.wcdb.database.SQLiteException; import com.xiaomi.mipush.sdk.Constants; import com.xingin.advert.report.AdBean; import com.xingin.advert.report.AdDao; import com.xingin.advert.report.MonitorApiService; import com.xingin.utils.async.run.task.XYRunnable; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import kotlin.Lazy; import kotlin.LazyKt__LazyJVMKt; import kotlin.Metadata; import kotlin.TuplesKt; import kotlin.collections.CollectionsKt___CollectionsKt; import kotlin.collections.MapsKt__MapsJVMKt; import kotlin.jvm.functions.Function0; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.Lambda; import okhttp3.MediaType; import okhttp3.RequestBody; import okhttp3.ResponseBody; import retrofit2.r; import tb.l; import wi2.h; import y7.f; @Metadata(bv = {}, d1 = {"\u0000L\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010 \n\u0002\b\u0003\n\u0002\u0010$\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0006\b\u0000\u0018\u00002\u00020\u0001:\u0001%B\u0017\u0012\u0006\u0010!\u001a\u00020 \u0012\u0006\u0010\"\u001a\u00020\t¢\u0006\u0004\b#\u0010$J\b\u0010\u0003\u001a\u00020\u0002H\u0016J\u0010\u0010\u0006\u001a\u00020\u00022\u0006\u0010\u0005\u001a\u00020\u0004H\u0016J&\u0010\r\u001a\b\u0012\u0004\u0012\u00020\u00070\f2\u0006\u0010\b\u001a\u00020\u00072\u0006\u0010\n\u001a\u00020\t2\u0006\u0010\u000b\u001a\u00020\u0007H\u0014J\b\u0010\u000e\u001a\u00020\u0002H\u0002J\u0010\u0010\u000f\u001a\u00020\u00022\u0006\u0010\u0005\u001a\u00020\u0004H\u0002J\u0010\u0010\u0010\u001a\u00020\u00022\u0006\u0010\u0005\u001a\u00020\u0004H\u0003J\u0016\u0010\u0013\u001a\u00020\u00022\f\u0010\u0012\u001a\b\u0012\u0004\u0012\u00020\u00040\u0011H\u0002J\u0010\u0010\u0014\u001a\u00020\u00022\u0006\u0010\u0005\u001a\u00020\u0004H\u0002R'\u0010\u001a\u001a\u000e\u0012\u0004\u0012\u00020\u0007\u0012\u0004\u0012\u00020\u00070\u00158BX\u0002¢\u0006\f\n\u0004\b\u0016\u0010\u0017\u001a\u0004\b\u0018\u0010\u0019R\u001d\u0010\u001f\u001a\u0004\u0018\u00010\u001b8BX\u0002¢\u0006\f\n\u0004\b\u001c\u0010\u0017\u001a\u0004\b\u001d\u0010\u001e¨\u0006&"}, d2 = {"Ltb/d;", "Ltb/l;", "", "g", "Lcom/xingin/advert/report/AdBean;", "adBean", "c", "", "url", "", "method", "body", "Ltb/l$b;", f.f156778k, GoogleApiAvailabilityLight.TRACKING_SOURCE_NOTIFICATION, "m", "r", "", "beans", "l", "q", "", "headers$delegate", "Lkotlin/Lazy;", "o", "()Ljava/util/Map;", "headers", "Lokhttp3/MediaType;", "mediaType$delegate", com.igexin.push.core.d.c.f25536c, "()Lokhttp3/MediaType;", "mediaType", "Lcom/xingin/advert/report/AdDao;", "adDao", "retryCount", "<init>", "(Lcom/xingin/advert/report/AdDao;I)V", "a", "ads_release"}, k = 1, mv = {1, 6, 0}) /* compiled from: AdMonitorService2.kt */ public final class d extends l { /* renamed from: l reason: collision with root package name */ public static final a f132887l = new a(null); /* renamed from: f reason: collision with root package name */ public final AdDao f132888f; /* renamed from: g reason: collision with root package name */ public final MonitorApiService f132889g = ((MonitorApiService) fz1.b.f80449a.d(MonitorApiService.class)); /* renamed from: h reason: collision with root package name */ public final ConcurrentLinkedQueue<AdBean> f132890h; /* renamed from: i reason: collision with root package name */ public final ScheduledExecutorService f132891i; /* renamed from: j reason: collision with root package name */ public final Lazy f132892j; /* renamed from: k reason: collision with root package name */ public final Lazy f132893k; @Metadata(bv = {}, d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u000e\n\u0002\b\u0005\b\u0003\u0018\u00002\u00020\u0001B\t\b\u0002¢\u0006\u0004\b\u0005\u0010\u0006R\u0014\u0010\u0003\u001a\u00020\u00028\u0002XT¢\u0006\u0006\n\u0004\b\u0003\u0010\u0004¨\u0006\u0007"}, d2 = {"Ltb/d$a;", "", "", "TAG", "Ljava/lang/String;", "<init>", "()V", "ads_release"}, k = 1, mv = {1, 6, 0}) /* compiled from: AdMonitorService2.kt */ public static final class a { public a() { } public /* synthetic */ a(DefaultConstructorMarker defaultConstructorMarker) { this(); } } @Metadata(bv = {}, d1 = {"\u0000\u0011\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\b\u0002*\u0001\u0000\b\n\u0018\u00002\u00020\u0001J\b\u0010\u0003\u001a\u00020\u0002H\u0016¨\u0006\u0004"}, d2 = {"tb/d$b", "Lcom/xingin/utils/async/run/task/XYRunnable;", "", "execute", "ads_release"}, k = 1, mv = {1, 6, 0}) /* compiled from: AdMonitorService2.kt */ public static final class b extends XYRunnable { /* renamed from: a reason: collision with root package name */ public final /* synthetic */ d f132894a; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public b(d dVar, h hVar) { super("GetAndPing", hVar); this.f132894a = dVar; } @Override // com.xingin.utils.async.run.task.XYRunnable public void execute() { while (!this.f132894a.f132890h.isEmpty()) { AdBean adBean = (AdBean) this.f132894a.f132890h.poll(); if (adBean != null) { this.f132894a.q(adBean); } } } } @Metadata(d1 = {"\u0000\f\n\u0000\n\u0002\u0010$\n\u0002\u0010\u000e\n\u0000\u0010\u0000\u001a\u000e\u0012\u0004\u0012\u00020\u0002\u0012\u0004\u0012\u00020\u00020\u0001H\n¢\u0006\u0002\b\u0003"}, d2 = {"<anonymous>", "", "", "invoke"}, k = 3, mv = {1, 6, 0}, xi = 48) /* compiled from: AdMonitorService2.kt */ public static final class c extends Lambda implements Function0<Map<String, ? extends String>> { /* renamed from: a reason: collision with root package name */ public static final c f132895a = new c(); public c() { super(0); } /* Return type fixed from 'java.util.Map<java.lang.String, java.lang.String>' to match base method */ @Override // kotlin.jvm.functions.Function0 public final Map<String, ? extends String> invoke() { return MapsKt__MapsJVMKt.mapOf(TuplesKt.to("User-Agent", k.f132917d.i())); } } @Metadata(bv = {}, d1 = {"\u0000\b\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0001\u001a\u0004\u0018\u00010\u0000H\n¢\u0006\u0004\b\u0001\u0010\u0002"}, d2 = {"Lokhttp3/MediaType;", "a", "()Lokhttp3/MediaType;"}, k = 3, mv = {1, 6, 0}) /* renamed from: tb.d$d reason: collision with other inner class name */ /* compiled from: AdMonitorService2.kt */ public static final class C2133d extends Lambda implements Function0<MediaType> { /* renamed from: a reason: collision with root package name */ public static final C2133d f132896a = new C2133d(); public C2133d() { super(0); } /* renamed from: a */ public final MediaType invoke() { return MediaType.parse("application/json; charset=utf-8"); } } @Metadata(bv = {}, d1 = {"\u0000\u0011\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\b\u0002*\u0001\u0000\b\n\u0018\u00002\u00020\u0001J\b\u0010\u0003\u001a\u00020\u0002H\u0016¨\u0006\u0004"}, d2 = {"tb/d$e", "Lcom/xingin/utils/async/run/task/XYRunnable;", "", "execute", "ads_release"}, k = 1, mv = {1, 6, 0}) /* compiled from: AdMonitorService2.kt */ public static final class e extends XYRunnable { /* renamed from: a reason: collision with root package name */ public final /* synthetic */ AdBean f132897a; /* renamed from: b reason: collision with root package name */ public final /* synthetic */ d f132898b; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public e(AdBean adBean, d dVar) { super("retryAdMon", null, 2, null); this.f132897a = adBean; this.f132898b = dVar; } @Override // com.xingin.utils.async.run.task.XYRunnable public void execute() { String baseUrl = this.f132897a.getBaseUrl(); String body = this.f132897a.getBody(); qb.a.b("AdMonitorService2", "retry: " + baseUrl + " " + body); this.f132898b.q(this.f132897a); } } /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public d(AdDao adDao, int i10) { super(i10, i10); Intrinsics.checkNotNullParameter(adDao, "adDao"); this.f132888f = adDao; ConcurrentLinkedQueue<AdBean> concurrentLinkedQueue = new ConcurrentLinkedQueue<>(); this.f132890h = concurrentLinkedQueue; this.f132891i = wi2.e.j(ti2.a.b() + 1, "ads_3", h.HIGH); this.f132892j = LazyKt__LazyJVMKt.lazy(c.f132895a); this.f132893k = LazyKt__LazyJVMKt.lazy(C2133d.f132896a); try { concurrentLinkedQueue.addAll(AdDao.a.a(adDao, System.currentTimeMillis(), null, 2, null)); concurrentLinkedQueue.addAll(AdDao.a.b(adDao, null, 1, null)); String str = CollectionsKt___CollectionsKt.joinToString$default(concurrentLinkedQueue, ", ", null, null, 0, null, null, 62, null); qb.a.a("load monitor: " + str); } catch (SQLiteException e14) { qb.a.c("load monitor failed: " + e14); } } @Override // tb.l public void c(AdBean adBean) { Intrinsics.checkNotNullParameter(adBean, "adBean"); qb.a.a("add monitor: " + adBean); this.f132890h.add(adBean); n(); } @Override // tb.l public l.b<String> f(String str, int i10, String str2) { r<ResponseBody> rVar; Intrinsics.checkNotNullParameter(str, "url"); Intrinsics.checkNotNullParameter(str2, "body"); qb.a.b("3Monitor", str + ", " + str2); if (!Intrinsics.areEqual("https://referee.xiaohongshu.com/v1/third/collect", str) && !Intrinsics.areEqual("https://referee.xiaohongshu.com/v1/stateReport", str)) { return super.f(str, i10, str2); } try { RequestBody create = RequestBody.create(p(), str2); if (Intrinsics.areEqual(str, "https://referee.xiaohongshu.com/v1/third/collect")) { MonitorApiService monitorApiService = this.f132889g; Map<String, String> o14 = o(); Intrinsics.checkNotNullExpressionValue(create, "requestBody"); rVar = monitorApiService.collect(o14, create).execute(); } else if (Intrinsics.areEqual(str, "https://referee.xiaohongshu.com/v1/stateReport")) { MonitorApiService monitorApiService2 = this.f132889g; Map<String, String> o15 = o(); Intrinsics.checkNotNullExpressionValue(create, "requestBody"); rVar = monitorApiService2.stateReport(o15, create).execute(); } else { return new l.b.a(-1, "unknown url: " + str, null, 4, null); } if (rVar.f()) { ResponseBody a14 = rVar.a(); String string = a14 != null ? a14.string() : null; if (string == null) { string = ""; } return new l.b.C2136b(string, rVar.b()); } int b14 = rVar.b(); String g10 = rVar.g(); Intrinsics.checkNotNullExpressionValue(g10, "response.message()"); return new l.b.a(b14, g10, null, 4, null); } catch (Exception e14) { return new l.b.a(-1, e14.toString(), null, 4, null); } } @Override // tb.l public void g() { n(); } public final void l(List<AdBean> list) { for (T t14 : list) { try { this.f132888f.insert(t14); } catch (Throwable th3) { String baseUrl = t14.getBaseUrl(); qb.a.d("AdMonitorService2", "dbError: " + baseUrl + " insert failed: " + th3); } qb.a.a("insert monitor: " + ((Object) t14)); } this.f132890h.addAll(list); } public final void m(AdBean adBean) { try { this.f132888f.delete(adBean); } catch (Throwable th3) { String baseUrl = adBean.getBaseUrl(); qb.a.d("AdMonitorService2", "dbError: " + baseUrl + " delete failed: " + th3); } qb.a.a("delete monitor: " + adBean); } public final void n() { this.f132891i.execute(new b(this, h.HIGH)); } public final Map<String, String> o() { return (Map) this.f132892j.getValue(); } public final MediaType p() { return (MediaType) this.f132893k.getValue(); } public final void q(AdBean adBean) { l.b<List<AdBean>> bVar; qb.a.a("handle monitor: " + adBean); String baseUrl = adBean.getBaseUrl(); if (Intrinsics.areEqual(baseUrl, "https://referee.xiaohongshu.com/v1/third/collect")) { bVar = b(adBean); } else if (Intrinsics.areEqual(baseUrl, "https://referee.xiaohongshu.com/v1/stateReport")) { bVar = e(adBean); } else { bVar = d(adBean); } adBean.setCount(adBean.getCount() + 1); if (bVar instanceof l.b.a) { if (adBean.getCount() >= adBean.getMaxCount()) { m(adBean); } else { r(adBean); } List<AdBean> list = (List) ((l.b.a) bVar).a(); if (list != null) { l(list); } } else if (bVar instanceof l.b.C2136b) { m(adBean); l((List) ((l.b.C2136b) bVar).a()); } } @SuppressLint({"CheckResult"}) public final void r(AdBean adBean) { try { this.f132888f.update(adBean); } catch (Throwable th3) { String baseUrl = adBean.getBaseUrl(); qb.a.d("AdMonitorService2", "dbError: " + baseUrl + " update failed: " + th3); } qb.a.a("update monitor: " + adBean); this.f132891i.schedule(new e(adBean, this), Constants.ASSEMBLE_PUSH_NETWORK_INTERVAL, TimeUnit.MILLISECONDS); } }