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


package com.overlook.android.fing.ui.purchase;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.os.Handler;
import android.util.Log;
import com.overlook.android.fing.R;
import com.overlook.android.fing.engine.FingService;
import com.overlook.android.fing.engine.l.q;
import com.overlook.android.fing.engine.services.netbox.m0;
import com.overlook.android.fing.engine.services.netbox.o0;
import com.overlook.android.fing.ui.misc.h;
import e.f.a.a.b.f.f0;
import e.f.a.a.b.f.u;
import h.c0;
import h.e0;
import h.f;
import h.g;
import h.i0;
import h.k0;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.CopyOnWriteArrayList;
import okhttp3.internal.connection.e;
import org.json.JSONArray;
import org.json.JSONObject;

/* compiled from: PurchaseManager */
public class q1 extends ContextWrapper implements u1 {

    /* renamed from: i  reason: collision with root package name */
    public static final Set<String> f17966i = new TreeSet(Arrays.asList("adsfree_3mo", "adsfree_6mo", "adsfree_1yr"));
    public static final Set<String> j = new TreeSet(Arrays.asList("premium_1mo", "premium_1yr"));
    public static final Set<String> k = new TreeSet(Arrays.asList("adsfree_3mo", "adsfree_6mo", "adsfree_1yr", "premium_1mo", "premium_1yr"));
    private static final Comparator<o1> l = c1.f17876a;

    /* renamed from: a  reason: collision with root package name */
    private final Thread f17967a = Thread.currentThread();
    private final Handler b = new Handler();

    /* renamed from: c  reason: collision with root package name */
    private final FingService f17968c;

    /* renamed from: d  reason: collision with root package name */
    private final List<b> f17969d = new CopyOnWriteArrayList();

    /* renamed from: e  reason: collision with root package name */
    private final Map<s1, t1> f17970e;

    /* renamed from: f  reason: collision with root package name */
    private n1 f17971f;

    /* renamed from: g  reason: collision with root package name */
    private List<String> f17972g;

    /* renamed from: h  reason: collision with root package name */
    private h f17973h;

    /* access modifiers changed from: package-private */
    /* compiled from: PurchaseManager */
    public class a implements g {
        a() {
        }

        /* JADX WARNING: Code restructure failed: missing block: B:40:0x009a, code lost:
            r0 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:41:0x009b, code lost:
            if (r8 != null) goto L_0x009d;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:43:?, code lost:
            r8.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:44:0x00a1, code lost:
            r8 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:45:0x00a2, code lost:
            r7.addSuppressed(r8);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:46:0x00a5, code lost:
            throw r0;
         */
        @Override // h.g
        public void a(f fVar, i0 i0Var) {
            try {
                if (i0Var.x()) {
                    k0 b = i0Var.b();
                    if (b != null) {
                        JSONObject jSONObject = new JSONObject(b.i());
                        if (!jSONObject.has("data") || !jSONObject.getJSONObject("data").has("products")) {
                            throw new IOException("JSON has no products configured");
                        }
                        ArrayList arrayList = new ArrayList();
                        JSONArray jSONArray = jSONObject.getJSONObject("data").getJSONArray("products");
                        int i2 = 0;
                        for (int i3 = 0; i3 < jSONArray.length(); i3++) {
                            arrayList.add(jSONArray.getString(i3));
                        }
                        n1 n1Var = null;
                        if (jSONObject.has("promos")) {
                            JSONArray jSONArray2 = jSONObject.getJSONArray("promos");
                            n1 n1Var2 = null;
                            while (true) {
                                if (i2 >= jSONArray2.length()) {
                                    break;
                                }
                                n1Var2 = n1.k(jSONArray2.getJSONObject(i2));
                                if (n1Var2 != null && n1Var2.j()) {
                                    break;
                                }
                                if (n1Var2 != null && !n1Var2.j()) {
                                    n1Var2 = null;
                                }
                                i2++;
                            }
                            n1Var = n1Var2;
                        }
                        q1.this.z(new d1(this, arrayList, n1Var));
                        b.close();
                        return;
                    }
                    throw new IOException("HTTP response body is empty!");
                }
                throw new IOException("HTTP response invalid (code=" + i0Var.i() + ",message=" + i0Var.y() + ")");
            } catch (Exception e2) {
                Log.e("fing:purchase", "Failed to parse products JSON", e2);
                q1.b(q1.this, e2);
            }
        }

        @Override // h.g
        public void b(f fVar, IOException iOException) {
            Log.e("fing:purchase", "Failed to retrieve products JSON", iOException);
            q1.b(q1.this, iOException);
        }
    }

    /* compiled from: PurchaseManager */
    public interface b extends u1 {
        void G();

        void d(Throwable th);
    }

    public q1(Context context, FingService fingService) {
        super(context);
        HashMap hashMap = new HashMap();
        this.f17970e = hashMap;
        this.f17972g = new ArrayList();
        this.f17973h = new h(null);
        this.f17968c = fingService;
        if (q.o(this)) {
            hashMap.put(s1.GOOGLE, new h1(this, fingService, new ArrayList(k), this));
        }
        if (q.q(this)) {
            hashMap.put(s1.HUAWEI, new l1(this, fingService, new ArrayList(k), this));
        }
        u();
    }

    static void b(q1 q1Var, Throwable th) {
        q1Var.z(new e1(q1Var, th));
    }

    static void g(q1 q1Var) {
        q1Var.z(new f1(q1Var));
    }

    private static o1 n(List<o1> list) {
        if (list.isEmpty()) {
            return null;
        }
        Collections.sort(list, l);
        return list.get(0);
    }

    private void u() {
        Log.i("fing:purchase", "Fetching products from https://cdn.fing.io/json/iap/iap_android_2.0.json");
        c0 c0Var = new c0(com.overlook.android.fing.engine.j.h.b.b());
        e0.a aVar = new e0.a();
        aVar.h("https://cdn.fing.io/json/iap/iap_android_2.0.json");
        e0 b2 = aVar.b();
        this.f17973h.j(5000, true);
        ((e) c0Var.A(b2)).g(new a());
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void z(Runnable runnable) {
        if (Thread.currentThread() != this.f17967a) {
            this.b.removeCallbacks(runnable);
            this.b.post(runnable);
            return;
        }
        runnable.run();
    }

    public void A() {
        for (t1 t1Var : this.f17970e.values()) {
            t1Var.p();
        }
    }

    public void B(Context context) {
        C(context, q(), null, null);
    }

    public void C(Context context, s1 s1Var, Runnable runnable, Runnable runnable2) {
        if (s1Var != null) {
            Intent intent = new Intent(context, PurchaseActivity.class);
            intent.putExtra("store", s1Var);
            context.startActivity(intent);
            return;
        }
        FingService fingService = this.f17968c;
        f0 f0Var = new f0(context);
        f0Var.K(R.string.inapp_purchases_disabled);
        f0Var.x(R.string.inapp_purchases_disabled_description2);
        f0Var.d(false);
        f0Var.G(R.string.prefs_contactus_title, new u(fingService, context, runnable2));
        f0Var.z(R.string.generic_cancel, new e.f.a.a.b.f.g(runnable));
        f0Var.M();
    }

    public void D(b bVar) {
        if (!this.f17969d.contains(bVar)) {
            this.f17969d.add(bVar);
        }
    }

    public void E(boolean z) {
        if (this.f17972g.isEmpty() && !this.f17973h.f()) {
            u();
        }
        for (s1 s1Var : this.f17970e.keySet()) {
            t1 t1Var = this.f17970e.get(s1Var);
            if (t1Var != null) {
                t1Var.q(z);
            }
        }
    }

    public void F(b bVar) {
        this.f17969d.remove(bVar);
    }

    @Override // com.overlook.android.fing.ui.purchase.u1
    public void L(s1 s1Var, int i2) {
        for (b bVar : this.f17969d) {
            bVar.L(s1Var, i2);
        }
    }

    @Override // com.overlook.android.fing.ui.purchase.u1
    public void O(s1 s1Var, m1 m1Var, int i2) {
        for (b bVar : this.f17969d) {
            bVar.O(s1Var, m1Var, i2);
        }
    }

    @Override // com.overlook.android.fing.ui.purchase.u1
    public void Y(s1 s1Var, o1 o1Var) {
        for (b bVar : this.f17969d) {
            bVar.Y(s1Var, o1Var);
        }
    }

    @Override // com.overlook.android.fing.ui.purchase.u1
    public void a0(s1 s1Var, List<o1> list) {
        o0 K;
        for (b bVar : this.f17969d) {
            bVar.a0(s1Var, list);
        }
        m0 m0Var = (m0) this.f17968c.k();
        if (m0Var.S() && (K = m0Var.K()) != null && K.a() == o0.a.FREE && t(j)) {
            Log.d("fing:purchase", "Account type of sync: forcing synchronization...");
            this.f17968c.f().l0();
        }
    }

    @Override // com.overlook.android.fing.ui.purchase.u1
    public void b0(s1 s1Var, m1 m1Var) {
        for (b bVar : this.f17969d) {
            bVar.b0(s1Var, m1Var);
        }
    }

    @Override // com.overlook.android.fing.ui.purchase.u1
    public void f0(s1 s1Var, List<m1> list) {
        for (b bVar : this.f17969d) {
            bVar.f0(s1Var, list);
        }
    }

    public boolean h(s1 s1Var) {
        t1 t1Var = this.f17970e.get(s1Var);
        if (t1Var != null) {
            return t1Var.a();
        }
        return false;
    }

    public boolean i(s1 s1Var, m1 m1Var) {
        return j(s1Var, m1Var.c());
    }

    public boolean j(s1 s1Var, String str) {
        t1 t1Var;
        n1 n1Var = this.f17971f;
        if ((n1Var == null || n1Var.f().contains(str)) && (t1Var = this.f17970e.get(s1Var)) != null) {
            return t1Var.b(str);
        }
        return false;
    }

    public boolean k(s1 s1Var) {
        t1 t1Var = this.f17970e.get(s1Var);
        if (t1Var != null) {
            return t1Var.c();
        }
        return false;
    }

    public void l(Activity activity, s1 s1Var, Intent intent) {
        t1 t1Var = this.f17970e.get(s1Var);
        if (t1Var != null) {
            t1Var.d(activity, intent);
        }
    }

    public List<m1> m(s1 s1Var) {
        t1 t1Var = this.f17970e.get(s1Var);
        if (t1Var != null) {
            return t1Var.g(this.f17972g);
        }
        return Collections.emptyList();
    }

    public o1 o() {
        ArrayList arrayList = new ArrayList();
        for (t1 t1Var : this.f17970e.values()) {
            for (o1 o1Var : t1Var.i()) {
                if (o1Var.c() == r1.ACTIVE) {
                    arrayList.add(o1Var);
                }
            }
        }
        return n(arrayList);
    }

    public o1 p(s1 s1Var) {
        ArrayList arrayList = new ArrayList();
        t1 t1Var = this.f17970e.get(s1Var);
        if (t1Var != null) {
            for (o1 o1Var : t1Var.i()) {
                if (o1Var.c() == r1.ACTIVE) {
                    arrayList.add(o1Var);
                }
            }
        }
        return n(arrayList);
    }

    public s1 q() {
        boolean z;
        if (!this.f17970e.isEmpty()) {
            Iterator<s1> it = this.f17970e.keySet().iterator();
            while (true) {
                if (it.hasNext()) {
                    if (h(it.next())) {
                        z = true;
                        break;
                    }
                } else {
                    break;
                }
            }
        }
        z = false;
        if (!z) {
            return null;
        }
        HashSet hashSet = new HashSet();
        ArrayList arrayList = new ArrayList();
        for (s1 s1Var : this.f17970e.keySet()) {
            ArrayList arrayList2 = new ArrayList();
            t1 t1Var = this.f17970e.get(s1Var);
            if (t1Var != null) {
                arrayList2.addAll(t1Var.i());
            }
            arrayList.addAll(arrayList2);
        }
        Iterator it2 = arrayList.iterator();
        while (it2.hasNext()) {
            hashSet.add(((o1) it2.next()).b().j());
        }
        if (hashSet.size() == 1) {
            return (s1) hashSet.iterator().next();
        }
        if (hashSet.size() > 1) {
            Collections.sort(arrayList, l);
            return ((o1) arrayList.get(0)).b().j();
        }
        s1[] values = s1.values();
        for (int i2 = 0; i2 < 3; i2++) {
            s1 s1Var2 = values[i2];
            t1 t1Var2 = this.f17970e.get(s1Var2);
            if (t1Var2 != null && t1Var2.a()) {
                return s1Var2;
            }
        }
        return null;
    }

    public n1 r() {
        return this.f17971f;
    }

    public o1 s(String str, s1 s1Var) {
        t1 t1Var = this.f17970e.get(s1Var);
        if (t1Var != null) {
            return t1Var.h(str);
        }
        return null;
    }

    public boolean t(Set<String> set) {
        for (t1 t1Var : this.f17970e.values()) {
            Iterator<o1> it = t1Var.i().iterator();
            while (true) {
                if (it.hasNext()) {
                    o1 next = it.next();
                    if (next.c() == r1.ACTIVE && set.contains(next.b().c())) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    public boolean v() {
        for (t1 t1Var : this.f17970e.values()) {
            if (!t1Var.l()) {
                return false;
            }
        }
        return true;
    }

    public /* synthetic */ void w(Throwable th) {
        for (b bVar : this.f17969d) {
            bVar.d(th);
        }
    }

    public /* synthetic */ void x() {
        for (b bVar : this.f17969d) {
            bVar.G();
        }
    }

    public void y(Activity activity, m1 m1Var) {
        t1 t1Var = this.f17970e.get(m1Var.j());
        if (t1Var != null) {
            t1Var.m(activity, m1Var);
        }
    }
}