package p5; import h5.f; import h5.g0; import h5.y; import i5.c; import java.io.IOException; import java.io.InputStream; import java.io.InterruptedIOException; import java.net.IDN; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; /* loaded from: classes2.dex */ public final class a { /* renamed from: e, reason: collision with root package name */ private static final byte[] f13241e = {42}; /* renamed from: f, reason: collision with root package name */ private static final String[] f13242f = new String[0]; /* renamed from: g, reason: collision with root package name */ private static final String[] f13243g = {"*"}; /* renamed from: h, reason: collision with root package name */ private static final a f13244h = new a(); /* renamed from: a, reason: collision with root package name */ private final AtomicBoolean f13245a = new AtomicBoolean(false); /* renamed from: b, reason: collision with root package name */ private final CountDownLatch f13246b = new CountDownLatch(1); /* renamed from: c, reason: collision with root package name */ private byte[] f13247c; /* renamed from: d, reason: collision with root package name */ private byte[] f13248d; private static String a(byte[] bArr, byte[][] bArr2, int i10) { int i11; boolean z10; int i12; int i13; int length = bArr.length; int i14 = 0; while (i14 < length) { int i15 = (i14 + length) / 2; while (i15 > -1 && bArr[i15] != 10) { i15--; } int i16 = i15 + 1; int i17 = 1; while (true) { i11 = i16 + i17; if (bArr[i11] == 10) { break; } i17++; } int i18 = i11 - i16; int i19 = i10; boolean z11 = false; int i20 = 0; int i21 = 0; while (true) { if (z11) { i12 = 46; z10 = false; } else { z10 = z11; i12 = bArr2[i19][i20] & 255; } i13 = i12 - (bArr[i16 + i21] & 255); if (i13 == 0) { i21++; i20++; if (i21 == i18) { break; } if (bArr2[i19].length != i20) { z11 = z10; } else { if (i19 == bArr2.length - 1) { break; } i19++; z11 = true; i20 = -1; } } else { break; } } if (i13 >= 0) { if (i13 <= 0) { int i22 = i18 - i21; int length2 = bArr2[i19].length - i20; while (true) { i19++; if (i19 >= bArr2.length) { break; } length2 += bArr2[i19].length; } if (length2 >= i22) { if (length2 <= i22) { return new String(bArr, i16, i18, c.f10880j); } } } i14 = i11 + 1; } length = i16 - 1; } return null; } private void b() { InputStream resourceAsStream = a.class.getResourceAsStream("publicsuffixes.gz"); if (resourceAsStream == null) { return; } f f10 = g0.f(new y(g0.h(resourceAsStream))); try { byte[] bArr = new byte[f10.readInt()]; f10.readFully(bArr); byte[] bArr2 = new byte[f10.readInt()]; f10.readFully(bArr2); synchronized (this) { this.f13247c = bArr; this.f13248d = bArr2; } this.f13246b.countDown(); } finally { c.j(f10); } } private String[] c(String[] strArr) { String str; String str2; String str3; int i10 = 0; if (this.f13245a.get() || !this.f13245a.compareAndSet(false, true)) { try { this.f13246b.await(); } catch (InterruptedException unused) { } } else { d(); } synchronized (this) { if (this.f13247c == null) { throw new IllegalStateException("Unable to load publicsuffixes.gz resource from the classpath."); } } int length = strArr.length; byte[][] bArr = new byte[length][]; for (int i11 = 0; i11 < strArr.length; i11++) { bArr[i11] = strArr[i11].getBytes(c.f10880j); } int i12 = 0; while (true) { str = null; if (i12 >= length) { str2 = null; break; } str2 = a(this.f13247c, bArr, i12); if (str2 != null) { break; } i12++; } if (length > 1) { byte[][] bArr2 = (byte[][]) bArr.clone(); for (int i13 = 0; i13 < bArr2.length - 1; i13++) { bArr2[i13] = f13241e; str3 = a(this.f13247c, bArr2, i13); if (str3 != null) { break; } } } str3 = null; if (str3 != null) { while (true) { if (i10 >= length - 1) { break; } String a10 = a(this.f13248d, bArr, i10); if (a10 != null) { str = a10; break; } i10++; } } if (str != null) { return ("!" + str).split("\\."); } if (str2 == null && str3 == null) { return f13243g; } String[] split = str2 != null ? str2.split("\\.") : f13242f; String[] split2 = str3 != null ? str3.split("\\.") : f13242f; return split.length > split2.length ? split : split2; } private void d() { boolean z10 = false; while (true) { try { try { b(); break; } catch (InterruptedIOException unused) { z10 = true; } catch (IOException e10) { o5.a.j().o(5, "Failed to read public suffix list", e10); if (z10) { Thread.currentThread().interrupt(); return; } return; } } catch (Throwable th) { if (z10) { Thread.currentThread().interrupt(); } throw th; } } if (z10) { Thread.currentThread().interrupt(); } } public static a e() { return f13244h; } public String f(String str) { if (str == null) { throw new NullPointerException("domain == null"); } String[] split = IDN.toUnicode(str).split("\\."); String[] c10 = c(split); if (split.length == c10.length && c10[0].charAt(0) != '!') { return null; } char charAt = c10[0].charAt(0); int length = split.length; int length2 = c10.length; if (charAt != '!') { length2++; } StringBuilder sb = new StringBuilder(); String[] split2 = str.split("\\."); for (int i10 = length - length2; i10 < split2.length; i10++) { sb.append(split2[i10]); sb.append('.'); } sb.deleteCharAt(sb.length() - 1); return sb.toString(); } }