package com.ss.android.ugc.tiktok.seclink.impl; import X.AbstractC09210Ys; import X.AbstractC09220Yt; import X.AbstractC80073Dg; import X.AbstractC80123Dl; import X.AnonymousClass0FY; import X.AnonymousClass0WE; import X.AnonymousClass0Z3; import X.AnonymousClass0ZB; import X.AnonymousClass0ZI; import X.AnonymousClass0ZQ; import X.AnonymousClass1ZP; import X.AnonymousClass1ZS; import X.AnonymousClass2PS; import X.AnonymousClass3DZ; import X.AnonymousClass3EZ; import X.C16360kz; import X.C21090sc; import X.C23710wq; import X.C39581hL; import X.C44231oq; import X.C44241or; import X.C50691zG; import X.C80013Da; import X.C80023Db; import X.C80043Dd; import X.C80053De; import X.C80063Df; import X.C80113Dk; import X.EB6; import X.View$OnAttachStateChangeListenerC80033Dc; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.text.TextUtils; import android.view.View; import android.webkit.WebView; import com.bytedance.covode.number.Covode; import com.bytedance.ies.abmock.SettingsManager; import com.bytedance.ies.bullet.kit.web.SSWebView; import com.bytedance.retrofit2.mime.TypedByteArray; import com.bytedance.retrofit2.mime.TypedOutput; import com.bytedance.ttnet.utils.RetrofitUtils; import com.ss.android.ugc.aweme.setting.services.ISettingService; import com.ss.android.ugc.aweme.setting.services.SettingServiceImpl; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import kotlin.g.b.m; import org.json.JSONObject; public final class SecLinkManager { public static Map<View, AbstractC80073Dg> LIZ = new ConcurrentHashMap(); public static final SecLinkManager LIZIZ; public interface SecLinkDataApi { static { Covode.recordClassIndex(114915); } @AnonymousClass0ZB AnonymousClass0ZI<String> executePost(@AbstractC09210Ys String str, @AbstractC09220Yt TypedOutput typedOutput, @AnonymousClass0Z3 List<AnonymousClass0ZQ> list); } static { Covode.recordClassIndex(114912); SecLinkManager secLinkManager = new SecLinkManager(); LIZIZ = secLinkManager; Context LIZ2 = AnonymousClass0WE.LJJI.LIZ(); String valueOf = String.valueOf(AnonymousClass0WE.LJIILJJIL); ISettingService LJIJJLI = SettingServiceImpl.LJIJJLI(); m.LIZIZ(LJIJJLI, ""); String LIZ3 = LJIJJLI.LIZ(LJIJJLI.LIZ(AnonymousClass0WE.LJJI.LIZ()).LIZJ()); if (LIZ2 == null) { throw new RuntimeException("context can not be null."); } else if (!TextUtils.isEmpty(valueOf)) { String str = "https://www.tiktok.com/link//"; if (!TextUtils.isEmpty(str)) { Context applicationContext = LIZ2.getApplicationContext(); if (C16360kz.LIZJ && applicationContext == null) { applicationContext = C16360kz.LIZ; } C80063Df.LIZ = applicationContext; C80053De r0 = new C80053De(); C80063Df.LIZIZ = r0; r0.LIZ = valueOf; C80063Df.LIZIZ.LIZIZ = LIZ3; C80053De r2 = C80063Df.LIZIZ; if (!TextUtils.isEmpty(str)) { str = str.substring(0, 28); } r2.LIZJ = str; C80063Df.LIZJ = true; if (!SettingsManager.LIZ().LIZ("disable_jsballowlist_exportedto_seclinkallowlist", true)) { secLinkManager.LIZ(C80113Dk.LIZ(Collections.singletonList("host"))); } if (C44241or.LIZIZ.LIZ().LIZ) { C80053De r22 = C80063Df.LIZIZ; m.LIZIZ(r22, ""); r22.LJ = C44241or.LIZIZ.LIZ().LIZIZ; secLinkManager.LIZ(AnonymousClass2PS.LIZIZ.LIZ().LIZ); } else { String[] LIZ4 = C50691zG.LIZ(); if (!(LIZ4 == null || LIZ4.length == 0)) { secLinkManager.LIZ(AnonymousClass1ZP.LIZIZ(Arrays.copyOf(LIZ4, LIZ4.length))); } } AnonymousClass3EZ.LIZ = new AbstractC80123Dl() { /* class com.ss.android.ugc.tiktok.seclink.impl.SecLinkManager.AnonymousClass1 */ static { Covode.recordClassIndex(114913); } @Override // X.AbstractC80123Dl public final String LIZ(String str, JSONObject jSONObject) { C21090sc.LIZ(str, jSONObject); if (TextUtils.isEmpty(str)) { return null; } ArrayList arrayList = new ArrayList(); arrayList.add(new AnonymousClass0ZQ("Content-Type", "application/json")); String jSONObject2 = jSONObject.toString(); m.LIZIZ(jSONObject2, ""); Charset forName = Charset.forName("UTF-8"); m.LIZIZ(forName, ""); Objects.requireNonNull(jSONObject2, "null cannot be cast to non-null type java.lang.String"); byte[] bytes = jSONObject2.getBytes(forName); m.LIZIZ(bytes, ""); return ((SecLinkDataApi) RetrofitUtils.LIZ("https://www.tiktok.com/link/", SecLinkDataApi.class)).executePost(str, new TypedByteArray(null, bytes, new String[0]), arrayList).execute().LIZIZ; } @Override // X.AbstractC80123Dl public final void LIZ(String str, JSONObject jSONObject, AnonymousClass3DZ r11) { C21090sc.LIZ(str, jSONObject, r11); if (!TextUtils.isEmpty(str)) { ArrayList arrayList = new ArrayList(); arrayList.add(new AnonymousClass0ZQ("Content-Type", "application/json")); String jSONObject2 = jSONObject.toString(); m.LIZIZ(jSONObject2, ""); Charset forName = Charset.forName("UTF-8"); m.LIZIZ(forName, ""); Objects.requireNonNull(jSONObject2, "null cannot be cast to non-null type java.lang.String"); byte[] bytes = jSONObject2.getBytes(forName); m.LIZIZ(bytes, ""); ((SecLinkDataApi) RetrofitUtils.LIZ("https://www.tiktok.com/link/", SecLinkDataApi.class)).executePost(str, new TypedByteArray(null, bytes, new String[0]), arrayList).enqueue(new C80013Da(r11)); } } }; return; } throw new RuntimeException("host can not be empty."); } else { throw new RuntimeException("aid can not be empty."); } } public static String LIZ(Intent intent, String str) { try { return intent.getStringExtra(str); } catch (Exception unused) { return null; } } private void LIZ(List<String> list) { C80053De r1 = C80063Df.LIZIZ; if (r1.LIZLLL == null) { r1.LIZLLL = new ArrayList(); } r1.LIZLLL.addAll(list); } public final String LIZ(String str, String str2) { if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2) || C80063Df.LIZIZ == null || C80023Db.LIZ(str)) { return str; } Uri parse = Uri.parse(str); m.LIZIZ(parse, ""); String host = parse.getHost(); C80053De r0 = C80063Df.LIZIZ; m.LIZIZ(r0, ""); List<String> list = r0.LIZLLL; if (list != null && (!list.isEmpty())) { Iterator<String> it = list.iterator(); while (true) { if (!it.hasNext()) { break; } String next = it.next(); m.LIZIZ(next, ""); if (!TextUtils.isEmpty(host)) { if (TextUtils.equals(host, next)) { break; } if (host == null) { m.LIZIZ(); } if (AnonymousClass1ZS.LIZJ(host, ".".concat(String.valueOf(next)), false)) { break; } } } if (TextUtils.equals("https", parse.getScheme())) { return str; } } return C80023Db.LIZ(str, str2, -1); } public final void LIZ(WebView webView, String str) { C21090sc.LIZ(webView); webView.addOnAttachStateChangeListener(new View$OnAttachStateChangeListenerC80033Dc()); AbstractC80073Dg LIZ2 = C80063Df.LIZ(webView, str); LIZ2.LIZ(); Map<View, AbstractC80073Dg> map = LIZ; m.LIZIZ(LIZ2, ""); map.put(webView, LIZ2); } public final Boolean LIZIZ(WebView webView, String str) { T t; T t2; boolean z; C21090sc.LIZ(webView); boolean z2 = false; if (str == null || !C80023Db.LIZ(str, "http")) { return false; } List<C80043Dd> list = C39581hL.LIZIZ.LIZ().LIZIZ; if (list != null) { Iterator<T> it = list.iterator(); while (true) { if (!it.hasNext()) { t2 = null; break; } t2 = it.next(); T t3 = t2; int i2 = t3.LIZIZ; if (i2 == TypeEnum.START_WITH.getType()) { z = AnonymousClass1ZS.LIZIZ(str, t3.LIZ, false); continue; } else if (i2 == TypeEnum.CONTAINS.getType()) { z = AnonymousClass1ZS.LIZ((CharSequence) str, (CharSequence) t3.LIZ, false); continue; } else if (i2 == TypeEnum.REGEX_MATCHES.getType()) { z = new C23710wq(t3.LIZ).matches(str); continue; } else if (i2 == TypeEnum.REGEX_CONTAINS_MATCH_IN.getType()) { z = new C23710wq(t3.LIZ).containsMatchIn(str); continue; } else if (i2 == TypeEnum.EQUAL.getType()) { z = m.LIZ((Object) t3.LIZ, (Object) str); continue; } else { z = false; continue; } if (z) { break; } } if (t2 != null) { LIZIZ.LIZ(webView, "common"); } } AbstractC80073Dg r1 = LIZ.get(webView); if (r1 != null) { String url = webView.getUrl(); Boolean valueOf = webView instanceof SSWebView ? Boolean.valueOf(((SSWebView) webView).LIZ()) : webView instanceof EB6 ? Boolean.valueOf(((EB6) webView).hasClickInTimeInterval()) : null; C44231oq LIZ2 = C44241or.LIZIZ.LIZ(); if (!(url == null || url.length() == 0) && LIZ2.LIZ) { Iterator<T> it2 = LIZ2.LIZJ.iterator(); while (true) { if (!it2.hasNext()) { t = null; break; } t = it2.next(); if ((url != null ? Boolean.valueOf(AnonymousClass1ZS.LIZ((CharSequence) url, (CharSequence) t, false)) : null).booleanValue()) { break; } } T t4 = t; if (t4 == null || t4.length() == 0) { z2 = true; } } if (!z2 || !m.LIZ((Object) valueOf, (Object) false)) { r1.LIZJ(str); } else { boolean LIZLLL = r1.LIZLLL(str); JSONObject jSONObject = new JSONObject(); if (str == null || C80023Db.LIZ(str, "http")) { try { Uri parse = Uri.parse(str); m.LIZIZ(parse, ""); jSONObject.put("host", parse.getHost()); jSONObject.put("url", str); if (url != null) { Uri parse2 = Uri.parse(url); m.LIZIZ(parse2, ""); jSONObject.put("origin_hos", parse2.getHost()); jSONObject.put("origin_url", url); } } catch (Exception unused) { } AnonymousClass0FY.LIZ("monitor_seclink_first_jump", jSONObject, (JSONObject) null, (JSONObject) null); } return Boolean.valueOf(LIZLLL); } } return false; } }