package com.overlook.android.fing.engine.j.g; import android.util.Log; import com.google.protobuf.c; import com.overlook.android.fing.engine.j.h.b; import com.overlook.android.fing.engine.l.s; import com.overlook.android.fing.engine.model.net.GeoIpInfo; import e.f.a.a.a.a2; import e.f.a.a.a.u9; import h.c0; import h.e0; import h.i0; import h.k0; import h.y; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.concurrent.TimeUnit; import okhttp3.internal.connection.e; /* compiled from: GeoIpResolver */ public class d { /* renamed from: a reason: collision with root package name */ private final String f15187a; private final c0 b; /* renamed from: c reason: collision with root package name */ private final Object f15188c; /* renamed from: d reason: collision with root package name */ private GeoIpInfo f15189d; /* renamed from: e reason: collision with root package name */ private Thread f15190e; /* renamed from: f reason: collision with root package name */ private boolean f15191f; public d() { this("fingdroid/11.1.0"); } private void b(s<GeoIpInfo> sVar, GeoIpInfo geoIpInfo) { Log.d("fing:geoip-resolver", "Fetched GeoIP info: " + geoIpInfo); synchronized (this.f15188c) { this.f15191f = true; this.f15188c.notifyAll(); } if (sVar != null) { sVar.onSuccess(geoIpInfo); } } public boolean a(long j) { boolean z; synchronized (this.f15188c) { if (!this.f15191f) { try { Log.d("fing:geoip-resolver", "Awaiting GeoIP resolution termination..."); this.f15188c.wait(j); } catch (InterruptedException unused) { } } z = this.f15191f; } return z; } public GeoIpInfo c() { synchronized (this.f15188c) { GeoIpInfo geoIpInfo = this.f15189d; if (geoIpInfo == null) { return null; } return new GeoIpInfo(geoIpInfo); } } public boolean d() { boolean z; synchronized (this.f15188c) { z = this.f15191f; } return z; } /* JADX WARNING: Code restructure failed: missing block: B:24:0x0081, code lost: r2 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:25:0x0082, code lost: if (r0 != null) goto L_0x0084; */ /* JADX WARNING: Code restructure failed: missing block: B:27:?, code lost: r0.close(); */ /* JADX WARNING: Code restructure failed: missing block: B:28:0x0088, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:29:0x0089, code lost: r1.addSuppressed(r0); */ /* JADX WARNING: Code restructure failed: missing block: B:30:0x008c, code lost: throw r2; */ public void e(s sVar) { Log.d("fing:geoip-resolver", "Fetching GeoIP information from https://internetcheck.fing.com/geoip/v1/record"); try { y j = y.j("https://internetcheck.fing.com/geoip/v1/record?full=true"); if (j != null) { y.a i2 = j.i(); e0.a aVar = new e0.a(); aVar.a("User-Agent", this.f15187a); aVar.a("Accept", "application/protobuf"); aVar.a("X-Api-Key", "7b0d3f48-a6df-48a9-80f7-0f5ca6868503"); aVar.i(i2.c()); i0 k = ((e) this.b.A(aVar.b())).k(); if (k.x()) { k0 b2 = k.b(); if (b2 != null) { byte[] b3 = b2.b(); b2.close(); GeoIpInfo k2 = u9.k((a2) ((c) a2.I).c(new ByteArrayInputStream(b3))); synchronized (this.f15188c) { this.f15189d = k2; } b(sVar, k2); try { this.b.k().a(); } catch (Exception unused) { } } else { throw new IOException("HTTP response body is empty!"); } } else { throw new IOException("HTTP response invalid (code=" + k.i() + ",message=" + k.y() + ")"); } } else { throw new IOException("Invalid endpoint: https://internetcheck.fing.com/geoip/v1/record"); } } catch (Exception e2) { Log.e("fing:geoip-resolver", "Failed to fetch GeoIP info ", e2); synchronized (this.f15188c) { this.f15191f = true; this.f15188c.notifyAll(); if (sVar != null) { sVar.onFailure(e2); } } } } public void f() { Thread thread = new Thread(new b(this, null)); this.f15190e = thread; thread.start(); } public void g(s<GeoIpInfo> sVar) { Thread thread = new Thread(new b(this, sVar)); this.f15190e = thread; thread.start(); } public d(String str) { this.f15188c = new Object(); this.f15187a = str; c0.a b2 = b.b(); TimeUnit timeUnit = TimeUnit.SECONDS; b2.b(6, timeUnit); b2.L(6, timeUnit); b2.I(6, timeUnit); this.b = new c0(b2); } }