package defpackage; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.ResolveInfo; import android.content.pm.Signature; import android.os.Bundle; import android.os.StrictMode; import android.text.TextUtils; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.security.KeyFactory; import java.security.PublicKey; import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; import java.util.Iterator; import java.util.LinkedList; import java.util.List; /* renamed from: TI1 reason: default package */ /* compiled from: chromium-ChromePublic.apk-stable-447210115 */ public abstract class TI1 { public static byte[] a; public static byte[] b; public static PublicKey c; public static boolean d; public static boolean a(Context context, String str, String str2) { for (ResolveInfo resolveInfo : g(context, str2, str)) { ActivityInfo activityInfo = resolveInfo.activityInfo; if (activityInfo != null && c(context, activityInfo.packageName)) { return true; } } return false; } public static ResolveInfo b(Context context, List list) { Iterator it = list.iterator(); while (it.hasNext()) { ResolveInfo resolveInfo = (ResolveInfo) it.next(); ActivityInfo activityInfo = resolveInfo.activityInfo; if (activityInfo != null && c(context, activityInfo.packageName)) { return resolveInfo; } } return null; } public static boolean c(Context context, String str) { return d(context, str) != 0; } /* JADX WARNING: Can't wrap try/catch for region: R(5:64|65|66|67|68) */ /* JADX WARNING: Code restructure failed: missing block: B:89:0x0142, code lost: if (r6 != null) goto L_0x0103; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:67:0x0103 */ /* JADX WARNING: Missing exception handler attribute for start block: B:75:0x0115 */ /* JADX WARNING: Removed duplicated region for block: B:108:0x016b A[RETURN] */ /* JADX WARNING: Removed duplicated region for block: B:109:0x016d A[RETURN] */ /* JADX WARNING: Removed duplicated region for block: B:86:0x013d A[SYNTHETIC, Splitter:B:86:0x013d] */ /* JADX WARNING: Removed duplicated region for block: B:93:0x014b A[SYNTHETIC, Splitter:B:93:0x014b] */ /* JADX WARNING: Removed duplicated region for block: B:97:0x0152 A[SYNTHETIC, Splitter:B:97:0x0152] */ public static int d(Context context, String str) { boolean z; boolean z2; String str2; Throwable th; RandomAccessFile randomAccessFile; Exception e; int i; String string; String string2; Bundle bundle; if (a == null || b == null) { AbstractC5452vj0.g("WebApkValidator", "WebApk validation failure - expected signature not set - missing call to WebApkValidator.init", new Object[0]); return 0; } try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(str, 192); ApplicationInfo applicationInfo = packageInfo.applicationInfo; boolean z3 = true; if (applicationInfo == null || (bundle = applicationInfo.metaData) == null) { AbstractC5452vj0.a("WebApkValidator", "no application info, or metaData retrieved.", new Object[0]); z = true; } else { z = TextUtils.isEmpty(bundle.getString("org.chromium.webapk.shell_apk.startUrl")); } if (z) { return 0; } if (d || h(packageInfo, str)) { return 1; } if (str.equals("com.google.android.apps.mapslite") && (string = packageInfo.applicationInfo.metaData.getString("org.chromium.webapk.shell_apk.startUrl")) != null && string.startsWith("https://www.google.com/maps") && (string2 = packageInfo.applicationInfo.metaData.getString("org.chromium.webapk.shell_apk.scope")) != null && string2.equals("https://www.google.com/maps")) { z2 = true; } else { z2 = false; } if (z2) { return 2; } try { if (c == null) { c = KeyFactory.getInstance("EC").generatePublic(new X509EncodedKeySpec(b)); } PublicKey publicKey = c; if (publicKey == null) { AbstractC5452vj0.a("WebApkValidator", "WebApk validation failure - unable to decode public key", new Object[0]); } else { ApplicationInfo applicationInfo2 = packageInfo.applicationInfo; if (applicationInfo2 == null || (str2 = applicationInfo2.sourceDir) == null) { AbstractC5452vj0.a("WebApkValidator", "WebApk validation failure - missing applicationInfo sourcedir", new Object[0]); } else { StrictMode.ThreadPolicy allowThreadDiskReads = StrictMode.allowThreadDiskReads(); FileChannel fileChannel = null; try { randomAccessFile = new RandomAccessFile(str2, "r"); try { fileChannel = randomAccessFile.getChannel(); MappedByteBuffer map = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size()); map.load(); XI1 xi1 = new XI1(map); try { i = xi1.f(); if (i == 0) { if (XI1.b(xi1.e) == null) { i = 5; } else { i = xi1.e(); if (i == 0) { i = 0; } } } } catch (Exception unused) { i = 1; } if (i != 0) { AbstractC5452vj0.a("WebApkValidator", String.format("Failure reading %s: %s", str2, Integer.valueOf(i)), new Object[0]); StrictMode.setThreadPolicy(allowThreadDiskReads); fileChannel.close(); randomAccessFile.close(); } else { if (xi1.i(publicKey) != 0) { z3 = false; } StrictMode.setThreadPolicy(allowThreadDiskReads); fileChannel.close(); try { randomAccessFile.close(); } catch (IOException unused2) { } if (!z3) { return 3; } return 0; } } catch (Exception e2) { e = e2; try { AbstractC5452vj0.a("WebApkValidator", "WebApk file error for file " + str2, e); StrictMode.setThreadPolicy(allowThreadDiskReads); if (fileChannel != null) { try { fileChannel.close(); } catch (IOException unused3) { } } } catch (Throwable th2) { th = th2; StrictMode.setThreadPolicy(allowThreadDiskReads); if (fileChannel != null) { try { fileChannel.close(); } catch (IOException unused4) { } } if (randomAccessFile != null) { try { randomAccessFile.close(); } catch (IOException unused5) { } } throw th; } } } catch (Exception e3) { e = e3; randomAccessFile = null; AbstractC5452vj0.a("WebApkValidator", "WebApk file error for file " + str2, e); StrictMode.setThreadPolicy(allowThreadDiskReads); if (fileChannel != null) { } } catch (Throwable th3) { th = th3; randomAccessFile = null; StrictMode.setThreadPolicy(allowThreadDiskReads); if (fileChannel != null) { } if (randomAccessFile != null) { } throw th; } } } } catch (Exception e4) { AbstractC5452vj0.a("WebApkValidator", "WebApk failed to get Public Key", e4); } z3 = false; if (!z3) { } } catch (Exception unused6) { } } public static String e(Context context, String str) { ResolveInfo b2 = b(context, f(context, str)); if (b2 != null) { return b2.activityInfo.packageName; } return null; } public static List f(Context context, String str) { return g(context, str, null); } /* JADX WARNING: Code restructure failed: missing block: B:20:0x003b, code lost: r2 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:24:0x0045, code lost: return new java.util.LinkedList(); */ /* JADX WARNING: Code restructure failed: missing block: B:25:0x0046, code lost: android.os.StrictMode.setThreadPolicy(r3); */ /* JADX WARNING: Code restructure failed: missing block: B:26:0x0049, code lost: throw r2; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:21:0x003d */ public static List g(Context context, String str, String str2) { Intent intent = null; try { Intent parseUri = Intent.parseUri(str, 1); parseUri.addCategory("android.intent.category.BROWSABLE"); if (str2 != null) { parseUri.setPackage(str2); } else { parseUri.setComponent(null); } Intent selector = parseUri.getSelector(); if (selector != null) { selector.addCategory("android.intent.category.BROWSABLE"); selector.setComponent(null); } intent = parseUri; } catch (Exception unused) { } if (intent == null) { return new LinkedList(); } StrictMode.ThreadPolicy allowThreadDiskReads = StrictMode.allowThreadDiskReads(); List<ResolveInfo> queryIntentActivities = context.getPackageManager().queryIntentActivities(intent, 64); StrictMode.setThreadPolicy(allowThreadDiskReads); return queryIntentActivities; } public static boolean h(PackageInfo packageInfo, String str) { Signature[] signatureArr = packageInfo.signatures; if (signatureArr != null && signatureArr.length == 2 && str.startsWith("org.chromium.webapk")) { for (Signature signature : packageInfo.signatures) { if (Arrays.equals(a, signature.toByteArray())) { return true; } } } return false; } }