package com.geetest.sdk.dialog.views; import android.animation.ObjectAnimator; import android.app.Activity; import android.content.Context; import android.os.Build; import android.os.Handler; import android.os.Message; import android.text.TextUtils; import android.view.ViewGroup; import android.webkit.JavascriptInterface; import com.geetest.sdk.GT3ConfigBean; import com.geetest.sdk.NoProguard; import com.geetest.sdk.au; import com.geetest.sdk.av; import com.geetest.sdk.f; import com.geetest.sdk.utils.g; import com.geetest.sdk.utils.h; import com.geetest.sdk.utils.i; import com.geetest.sdk.utils.l; import com.huawei.hms.framework.common.ContainerUtils; import java.util.HashMap; import java.util.List; import java.util.Map; import org.json.JSONObject; import u.e; public class WebviewBuilder { /* renamed from: m reason: collision with root package name */ private static final String f29293m = "WebviewBuilder"; /* renamed from: n reason: collision with root package name */ public static int f29294n; /* renamed from: o reason: collision with root package name */ public static int f29295o; /* renamed from: a reason: collision with root package name */ private Context f29296a; /* renamed from: b reason: collision with root package name */ private au f29297b; /* renamed from: c reason: collision with root package name */ private com.geetest.sdk.model.beans.b f29298c; /* renamed from: d reason: collision with root package name */ private GT3ConfigBean f29299d; /* renamed from: e reason: collision with root package name */ private int f29300e; /* renamed from: f reason: collision with root package name */ private int f29301f; /* renamed from: g reason: collision with root package name */ private f f29302g; /* renamed from: h reason: collision with root package name */ private int f29303h; /* renamed from: i reason: collision with root package name */ private GtWebView f29304i = null; /* renamed from: j reason: collision with root package name */ private String f29305j; /* renamed from: k reason: collision with root package name */ private Runnable f29306k; /* renamed from: l reason: collision with root package name */ private Handler f29307l = new b(); public class JSInterface implements NoProguard { public class a implements Runnable { /* renamed from: a reason: collision with root package name */ public final /* synthetic */ int f29309a; /* renamed from: b reason: collision with root package name */ public final /* synthetic */ String f29310b; public a(int i10, String str) { this.f29309a = i10; this.f29310b = str; } public void run() { if (WebviewBuilder.this.f29299d == null || WebviewBuilder.this.f29299d.getListener() == null) { l.b(WebviewBuilder.f29293m, "configBean is null !"); } else { WebviewBuilder.this.f29299d.getListener().onReceiveCaptchaCode(this.f29309a); } if (WebviewBuilder.this.f29297b == null) { return; } if (this.f29309a == 1) { WebviewBuilder.this.f29297b.a(true, this.f29310b); } else { WebviewBuilder.this.c(); } } } public class b implements Runnable { public b() { } public void run() { if (WebviewBuilder.this.f29304i != null && !WebviewBuilder.this.f29304i.b()) { if (WebviewBuilder.this.f29307l != null) { try { WebviewBuilder.this.f29307l.removeCallbacks(WebviewBuilder.this.f29306k); WebviewBuilder.this.f29307l.removeMessages(1); } catch (Exception unused) { } } if (WebviewBuilder.this.f29297b != null) { WebviewBuilder.this.f29297b.a(); } } } } public class c implements Runnable { /* renamed from: a reason: collision with root package name */ public final /* synthetic */ String f29313a; public c(String str) { this.f29313a = str; } public void run() { try { JSONObject jSONObject = new JSONObject(this.f29313a); WebviewBuilder.this.f29297b.a(jSONObject.getString("error_code").replaceAll("[a-zA-Z]", ""), jSONObject.getString("user_error")); } catch (Exception e10) { e10.printStackTrace(); au auVar = WebviewBuilder.this.f29297b; auVar.a("202", this.f29313a + "-->" + e10.toString()); } } } public class d implements Runnable { public d() { } public void run() { WebviewBuilder.this.f29304i.setVoice(true); WebviewBuilder.this.f29298c.i("voice"); int a10 = i.a(WebviewBuilder.this.f29296a); int b10 = i.b(WebviewBuilder.this.f29296a); int a11 = g.a(WebviewBuilder.this.f29296a, 275.0f); int a12 = g.a(WebviewBuilder.this.f29296a, 348.0f); int a13 = g.a(WebviewBuilder.this.f29296a, 300.0f); if (WebviewBuilder.this.f29296a.getApplicationContext().getResources().getConfiguration().orientation == 1) { int i10 = (b10 * 4) / 5; if (i10 >= a13) { a13 = i10; } if (i10 <= a12) { a12 = a13; } WebviewBuilder.f29294n = a12; WebviewBuilder.f29295o = (a12 * WebviewBuilder.this.f29303h) / 100; } else { int a14 = g.a(WebviewBuilder.this.f29296a, (float) (g.b(WebviewBuilder.this.f29296a, (float) a10) - 44)); if (a14 >= a11) { a11 = a14; } if (a14 <= a12) { a12 = a11; } WebviewBuilder.f29295o = a12; WebviewBuilder.f29294n = (a12 * 100) / WebviewBuilder.this.f29303h; } if (!(WebviewBuilder.this.f29304i == null || WebviewBuilder.this.f29304i.getLayoutParams() == null)) { ViewGroup.LayoutParams layoutParams = WebviewBuilder.this.f29304i.getLayoutParams(); layoutParams.width = WebviewBuilder.f29294n; layoutParams.height = WebviewBuilder.f29295o; WebviewBuilder.this.f29304i.setLayoutParams(layoutParams); } if (WebviewBuilder.this.f29302g != null) { com.geetest.sdk.utils.d.f29443a = true; try { WebviewBuilder.this.f29302g.show(); } catch (Exception e10) { e10.printStackTrace(); } } com.geetest.sdk.utils.d.f29443a = false; } } private JSInterface() { } @JavascriptInterface public void gt3Error(String str) { l.b("JSInterface-->gt3Error", str); if (WebviewBuilder.this.f29307l != null) { try { WebviewBuilder.this.f29307l.removeCallbacks(WebviewBuilder.this.f29306k); WebviewBuilder.this.f29307l.removeMessages(1); } catch (Exception unused) { } } if (WebviewBuilder.this.f29297b != null && WebviewBuilder.this.f29296a != null && (WebviewBuilder.this.f29296a instanceof Activity)) { ((Activity) WebviewBuilder.this.f29296a).runOnUiThread(new c(str)); } } @JavascriptInterface public void gtCallBack(String str, String str2, String str3) { String str4 = WebviewBuilder.f29293m; l.b(str4, "JSInterface-->gtCallBack-->code: " + str + ", message: " + str3); String str5 = WebviewBuilder.f29293m; l.d(str5, "JSInterface-->gtCallBack-->code: " + str + ", result: " + str2 + ", message: " + str3); try { int parseInt = Integer.parseInt(str); if (WebviewBuilder.this.f29296a != null && !((Activity) WebviewBuilder.this.f29296a).isFinishing()) { ((Activity) WebviewBuilder.this.f29296a).runOnUiThread(new a(parseInt, str2)); } } catch (Exception e10) { e10.printStackTrace(); } } @JavascriptInterface public void gtClose() { l.b(WebviewBuilder.f29293m, "JSInterface-->gtClose"); if (WebviewBuilder.this.f29297b != null) { WebviewBuilder.this.f29297b.b(); } } @JavascriptInterface public void gtNotify(String str) { String str2 = WebviewBuilder.f29293m; l.b(str2, "JSInterface-->gtNotify-->" + str); try { WebviewBuilder.this.f29303h = Integer.parseInt(new JSONObject(str).getString("aspect_radio")); if (WebviewBuilder.this.f29296a != null && !((Activity) WebviewBuilder.this.f29296a).isFinishing()) { ((Activity) WebviewBuilder.this.f29296a).runOnUiThread(new d()); } } catch (Exception e10) { e10.printStackTrace(); au auVar = WebviewBuilder.this.f29297b; auVar.a("202", "parse aspect_radio failed-->" + e10.toString()); } } @JavascriptInterface public void gtReady() { l.b(WebviewBuilder.f29293m, "JSInterface-->gtReady"); if (WebviewBuilder.this.f29296a != null && (WebviewBuilder.this.f29296a instanceof Activity)) { ((Activity) WebviewBuilder.this.f29296a).runOnUiThread(new b()); } } } public class b extends Handler { public b() { } public void handleMessage(Message message) { if (message.what == 1 && WebviewBuilder.this.f29297b != null) { l.b(WebviewBuilder.f29293m, String.format("handleMessage-->timeout %s !", Integer.valueOf(WebviewBuilder.this.f29298c.q()))); WebviewBuilder.this.f29297b.a("204", "load static resource timeout !"); } } } public class c implements Runnable { public c() { } public void run() { Message message = new Message(); message.what = 1; WebviewBuilder.this.f29307l.sendMessage(message); } } public WebviewBuilder(Context context, f fVar) { this.f29296a = context; this.f29297b = new au(); this.f29302g = fVar; } private float f() { return this.f29296a.getResources().getDisplayMetrics().density; } /* JADX WARNING: Code restructure failed: missing block: B:47:0x0154, code lost: if (r3 > r5) goto L_0x0169; */ /* JADX WARNING: Code restructure failed: missing block: B:50:0x015b, code lost: if (r3 > r6) goto L_0x0166; */ /* JADX WARNING: Removed duplicated region for block: B:58:0x016b */ /* JADX WARNING: Removed duplicated region for block: B:59:0x0175 */ private int g() { int i10; int i11; int a10 = i.a(this.f29296a); int b10 = i.b(this.f29296a); int a11 = g.a(this.f29296a, 300.0f); int a12 = g.a(this.f29296a, 275.0f); int a13 = g.a(this.f29296a, 410.0f); int a14 = g.a(this.f29296a, 348.0f); String str = f29293m; l.d(str, "widthScreen: " + g.b(this.f29296a, (float) b10)); if (a10 < b10) { i10 = (a10 * 4) / 5; } else { i10 = (b10 * 4) / 5; } if ("beeline".equals(this.f29298c.o()) || (i11 = this.f29303h) <= 60) { this.f29300e = a11; this.f29301f = (a11 * this.f29303h) / 100; } else if (i11 >= 100) { if (!"slide".equals(this.f29298c.o()) || Build.VERSION.SDK_INT >= 19) { if (a10 < b10) { Context context = this.f29296a; int a15 = g.a(context, (float) (g.b(context, (float) a10) - 44)); l.b(str, "limitationWidth: " + a15); if ((((Activity) this.f29296a).getWindow().getAttributes().flags & 1024) == 1024) { a15 = (a15 * 9) / 10; } if (h.b(this.f29296a)) { if (a15 >= a12) { a12 = a15; } } else if (a15 >= a12) { a12 = a15; } } else { if (i10 >= a11) { a11 = i10; } if (i10 <= a14) { a13 = a11; if (a10 < b10) { this.f29300e = (a13 * 100) / this.f29303h; this.f29301f = a13; } else { this.f29300e = a13; this.f29301f = (this.f29303h * a13) / 100; } i10 = a13; } } a13 = a14; if (a10 < b10) { } i10 = a13; } else { float f10 = f(); l.d(str, "scale: " + f10); int a16 = g.a(this.f29296a, 210.0f); int a17 = g.a(this.f29296a, 230.0f); int a18 = g.a(this.f29296a, 250.0f); int a19 = g.a(this.f29296a, 270.0f); int a20 = g.a(this.f29296a, 280.0f); int a21 = g.a(this.f29296a, 340.0f); double d10 = (double) f10; if (d10 <= 1.5d) { if (i10 >= a16) { a16 = i10; } if (i10 <= a12) { a12 = a16; } } else if (d10 <= 2.0d) { if (i10 >= a17) { a17 = i10; } a12 = i10 > a20 ? a20 : a17; } else if (d10 <= 3.0d) { a12 = i10 < a18 ? a18 : i10; if (i10 > a21) { a12 = a21; } } else { a12 = i10 < a19 ? a19 : i10; if (i10 > a14) { a12 = a14; } } } a13 = a12; if (a10 < b10) { } i10 = a13; } else { if (a10 < b10) { Context context2 = this.f29296a; int a22 = g.a(context2, (float) (g.b(context2, (float) a10) - 44)); if (a22 >= a12) { a12 = a22; } if (a22 <= a14) { a14 = a12; } } else { if (i10 >= a11) { a11 = i10; } if (i10 <= a14) { a14 = a11; } } this.f29300e = a14; this.f29301f = (this.f29303h * a14) / 100; i10 = a14; } l.d(str, "widthPX: " + i10); l.d(str, "widthDP: " + g.b(this.f29296a, (float) i10)); l.d(str, "height: " + this.f29303h); l.d(str, "mWidth: " + this.f29300e); l.d(str, "mHeight: " + this.f29301f); StringBuilder sb2 = new StringBuilder(); sb2.append("deviceWidth: "); Context context3 = this.f29296a; sb2.append(g.b(context3, (float) i.b(context3))); l.d(str, sb2.toString()); StringBuilder sb3 = new StringBuilder(); sb3.append("deviceHeight: "); Context context4 = this.f29296a; sb3.append(g.b(context4, (float) i.a(context4))); l.d(str, sb3.toString()); return i10; } public void b() { GtWebView gtWebView = this.f29304i; if (gtWebView != null) { gtWebView.removeJavascriptInterface("JSInterface"); ViewGroup viewGroup = (ViewGroup) this.f29304i.getParent(); if (viewGroup != null) { viewGroup.removeView(this.f29304i); } this.f29304i.removeAllViews(); this.f29304i.destroy(); this.f29304i = null; } try { Handler handler = this.f29307l; if (handler != null) { handler.removeCallbacks(this.f29306k); this.f29307l.removeMessages(1); this.f29307l = null; } } catch (Exception unused) { } } public void c() { GtWebView gtWebView = this.f29304i; if (gtWebView != null) { ObjectAnimator ofFloat = ObjectAnimator.ofFloat(gtWebView, e.f135456t, 0.0f, 2.0f, 4.0f, 2.0f, 0.0f, -2.0f, -4.0f, -2.0f, 0.0f, 2.0f, 4.0f, 2.0f, 0.0f, -2.0f, -4.0f, -2.0f, 0.0f); ofFloat.setDuration(500L); ofFloat.start(); } } public void d() { g(); GtWebView gtWebView = this.f29304i; if (gtWebView != null && gtWebView.getLayoutParams() != null) { f29294n = this.f29300e; f29295o = this.f29301f; ViewGroup.LayoutParams layoutParams = this.f29304i.getLayoutParams(); layoutParams.width = f29294n; layoutParams.height = f29295o; this.f29304i.setLayoutParams(layoutParams); } } public void a(av avVar) { this.f29297b.a(avVar); } public void a(com.geetest.sdk.model.beans.b bVar) { this.f29298c = bVar; } public void a(GT3ConfigBean gT3ConfigBean) { this.f29299d = gT3ConfigBean; } public GtWebView a() { String str; String str2; String str3; new HashMap(); this.f29303h = this.f29298c.l(); new HashMap(); Map<String, Integer> a10 = this.f29298c.j().a(); if (a10 == null || a10.size() <= 0) { str2 = ""; str = str2; } else { str2 = ""; str = str2; for (Map.Entry<String, Integer> entry : a10.entrySet()) { if (!TextUtils.isEmpty(entry.getKey())) { str = str + "&aspect_radio_" + entry.getKey() + ContainerUtils.KEY_VALUE_DELIMITER + entry.getValue(); str2 = str2 + "&" + entry.getKey() + ContainerUtils.KEY_VALUE_DELIMITER + this.f29298c.j().b().optString(entry.getKey()); } } } Map<String, String> e10 = this.f29298c.e(); if (e10 == null || e10.size() <= 0) { str3 = ""; } else { str3 = ""; for (Map.Entry<String, String> entry2 : e10.entrySet()) { if (!TextUtils.isEmpty(entry2.getKey())) { str3 = str3 + "&" + entry2.getKey() + ContainerUtils.KEY_VALUE_DELIMITER + entry2.getValue(); } } } this.f29305j = "?gt=" + this.f29298c.k() + "&challenge=" + this.f29298c.c() + "&lang=" + this.f29298c.m() + "&title=&type=" + this.f29298c.o() + "&api_server=" + this.f29298c.i().a() + "&static_servers=" + this.f29298c.i().b().toString().replace("[", "").replace("]", "") + "&width=100%&timeout=" + this.f29298c.t() + "&debug=" + this.f29298c.u() + str + str2 + str3; List<String> b10 = this.f29298c.i().b(); String str4 = (b10 == null || b10.size() <= 0) ? "https://static.geetest.com/static/appweb/app3-index.html" + this.f29305j : String.format("https://%s/static/appweb/app3-index.html", b10.get(0)) + this.f29305j; try { GtWebView gtWebView = new GtWebView(this.f29296a.getApplicationContext()); this.f29304i = gtWebView; gtWebView.a(); if (this.f29307l != null) { c cVar = new c(); this.f29306k = cVar; this.f29307l.postDelayed(cVar, (long) this.f29298c.q()); } this.f29304i.setObservable(this.f29297b); this.f29304i.setLayoutParams(new ViewGroup.LayoutParams(-2, -2)); this.f29304i.setStaticUrl(str4); this.f29304i.setDataBean(this.f29298c); this.f29304i.setMyHandler(this.f29307l); this.f29304i.setRunnable(this.f29306k); this.f29304i.loadUrl(str4); this.f29304i.buildLayer(); this.f29304i.addJavascriptInterface(new JSInterface(), "JSInterface"); this.f29304i.setTimeout(this.f29298c.q()); d(); } catch (Exception e11) { e11.printStackTrace(); l.b(f29293m, "默认webview内核丢失,错误码:204_3-->" + e11.toString()); for (StackTraceElement stackTraceElement : e11.getStackTrace()) { l.b(f29293m, stackTraceElement.toString()); } Handler handler = this.f29307l; if (handler != null) { try { handler.removeCallbacks(this.f29306k); this.f29307l.removeMessages(1); } catch (Exception unused) { } } au auVar = this.f29297b; if (auVar != null) { auVar.a("204_3", "webview crate error -->" + e11.toString()); } } return this.f29304i; } }