package com.intsig.webview; import android.content.Context; import android.net.Uri; import android.text.TextUtils; import android.webkit.WebView; import androidx.annotation.NonNull; import androidx.work.Data; import com.intsig.log.LogUtils; import com.intsig.tianshu.URLEncoder; import com.intsig.utils.AESNopadding; import com.intsig.utils.ApplicationHelper; import com.intsig.utils.WhiteHostListManager; import com.microsoft.aad.adal.ClientMetricsEndpointType; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.Set; import java.util.regex.Pattern; public class WebViewUtils { /* renamed from: a reason: collision with root package name */ public static String f41237a; /* renamed from: b reason: collision with root package name */ public static boolean f41238b; /* renamed from: c reason: collision with root package name */ private static Pattern f41239c; /* renamed from: d reason: collision with root package name */ public static WebViewAppInterface f41240d; static String a(String str) { String str2 = str; boolean z10 = false; try { if (new URL(str2).getProtocol() != null) { z10 = true; if (!z10 && str2 != null && !str2.contains(":")) { str2 = "http://" + str2; LogUtils.a("WebViewUtils", "addHttpProtocolIfNotExist = " + str2); } return str2; } } catch (MalformedURLException e10) { LogUtils.a("WebViewUtils", "addHttpSchemeIfNo: " + e10.getMessage()); } str2 = "http://" + str2; LogUtils.a("WebViewUtils", "addHttpProtocolIfNotExist = " + str2); return str2; } static String b(String str, String str2) { String str3; MalformedURLException e10; String str4; if (!TextUtils.isEmpty(str2) && !TextUtils.isEmpty(str)) { if (!str2.startsWith("http")) { try { URL url = new URL(str); if (str2.startsWith("/")) { str3 = url.getProtocol() + "://" + url.getHost() + str2; } else { String str5 = url.getProtocol() + "://" + url.getHost() + url.getPath(); try { if (!str5.endsWith("/")) { str5 = str5 + "/"; } str3 = str5 + str2; } catch (MalformedURLException e11) { str4 = str5; e10 = e11; LogUtils.e("WebViewUtils", e10); str3 = str4; LogUtils.a("WebViewUtils", "calculateIconUrl: from " + str2 + " to " + str3); str2 = str3; return str2; } } } catch (MalformedURLException e12) { e10 = e12; str4 = str2; LogUtils.e("WebViewUtils", e10); str3 = str4; LogUtils.a("WebViewUtils", "calculateIconUrl: from " + str2 + " to " + str3); str2 = str3; return str2; } } else { str3 = str2; } LogUtils.a("WebViewUtils", "calculateIconUrl: from " + str2 + " to " + str3); str2 = str3; } return str2; } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r1v5, types: [java.net.HttpURLConnection] */ /* JADX WARN: Type inference failed for: r1v12 */ /* JADX WARN: Type inference failed for: r1v14 */ /* JADX WARNING: Removed duplicated region for block: B:43:0x00d9 */ /* JADX WARNING: Removed duplicated region for block: B:46:0x00e1 */ /* JADX WARNING: Removed duplicated region for block: B:52:0x00eb */ /* JADX WARNING: Removed duplicated region for block: B:55:0x00f3 */ static boolean c(String str, String str2) { Throwable th; FileOutputStream fileOutputStream; HttpURLConnection httpURLConnection; Exception e10; HttpURLConnection httpURLConnection2; FileOutputStream fileOutputStream2; boolean z10 = false; if (!TextUtils.isEmpty(str)) { if (!TextUtils.isEmpty(str2)) { FileOutputStream fileOutputStream3 = null; try { LogUtils.h("WebViewUtils", "downLoadIcon from " + str + "start"); HttpURLConnection.setFollowRedirects(false); HttpURLConnection httpURLConnection3 = (HttpURLConnection) new URL(str).openConnection(); try { int responseCode = httpURLConnection3.getResponseCode(); InputStream inputStream = httpURLConnection3.getInputStream(); LogUtils.h("WebViewUtils", "downLoadIcon from " + str + ", responseCode=" + responseCode + ", is = " + inputStream); if (inputStream != null) { fileOutputStream = new FileOutputStream(str2); try { byte[] bArr = new byte[Data.MAX_DATA_BYTES]; while (true) { int read = inputStream.read(bArr); if (read == -1) { break; } fileOutputStream.write(bArr, 0, read); } fileOutputStream.close(); inputStream.close(); z10 = true; LogUtils.h("WebViewUtils", "downLoadIcon success"); fileOutputStream2 = fileOutputStream; } catch (Exception e11) { e10 = e11; httpURLConnection2 = httpURLConnection3; try { LogUtils.d("WebViewUtils", "downLoadIcon()", e10); if (httpURLConnection2 != 0) { } if (fileOutputStream != null) { } return z10; } catch (Throwable th2) { th = th2; httpURLConnection = httpURLConnection2; if (httpURLConnection != null) { } if (fileOutputStream != null) { } throw th; } } catch (Throwable th3) { th = th3; httpURLConnection = httpURLConnection3; if (httpURLConnection != null) { } if (fileOutputStream != null) { } throw th; } } else { fileOutputStream2 = fileOutputStream3; } httpURLConnection3.disconnect(); if (fileOutputStream2 != null) { try { fileOutputStream2.close(); } catch (IOException unused) { } return z10; } } catch (Exception e12) { e10 = e12; fileOutputStream = null; httpURLConnection2 = httpURLConnection3; LogUtils.d("WebViewUtils", "downLoadIcon()", e10); if (httpURLConnection2 != 0) { } if (fileOutputStream != null) { } return z10; } catch (Throwable th4) { th = th4; fileOutputStream = null; httpURLConnection = httpURLConnection3; if (httpURLConnection != null) { } if (fileOutputStream != null) { } throw th; } } catch (Exception e13) { e10 = e13; fileOutputStream = null; httpURLConnection2 = fileOutputStream3; LogUtils.d("WebViewUtils", "downLoadIcon()", e10); if (httpURLConnection2 != 0) { httpURLConnection2.disconnect(); } if (fileOutputStream != null) { fileOutputStream.close(); } return z10; } catch (Throwable th5) { th = th5; fileOutputStream = null; httpURLConnection = fileOutputStream3; if (httpURLConnection != null) { httpURLConnection.disconnect(); } if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException unused2) { } } throw th; } return z10; } } LogUtils.c("WebViewUtils", "illegal downLoadIcon from " + str + " to " + str2); return false; } public static boolean d(String str) { boolean z10 = false; if (TextUtils.isEmpty(str)) { return false; } try { Uri parse = Uri.parse(str); if (TextUtils.equals(parse.getScheme(), "cs") && TextUtils.equals(parse.getHost(), "wx")) { z10 = true; } return z10; } catch (Exception e10) { LogUtils.e("WebViewUtils", e10); return false; } } static String e(String str) { File file = new File(f41240d.l()); if (!file.exists()) { file.mkdirs(); } String b10 = (str == null || !str.contains(".")) ? ".jpg" : URLEncoder.b(str.substring(str.lastIndexOf(46))); return new File(file, "thumb123" + b10).getAbsolutePath(); } public static String f(String str, String str2) { String str3 = str; Uri parse = Uri.parse(str3); if (!str3.contains("?")) { Uri.Builder buildUpon = parse.buildUpon(); buildUpon.appendQueryParameter("intsig_key", str2); str3 = buildUpon.build().toString(); } else if (parse.getQueryParameter("intsig_key") != null) { Set<String> queryParameterNames = parse.getQueryParameterNames(); if (queryParameterNames != null && queryParameterNames.size() > 0) { int lastIndexOf = str3.lastIndexOf(parse.getEncodedQuery()); if (lastIndexOf < 0) { lastIndexOf = str3.lastIndexOf(parse.getQuery()); } StringBuilder sb2 = new StringBuilder(str3.substring(0, lastIndexOf)); boolean z10 = true; for (String str4 : queryParameterNames) { if (z10) { z10 = false; } else { sb2.append("&"); } StringBuilder sb3 = new StringBuilder(); sb3.append(str4); sb3.append("="); sb3.append(str4.equalsIgnoreCase(ClientMetricsEndpointType.TOKEN) ? str2 : URLEncoder.b(parse.getQueryParameter(str4))); sb2.append(sb3.toString()); } String fragment = parse.getFragment(); if (!TextUtils.isEmpty(fragment)) { sb2.append("#" + fragment); } return sb2.toString(); } } else { Uri.Builder buildUpon2 = parse.buildUpon(); buildUpon2.appendQueryParameter("intsig_key", str2); return buildUpon2.build().toString(); } return str3; } static String g(String str) { String str2; Uri parse; Set<String> queryParameterNames; if (TextUtils.isEmpty(str) || !m(str) || (queryParameterNames = (parse = Uri.parse(str)).getQueryParameterNames()) == null || queryParameterNames.size() <= 0) { str2 = str; } else { if (str.lastIndexOf(parse.getEncodedQuery()) < 0) { str.lastIndexOf(parse.getQuery()); } Uri.Builder buildUpon = parse.buildUpon(); buildUpon.clearQuery(); loop0: while (true) { for (String str3 : queryParameterNames) { if (!TextUtils.equals(str3, "intsig_key") && !TextUtils.equals(str3, "device_id") && !TextUtils.equals(str3, "deviceid") && !TextUtils.equals(str3, "user_id")) { if (!TextUtils.equals(str3, ClientMetricsEndpointType.TOKEN)) { buildUpon.appendQueryParameter(str3, parse.getQueryParameter(str3)); } } } break loop0; } str2 = buildUpon.build().toString(); } LogUtils.a("WebViewUtils", "getSharableUrl from " + str + " to " + str2); return s(str2); } static String h(String str) { String str2; MalformedURLException e10; String str3 = null; if (!TextUtils.isEmpty(str)) { try { str2 = new URL(str).getHost(); if (str2 != null) { try { if (str2.startsWith("www.")) { str2 = str2.substring(4, str2.length()); str3 = str2; } } catch (MalformedURLException e11) { e10 = e11; LogUtils.e("WebViewUtils", e10); str3 = str2; LogUtils.a("WebViewUtils", "getUrlSource source = " + str + " to " + str3); return str3; } } } catch (MalformedURLException e12) { e10 = e12; str2 = null; LogUtils.e("WebViewUtils", e10); str3 = str2; LogUtils.a("WebViewUtils", "getUrlSource source = " + str + " to " + str3); return str3; } str3 = str2; } LogUtils.a("WebViewUtils", "getUrlSource source = " + str + " to " + str3); return str3; } static String i(String str) { String str2 = str; if (!TextUtils.isEmpty(str2)) { String b10 = AESNopadding.b(f41240d.g()); if (!TextUtils.isEmpty(b10) && str2.startsWith("https")) { str2 = f(str2, b10); LogUtils.a("WebViewUtils", "handleUrlWithUserToken = " + str2); } } LogUtils.a("WebViewUtils", "handleUrlWithUserToken: res " + str2); return str2; } /* JADX WARNING: Removed duplicated region for block: B:14:0x006a */ public static void j(Context context) { WebViewAppInterface webViewAppInterface = f41240d; if (webViewAppInterface != null) { if (webViewAppInterface.i()) { if (f41240d.l() != null) { File file = new File(f41240d.l()); if (!file.exists()) { file.mkdirs(); LogUtils.a("WebViewUtils", "init mkdirs " + file); } } else { LogUtils.a("WebViewUtils", "sWebDbInterface can not be null or getCacheDirPath is null"); } if (ApplicationHelper.p()) { WebView.setWebContentsDebuggingEnabled(true); } WhiteHostListManager.b(context); } LogUtils.a("WebViewUtils", "not agreeCNPrivacyPolicy"); } if (ApplicationHelper.p()) { } WhiteHostListManager.b(context); } static boolean k(Context context) { return r(context, "camcard"); } static boolean l(Context context) { return r(context, "camscanner"); } static boolean m(String str) { if (!TextUtils.isEmpty(str)) { if (f41239c == null) { f41239c = Pattern.compile("(intsig\\.net|intsig\\.com|camscanner\\.com|camscanner\\.me|camcard\\.me|camcard\\.com)"); } if (f41239c.matcher(str).find()) { return true; } } return false; } public static void n(int i10) { f41240d.a(i10); } public static void o(int i10, int i11) { f41240d.y(i10, i11); } public static void p(int i10, String str) { f41240d.f(i10, str); } public static void q(@NonNull WebViewAppInterface webViewAppInterface) { f41240d = webViewAppInterface; } private static boolean r(Context context, String str) { String x10 = f41240d.x(); return x10 != null && x10.toLowerCase().contains(str); } static String s(String str) { if (str == null) { return null; } String[] strArr = {"http://info.camcard.com", "http://info.camcard.me", "http://info12013.camcard.com", "https://info.camcard.com", "https://info.camcard.me", "https://info12013.camcard.com"}; for (int i10 = 0; i10 < 6; i10++) { if (str.startsWith(strArr[i10])) { String queryParameter = Uri.parse(str).getQueryParameter("code"); if (!TextUtils.isEmpty(queryParameter)) { str = str.replace(queryParameter, ""); } int indexOf = str.indexOf(35); if (indexOf > 0) { String substring = str.substring(indexOf); String substring2 = str.substring(0, indexOf); if (substring2.contains("?")) { return substring2 + "&hash=" + URLEncoder.b(substring); } return substring2 + "?hash=" + URLEncoder.b(substring); } } } return str; } }