Fing.apk(点击下载) / k.java


package com.overlook.android.fing.engine.e;

import android.content.Context;
import android.content.ContextWrapper;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.util.Log;
import android.util.LruCache;
import com.huawei.hms.actions.SearchIntents;
import com.overlook.android.fing.engine.j.g.d;
import com.overlook.android.fing.engine.j.h.b;
import com.overlook.android.fing.engine.l.s;
import com.overlook.android.fing.engine.model.internet.IspInfo;
import com.overlook.android.fing.engine.model.internet.IspLookup;
import com.overlook.android.fing.engine.model.internet.IspQuery;
import com.overlook.android.fing.engine.model.internet.OutageInfo;
import com.overlook.android.fing.engine.model.internet.OutagesOverview;
import com.overlook.android.fing.engine.model.internet.UserRating;
import com.overlook.android.fing.engine.model.internet.UserRatingsQuery;
import com.overlook.android.fing.engine.model.net.GeoIpInfo;
import com.overlook.android.fing.engine.model.net.HardwareAddress;
import com.overlook.android.fing.engine.model.speedtest.InternetSpeedTestScore;
import com.overlook.android.fing.engine.services.netbox.j0;
import com.overlook.android.fing.engine.services.netbox.l0;
import com.overlook.android.fing.engine.services.netbox.m0;
import h.c0;
import h.e0;
import h.i0;
import h.k0;
import java.net.URL;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import okhttp3.internal.connection.e;
import org.json.JSONException;
import org.json.JSONObject;

/* compiled from: IspManager */
public class k extends ContextWrapper {

    /* renamed from: a  reason: collision with root package name */
    private final LruCache<IspQuery, IspLookup> f14739a = new LruCache<>(40);
    private final LruCache<String, IspLookup> b = new LruCache<>(20);

    /* renamed from: c  reason: collision with root package name */
    private final Executor f14740c = Executors.newSingleThreadExecutor();

    /* renamed from: d  reason: collision with root package name */
    private final h f14741d;

    /* renamed from: e  reason: collision with root package name */
    private final l0 f14742e;

    /* access modifiers changed from: package-private */
    /* compiled from: IspManager */
    public class a implements s<GeoIpInfo> {

        /* renamed from: a  reason: collision with root package name */
        final /* synthetic */ i f14743a;
        final /* synthetic */ String b;

        /* renamed from: c  reason: collision with root package name */
        final /* synthetic */ s f14744c;

        a(i iVar, String str, s sVar) {
            this.f14743a = iVar;
            this.b = str;
            this.f14744c = sVar;
        }

        @Override // com.overlook.android.fing.engine.l.s
        public void onFailure(Exception exc) {
            this.f14744c.onFailure(exc);
        }

        /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
        @Override // com.overlook.android.fing.engine.l.s
        public void onSuccess(GeoIpInfo geoIpInfo) {
            GeoIpInfo geoIpInfo2 = geoIpInfo;
            IspQuery ispQuery = new IspQuery(geoIpInfo2.u(), geoIpInfo2.y());
            ispQuery.i(this.f14743a == i.CELLULAR);
            ispQuery.j(true);
            ispQuery.m(5);
            k.this.l(ispQuery, new j(this, geoIpInfo2));
        }
    }

    public k(Context context, l0 l0Var, h hVar) {
        super(context);
        this.f14742e = l0Var;
        this.f14741d = hVar;
    }

    private IspInfo b(IspQuery ispQuery) {
        IspInfo ispInfo = new IspInfo();
        ispInfo.C(ispQuery.c());
        ispInfo.A(ispQuery.b());
        ispInfo.L(ispQuery.c());
        ispInfo.K("/isp/general/default_isp.png");
        ispInfo.I(c(ispInfo.i()));
        return ispInfo;
    }

    private static Bitmap c(String str) {
        try {
            Bitmap decodeStream = BitmapFactory.decodeStream(new URL("https://cdn.fing.io/images" + str).openStream());
            if (decodeStream != null) {
                return decodeStream;
            }
            return null;
        } catch (Exception e2) {
            Log.e("fing:isp-manager", "Logo ERROR: ", e2);
            return null;
        }
    }

    public void d(s sVar, IspQuery ispQuery) {
        IspInfo ispInfo;
        try {
            IspLookup k = k(ispQuery);
            if (k.d() != null) {
                ispInfo = k.d();
            } else {
                ispInfo = b(ispQuery);
            }
            sVar.onSuccess(ispInfo);
        } catch (Exception e2) {
            sVar.onFailure(e2);
        }
    }

    public void e(String str, String str2, String str3, boolean z, s sVar) {
        try {
            j0 j0Var = new j0("11.1.0");
            j0Var.F(((m0) this.f14742e).C());
            j0Var.G(((m0) this.f14742e).v());
            InternetSpeedTestScore r = j0Var.r(str, str2, str3, z);
            if (r != null) {
                sVar.onSuccess(r);
                return;
            }
            sVar.onFailure(new Exception("No score for " + str + " in country:" + str2 + " city:" + str3));
        } catch (Exception e2) {
            sVar.onFailure(e2);
        }
    }

    public void f(s sVar) {
        try {
            j0 j0Var = new j0("11.1.0");
            j0Var.F(((m0) this.f14742e).C());
            j0Var.G(((m0) this.f14742e).v());
            sVar.onSuccess(j0Var.s());
        } catch (Exception e2) {
            Log.e("fing:isp-manager", "Failed to lookup live outages", e2);
            sVar.onFailure(e2);
        }
    }

    public void g(String str, s sVar) {
        try {
            j0 j0Var = new j0("11.1.0");
            j0Var.F(((m0) this.f14742e).C());
            j0Var.G(((m0) this.f14742e).v());
            OutageInfo u = j0Var.u(str);
            if (u != null) {
                sVar.onSuccess(u);
                return;
            }
            sVar.onFailure(new Exception("No outage " + str));
        } catch (Exception e2) {
            sVar.onFailure(e2);
        }
    }

    public void h(s sVar) {
        try {
            j0 j0Var = new j0("11.1.0");
            j0Var.F(((m0) this.f14742e).C());
            j0Var.G(((m0) this.f14742e).v());
            sVar.onSuccess(j0Var.v());
        } catch (Exception e2) {
            Log.e("fing:isp-manager", "Failed to lookup live outages", e2);
            sVar.onFailure(e2);
        }
    }

    public void i(s sVar, UserRatingsQuery userRatingsQuery) {
        try {
            j0 j0Var = new j0("11.1.0");
            j0Var.F(((m0) this.f14742e).C());
            sVar.onSuccess(j0Var.w(userRatingsQuery));
        } catch (Exception e2) {
            Log.e("fing:isp-manager", "No user rating for " + userRatingsQuery);
            sVar.onFailure(e2);
        }
    }

    public void j(s<IspLookup> sVar) {
        String str;
        IspLookup ispLookup;
        i h2 = this.f14741d.h();
        if (h2 == i.NONE) {
            Log.w("fing:isp-manager", "Active ISP Lookup failed due to missing connectivity");
            sVar.onFailure(new Exception("Missing network connectivity"));
            return;
        }
        if (h2 == i.WIFI) {
            HardwareAddress m = this.f14741d.m();
            str = m != null ? m.toString() : null;
        } else {
            str = this.f14741d.i();
        }
        if (str == null || (ispLookup = this.b.get(str)) == null || System.currentTimeMillis() - ispLookup.f() >= 60000) {
            StringBuilder E = e.a.a.a.a.E("Performing active ISP lookup (network=");
            E.append(h2.name());
            E.append(")...");
            Log.i("fing:isp-manager", E.toString());
            new d("fingdroid/11.1.0").g(new a(h2, str, sVar));
            return;
        }
        Log.i("fing:isp-manager", "ISP Lookup for current network found in cache (not expired)");
        sVar.onSuccess(ispLookup);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:47:0x0144, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:49:?, code lost:
        r6.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:50:0x0149, code lost:
        r1 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:51:0x014a, code lost:
        r12.addSuppressed(r1);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:52:0x014d, code lost:
        throw r0;
     */
    public IspLookup k(IspQuery ispQuery) throws Exception {
        IspLookup ispLookup = this.f14739a.get(ispQuery);
        if (ispLookup != null && System.currentTimeMillis() - ispLookup.f() < 60000) {
            return ispLookup;
        }
        Log.i("fing:isp-manager", "Performing ISP Lookup...");
        j0 j0Var = new j0("11.1.0");
        j0Var.F(((m0) this.f14742e).C());
        j0Var.G(((m0) this.f14742e).v());
        IspLookup q = j0Var.q(ispQuery);
        if (q.d() == null) {
            q.l(b(ispQuery));
            return q;
        }
        IspInfo d2 = q.d();
        d2.C(ispQuery.c());
        if (ispQuery.h()) {
            LinkedHashSet linkedHashSet = new LinkedHashSet();
            if (d2.r() != null) {
                linkedHashSet.add(d2.r().toLowerCase());
            }
            if (d2.d() != null) {
                linkedHashSet.add(d2.d().toLowerCase());
            }
            c0.a b2 = b.b();
            TimeUnit timeUnit = TimeUnit.SECONDS;
            b2.b(2, timeUnit);
            b2.I(2, timeUnit);
            c0 c0Var = new c0(b2);
            Iterator it = linkedHashSet.iterator();
            while (it.hasNext()) {
                e0.a aVar = new e0.a();
                aVar.h(String.format("https://%s.wikipedia.org/w/api.php?action=query&prop=extracts&exintro&explaintext&titles=%s&format=json", (String) it.next(), d2.q()));
                i0 k = ((e) c0Var.A(aVar.b())).k();
                if (k.x()) {
                    k0 b3 = k.b();
                    if (b3 != null) {
                        String i2 = b3.i();
                        b3.close();
                        try {
                            JSONObject jSONObject = new JSONObject(i2);
                            if (jSONObject.has(SearchIntents.EXTRA_QUERY) && jSONObject.getJSONObject(SearchIntents.EXTRA_QUERY).has("pages")) {
                                JSONObject jSONObject2 = jSONObject.getJSONObject(SearchIntents.EXTRA_QUERY).getJSONObject("pages");
                                Iterator<String> keys = jSONObject2.keys();
                                while (true) {
                                    if (!keys.hasNext()) {
                                        break;
                                    }
                                    String string = jSONObject2.getJSONObject(keys.next()).getString("extract");
                                    if (!TextUtils.isEmpty(string)) {
                                        d2.V(string);
                                        break;
                                    }
                                }
                            }
                            if (d2.p() != null) {
                                break;
                            }
                        } catch (JSONException e2) {
                            Log.e("fing:isp-manager", "Wikipedia ERROR: ", e2);
                        }
                    } else if (b3 != null) {
                        b3.close();
                    }
                }
            }
        }
        if (ispQuery.g() && d2.i() != null) {
            d2.I(c(d2.i()));
        }
        if (ispQuery.g() && d2.b() != null) {
            d2.w(c(d2.b()));
        }
        if (ispQuery.g() && d2.i() == null && d2.b() == null) {
            d2.K("/isp/general/default_isp.png");
            d2.I(c(d2.i()));
        }
        Log.d("fing:isp-manager", "Fetched ISP information: " + d2);
        this.f14739a.put(ispQuery, q);
        return q;
    }

    public void l(IspQuery ispQuery, s<IspLookup> sVar) {
        this.f14740c.execute(new d(this, sVar, ispQuery));
    }

    public void m(IspQuery ispQuery, s<IspInfo> sVar) {
        this.f14740c.execute(new a(this, sVar, ispQuery));
    }

    public void n(String str, String str2, String str3, boolean z, s<InternetSpeedTestScore> sVar) {
        this.f14740c.execute(new c(this, str, str2, str3, z, sVar));
    }

    public void o(s<List<OutageInfo>> sVar) {
        this.f14740c.execute(new f(this, sVar));
    }

    public void p(String str, s<OutageInfo> sVar) {
        this.f14740c.execute(new e(this, str, sVar));
    }

    public void q(s<OutagesOverview> sVar) {
        this.f14740c.execute(new g(this, sVar));
    }

    public void r(UserRatingsQuery userRatingsQuery, s<Collection<UserRating>> sVar) {
        this.f14740c.execute(new b(this, sVar, userRatingsQuery));
    }
}