package tb; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.xingin.advert.report.AdBean; import com.xingin.advert.report.AdBodyBean; import com.xingin.advert.report.AdDao; import com.xingin.advert.report.AdReportBodyBean; import com.xingin.advert.report.AdServerResponseBean; import ja.b1; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; import kotlin.Metadata; import kotlin.NoWhenBranchMatchedException; import kotlin.Unit; import kotlin.collections.CollectionsKt__CollectionsJVMKt; import kotlin.collections.CollectionsKt__CollectionsKt; import kotlin.jvm.JvmStatic; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; import kotlin.text.StringsKt__StringsJVMKt; import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.ResponseBody; import org.json.JSONObject; import y7.f; import z60.h; @Metadata(bv = {}, d1 = {"\u0000@\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\b\u0003\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\b\n\u0002\b\u0004\n\u0002\u0010\t\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\t\b \u0018\u00002\u00020\u0001:\u0002\u0015\tB\u0017\u0012\u0006\u0010\u001c\u001a\u00020\u000e\u0012\u0006\u0010\u001d\u001a\u00020\u000e¢\u0006\u0004\b\u001e\u0010\u001fJ\b\u0010\u0003\u001a\u00020\u0002H&J\u0010\u0010\u0006\u001a\u00020\u00022\u0006\u0010\u0005\u001a\u00020\u0004H&J\u001c\u0010\t\u001a\u000e\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00040\b0\u00072\u0006\u0010\u0005\u001a\u00020\u0004H\u0014J\u001c\u0010\n\u001a\u000e\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00040\b0\u00072\u0006\u0010\u0005\u001a\u00020\u0004H\u0004J\u001c\u0010\u000b\u001a\u000e\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00040\b0\u00072\u0006\u0010\u0005\u001a\u00020\u0004H\u0004J&\u0010\u0011\u001a\b\u0012\u0004\u0012\u00020\f0\u00072\u0006\u0010\r\u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u000e2\u0006\u0010\u0010\u001a\u00020\fH\u0014J \u0010\u0015\u001a\u00020\u00042\u0006\u0010\u0012\u001a\u00020\u000e2\u0006\u0010\u0014\u001a\u00020\u00132\u0006\u0010\u0005\u001a\u00020\u0004H\u0002J\u0012\u0010\u0018\u001a\u00020\u00172\b\u0010\u0016\u001a\u0004\u0018\u00010\fH\u0002J \u0010\u001b\u001a\u00020\f2\u0006\u0010\u0019\u001a\u00020\u000e2\u0006\u0010\u001a\u001a\u00020\f2\u0006\u0010\u0010\u001a\u00020\fH\u0002¨\u0006 "}, d2 = {"Ltb/l;", "", "", "g", "Lcom/xingin/advert/report/AdBean;", "adBean", "c", "Ltb/l$b;", "", "b", "d", "e", "", "url", "", "method", "body", f.f156778k, "requestStatus", "", "costTime", "a", "response", "Lcom/xingin/advert/report/AdServerResponseBean;", h.f160753a, "status", "message", "i", "collectRetryCount", "reportRetryCount", "<init>", "(II)V", "ads_release"}, k = 1, mv = {1, 6, 0}) /* compiled from: BaseAdMonitorService.kt */ public abstract class l { /* renamed from: e reason: collision with root package name */ public static final a f132934e = new a(null); /* renamed from: a reason: collision with root package name */ public final int f132935a; /* renamed from: b reason: collision with root package name */ public final int f132936b; /* renamed from: c reason: collision with root package name */ public final OkHttpClient f132937c = new OkHttpClient(); /* renamed from: d reason: collision with root package name */ public final Gson f132938d = new Gson(); @Metadata(bv = {}, d1 = {"\u0000,\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0003\n\u0002\u0010\t\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\b\u0006\b\u0003\u0018\u00002\u00020\u0001B\t\b\u0002¢\u0006\u0004\b\u0011\u0010\u0012J\u0010\u0010\u0005\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0007J\b\u0010\u0007\u001a\u00020\u0006H\u0002R\u0014\u0010\b\u001a\u00020\u00068\u0002XT¢\u0006\u0006\n\u0004\b\b\u0010\tR\u0014\u0010\u000b\u001a\u00020\n8\u0000XT¢\u0006\u0006\n\u0004\b\u000b\u0010\fR\u0014\u0010\u000e\u001a\u00020\r8\u0002XT¢\u0006\u0006\n\u0004\b\u000e\u0010\u000fR\u0014\u0010\u0010\u001a\u00020\r8\u0002XT¢\u0006\u0006\n\u0004\b\u0010\u0010\u000f¨\u0006\u0013"}, d2 = {"Ltb/l$a;", "", "Lcom/xingin/advert/report/AdDao;", "adDao", "Ltb/l;", "a", "", "b", "DEFAULT_RETRY_COUNT", "I", "", "DELAY_TIME_FOR_RETRY", "J", "", "KEY_OF_RETRY_COUNT", "Ljava/lang/String;", "TAG", "<init>", "()V", "ads_release"}, k = 1, mv = {1, 6, 0}) /* compiled from: BaseAdMonitorService.kt */ public static final class a { @Metadata(bv = {}, d1 = {"\u0000\u000b\n\u0000\n\u0002\u0018\u0002\n\u0000*\u0001\u0000\b\n\u0018\u00002\b\u0012\u0004\u0012\u00028\u00000\u0001¨\u0006\u0002"}, d2 = {"tb/l$a$a", "Lcom/google/gson/reflect/TypeToken;", "xy_configcenter_library_release"}, k = 1, mv = {1, 6, 0}) /* renamed from: tb.l$a$a reason: collision with other inner class name */ /* compiled from: Config.kt */ public static final class C2135a extends TypeToken<Integer> { } public a() { } public /* synthetic */ a(DefaultConstructorMarker defaultConstructorMarker) { this(); } @JvmStatic public final l a(AdDao adDao) { Intrinsics.checkNotNullParameter(adDao, "adDao"); boolean Q = ua.a.f136547a.Q(); qb.a.b("AdMonitorService", "use new monitor service: " + Q); if (Q) { return new d(adDao, b()); } return new c(adDao); } public final int b() { ds0.f a14 = ds0.b.a(); Type type = new C2135a().getType(); Intrinsics.checkExpressionValueIsNotNull(type, "object : TypeToken<T>() {}.type"); return ((Number) a14.h("all_ads_thrid_monitor_retry_count", type, 10)).intValue(); } } @Metadata(bv = {}, d1 = {"\u0000\u0016\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\b0\u0018\u0000*\n\b\u0000\u0010\u0002 \u0001*\u00020\u00012\u00020\u0001:\u0002\u0005\u0006B\t\b\u0004¢\u0006\u0004\b\u0003\u0010\u0004\u0001\u0002\u0007\b¨\u0006\t"}, d2 = {"Ltb/l$b;", "", "T", "<init>", "()V", "a", "b", "Ltb/l$b$b;", "Ltb/l$b$a;", "ads_release"}, k = 1, mv = {1, 6, 0}) /* compiled from: BaseAdMonitorService.kt */ public static abstract class b<T> { @Metadata(bv = {}, d1 = {"\u0000$\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0010\b\b\u0018\u0000*\n\b\u0001\u0010\u0002 \u0001*\u00020\u00012\b\u0012\u0004\u0012\u00028\u00010\u0003B#\u0012\u0006\u0010\u000b\u001a\u00020\u0006\u0012\u0006\u0010\u000f\u001a\u00020\u0004\u0012\n\b\u0002\u0010\u0013\u001a\u0004\u0018\u00018\u0001¢\u0006\u0004\b\u0017\u0010\u0018J\t\u0010\u0005\u001a\u00020\u0004HÖ\u0001J\t\u0010\u0007\u001a\u00020\u0006HÖ\u0001J\u0013\u0010\n\u001a\u00020\t2\b\u0010\b\u001a\u0004\u0018\u00010\u0001HÖ\u0003R\u0017\u0010\u000b\u001a\u00020\u00068\u0006¢\u0006\f\n\u0004\b\u000b\u0010\f\u001a\u0004\b\r\u0010\u000eR\u0017\u0010\u000f\u001a\u00020\u00048\u0006¢\u0006\f\n\u0004\b\u000f\u0010\u0010\u001a\u0004\b\u0011\u0010\u0012R\u0019\u0010\u0013\u001a\u0004\u0018\u00018\u00018\u0006¢\u0006\f\n\u0004\b\u0013\u0010\u0014\u001a\u0004\b\u0015\u0010\u0016¨\u0006\u0019"}, d2 = {"Ltb/l$b$a;", "", "T", "Ltb/l$b;", "", "toString", "", "hashCode", "other", "", "equals", "status", "I", "c", "()I", "message", "Ljava/lang/String;", "b", "()Ljava/lang/String;", "data", "Ljava/lang/Object;", "a", "()Ljava/lang/Object;", "<init>", "(ILjava/lang/String;Ljava/lang/Object;)V", "ads_release"}, k = 1, mv = {1, 6, 0}) /* compiled from: BaseAdMonitorService.kt */ public static final class a<T> extends b<T> { /* renamed from: a reason: collision with root package name */ public final int f132939a; /* renamed from: b reason: collision with root package name */ public final String f132940b; /* renamed from: c reason: collision with root package name */ public final T f132941c; /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ a(int i10, String str, Object obj, int i14, DefaultConstructorMarker defaultConstructorMarker) { this(i10, str, (i14 & 4) != 0 ? null : obj); } public final T a() { return this.f132941c; } public final String b() { return this.f132940b; } public final int c() { return this.f132939a; } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof a)) { return false; } a aVar = (a) obj; return this.f132939a == aVar.f132939a && Intrinsics.areEqual(this.f132940b, aVar.f132940b) && Intrinsics.areEqual(this.f132941c, aVar.f132941c); } public int hashCode() { int hashCode = ((this.f132939a * 31) + this.f132940b.hashCode()) * 31; T t14 = this.f132941c; return hashCode + (t14 == null ? 0 : t14.hashCode()); } public String toString() { int i10 = this.f132939a; String str = this.f132940b; T t14 = this.f132941c; return "Error(status=" + i10 + ", message=" + str + ", data=" + ((Object) t14) + ")"; } /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public a(int i10, String str, T t14) { super(null); Intrinsics.checkNotNullParameter(str, "message"); this.f132939a = i10; this.f132940b = str; this.f132941c = t14; } } @Metadata(bv = {}, d1 = {"\u0000$\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\f\b\b\u0018\u0000*\n\b\u0001\u0010\u0002 \u0001*\u00020\u00012\b\u0012\u0004\u0012\u00028\u00010\u0003B\u0019\u0012\u0006\u0010\u000b\u001a\u00028\u0001\u0012\b\b\u0002\u0010\u000f\u001a\u00020\u0006¢\u0006\u0004\b\u0013\u0010\u0014J\t\u0010\u0005\u001a\u00020\u0004HÖ\u0001J\t\u0010\u0007\u001a\u00020\u0006HÖ\u0001J\u0013\u0010\n\u001a\u00020\t2\b\u0010\b\u001a\u0004\u0018\u00010\u0001HÖ\u0003R\u0017\u0010\u000b\u001a\u00028\u00018\u0006¢\u0006\f\n\u0004\b\u000b\u0010\f\u001a\u0004\b\r\u0010\u000eR\u0017\u0010\u000f\u001a\u00020\u00068\u0006¢\u0006\f\n\u0004\b\u000f\u0010\u0010\u001a\u0004\b\u0011\u0010\u0012¨\u0006\u0015"}, d2 = {"Ltb/l$b$b;", "", "T", "Ltb/l$b;", "", "toString", "", "hashCode", "other", "", "equals", "data", "Ljava/lang/Object;", "a", "()Ljava/lang/Object;", "status", "I", "b", "()I", "<init>", "(Ljava/lang/Object;I)V", "ads_release"}, k = 1, mv = {1, 6, 0}) /* renamed from: tb.l$b$b reason: collision with other inner class name */ /* compiled from: BaseAdMonitorService.kt */ public static final class C2136b<T> extends b<T> { /* renamed from: a reason: collision with root package name */ public final T f132942a; /* renamed from: b reason: collision with root package name */ public final int f132943b; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public C2136b(T t14, int i10) { super(null); Intrinsics.checkNotNullParameter(t14, "data"); this.f132942a = t14; this.f132943b = i10; } public final T a() { return this.f132942a; } public final int b() { return this.f132943b; } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof C2136b)) { return false; } C2136b bVar = (C2136b) obj; return Intrinsics.areEqual(this.f132942a, bVar.f132942a) && this.f132943b == bVar.f132943b; } public int hashCode() { return (this.f132942a.hashCode() * 31) + this.f132943b; } public String toString() { T t14 = this.f132942a; int i10 = this.f132943b; return "Success(data=" + ((Object) t14) + ", status=" + i10 + ")"; } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ C2136b(Object obj, int i10, int i14, DefaultConstructorMarker defaultConstructorMarker) { this(obj, (i14 & 2) != 0 ? 0 : i10); } } public b() { } public /* synthetic */ b(DefaultConstructorMarker defaultConstructorMarker) { this(); } } public l(int i10, int i14) { this.f132935a = i10; this.f132936b = i14; } public final AdBean a(int i10, long j14, AdBean adBean) { String str; AdBean adBean2 = new AdBean(); adBean2.setTimestamp(System.currentTimeMillis()); adBean2.setMethod(1); adBean2.setCount(0); adBean2.setMaxCount(this.f132936b); adBean2.setBaseUrl("https://referee.xiaohongshu.com/v1/stateReport"); Gson gson = new Gson(); AdReportBodyBean adReportBodyBean = new AdReportBodyBean(); adReportBodyBean.setUrl(adBean.getBaseUrl()); adReportBodyBean.setStatus(i10); adReportBodyBean.setRequestTimeSpent(((double) j14) / 1000.0d); adReportBodyBean.setRequestTimes(adBean.getCount() + 1); adReportBodyBean.setUserId(b1.f94179a.S0().getUserid()); adReportBodyBean.setUuid(adBean.getUuid()); adReportBodyBean.setCreateTime(adBean.getTimestamp()); try { str = ((AdBodyBean) this.f132938d.fromJson(adBean.getBody(), AdBodyBean.class)).getEvent(); } catch (Exception unused) { str = ""; } adReportBodyBean.setEvent(str); Unit unit = Unit.INSTANCE; String json = gson.toJson(adReportBodyBean); Intrinsics.checkNotNullExpressionValue(json, "Gson().toJson(AdReportBo… }\n })"); adBean2.setBody(json); return adBean2; } public b<List<AdBean>> b(AdBean adBean) { Intrinsics.checkNotNullParameter(adBean, "adBean"); f.f(f.f132903a, adBean.getBody(), null, 2, null); long currentTimeMillis = System.currentTimeMillis(); b<String> f14 = f(adBean.getBaseUrl(), adBean.getMethod(), adBean.getBody()); long currentTimeMillis2 = System.currentTimeMillis() - currentTimeMillis; if (f14 instanceof b.C2136b) { b.C2136b bVar = (b.C2136b) f14; AdServerResponseBean h10 = h((String) bVar.a()); ArrayList<String> requestURL = h10.getMetadata().getRequestURL(); ArrayList<String> arrayList = new ArrayList(); for (T t14 : requestURL) { if (!StringsKt__StringsJVMKt.isBlank(t14)) { arrayList.add(t14); } } ArrayList arrayList2 = new ArrayList(); for (String str : arrayList) { AdBean adBean2 = new AdBean(); adBean2.setTimestamp(System.currentTimeMillis()); adBean2.setMethod(0); adBean2.setCount(0); adBean2.setMaxCount(this.f132935a); adBean2.setBaseUrl(str); adBean2.setBody(adBean.getBody()); adBean2.setUuid(h10.getMetadata().getUuid()); arrayList2.add(adBean2); } if (arrayList2.isEmpty()) { String i10 = i(200, (String) bVar.a(), adBean.getBody()); qb.a.d("AdMonitorService", "emptyMonitoringLinks: " + i10); } arrayList2.add(a(bVar.b(), currentTimeMillis2, adBean)); return new b.C2136b(arrayList2, 0, 2, null); } else if (f14 instanceof b.a) { b.a aVar = (b.a) f14; String i14 = i(aVar.c(), aVar.b(), adBean.getBody()); String baseUrl = adBean.getBaseUrl(); qb.a.d("AdMonitorService", "getMonitorFailed: " + baseUrl + " error: " + i14); adBean.setCount(adBean.getCount() + 1); return new b.a(aVar.c(), i14, CollectionsKt__CollectionsJVMKt.listOf(a(aVar.c(), currentTimeMillis2, adBean))); } else { throw new NoWhenBranchMatchedException(); } } public abstract void c(AdBean adBean); public final b<List<AdBean>> d(AdBean adBean) { Intrinsics.checkNotNullParameter(adBean, "adBean"); long currentTimeMillis = System.currentTimeMillis(); b<String> f14 = f(adBean.getBaseUrl(), adBean.getMethod(), ""); long currentTimeMillis2 = System.currentTimeMillis() - currentTimeMillis; if (f14 instanceof b.C2136b) { return new b.C2136b(CollectionsKt__CollectionsJVMKt.listOf(a(((b.C2136b) f14).b(), currentTimeMillis2, adBean)), 0, 2, null); } if (f14 instanceof b.a) { b.a aVar = (b.a) f14; String i10 = i(aVar.c(), aVar.b(), adBean.getBody()); String baseUrl = adBean.getBaseUrl(); qb.a.d("AdMonitorService", "pingMonitorFailed: " + baseUrl + " error: " + i10); return new b.a(aVar.c(), i10, CollectionsKt__CollectionsJVMKt.listOf(a(aVar.c(), currentTimeMillis2, adBean))); } throw new NoWhenBranchMatchedException(); } public final b<List<AdBean>> e(AdBean adBean) { Intrinsics.checkNotNullParameter(adBean, "adBean"); b<String> f14 = f(adBean.getBaseUrl(), adBean.getMethod(), adBean.getBody()); if (f14 instanceof b.C2136b) { f.h(f.f132903a, adBean.getBody(), null, 2, null); return new b.C2136b(CollectionsKt__CollectionsKt.emptyList(), 0, 2, null); } else if (f14 instanceof b.a) { f.f132903a.d(adBean.getBody()); b.a aVar = (b.a) f14; String i10 = i(aVar.c(), aVar.b(), adBean.getBody()); String baseUrl = adBean.getBaseUrl(); qb.a.d("AdMonitorService", "statusReportFailed: " + baseUrl + " error: " + i10); return new b.a(aVar.c(), i10, null, 4, null); } else { throw new NoWhenBranchMatchedException(); } } public b<String> f(String str, int i10, String str2) { Intrinsics.checkNotNullParameter(str, "url"); Intrinsics.checkNotNullParameter(str2, "body"); if (StringsKt__StringsJVMKt.isBlank(str)) { return new b.a(-1, "Empty url", null, 4, null); } try { Request.Builder url = new Request.Builder().url(str); Intrinsics.checkNotNullExpressionValue(url, "Builder().url(url)"); if (i10 == 1) { url.post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str2)); } else { url.get(); } url.removeHeader("User-Agent"); url.addHeader("User-Agent", k.f132917d.i()); Response execute = this.f132937c.newCall(url.build()).execute(); if (execute.isSuccessful()) { ResponseBody body = execute.body(); String string = body != null ? body.string() : null; if (string == null) { string = ""; } return new b.C2136b(string, execute.code()); } int code = execute.code(); String message = execute.message(); Intrinsics.checkNotNullExpressionValue(message, "response.message()"); return new b.a(code, message, null, 4, null); } catch (Exception e14) { return new b.a(-1, e14.toString(), null, 4, null); } } public abstract void g(); public final AdServerResponseBean h(String str) { AdServerResponseBean adServerResponseBean; if (str != null) { try { adServerResponseBean = (AdServerResponseBean) this.f132938d.fromJson(str, AdServerResponseBean.class); } catch (Exception unused) { adServerResponseBean = new AdServerResponseBean(); } } else { adServerResponseBean = null; } return adServerResponseBean == null ? new AdServerResponseBean() : adServerResponseBean; } public final String i(int i10, String str, String str2) { JSONObject jSONObject = new JSONObject(); jSONObject.put("status", i10); jSONObject.put("message", str); jSONObject.put("data", str2); String jSONObject2 = jSONObject.toString(); Intrinsics.checkNotNullExpressionValue(jSONObject2, "JSONObject().apply {\n …ody)\n }.toString()"); return jSONObject2; } }