package com.pgl.ssdk.ces;

import android.content.Context;
import android.text.TextUtils;
import android.view.MotionEvent;
import com.pgl.ssdk.a4;
import com.pgl.ssdk.aa;
import com.pgl.ssdk.ab;
import com.pgl.ssdk.ac;
import com.pgl.ssdk.ad;
import com.pgl.ssdk.ae;
import com.pgl.ssdk.af;
import com.pgl.ssdk.ag;
import com.pgl.ssdk.ah;
import com.pgl.ssdk.ai;
import com.pgl.ssdk.aj;
import com.pgl.ssdk.ak;
import com.pgl.ssdk.al;
import com.pgl.ssdk.am;
import com.pgl.ssdk.an;
import com.pgl.ssdk.ao;
import com.pgl.ssdk.ar;
import com.pgl.ssdk.av;
import com.pgl.ssdk.aw;
import com.pgl.ssdk.ax;
import com.pgl.ssdk.ay;
import com.pgl.ssdk.ces.out.PglSSManager;
import com.pgl.ssdk.f;
import com.pgl.ssdk.u;
import com.pgl.ssdk.v;
import com.pgl.ssdk.w;
import com.pgl.ssdk.x;
import com.pgl.ssdk.y;
import com.pgl.ssdk.z;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes.dex */
public class b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static volatile b f24728a = null;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static boolean f24729b = false;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static Map<String, Object> f24730c = null;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static int f24731d = 1;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private static av.a f24732e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public Context f24733f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private String f24734g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private int f24735h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private String f24736i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private String f24737j = null;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private String f24738k = null;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public int f24739l = 1;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public int f24740m = 0;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public boolean f24741n = true;

    public class a implements Runnable {
        public a() {
        }

        @Override // java.lang.Runnable
        public void run() {
            try {
                f.c();
            } catch (Throwable unused) {
            }
        }
    }

    /* JADX INFO: renamed from: com.pgl.ssdk.ces.b$b, reason: collision with other inner class name */
    public class RunnableC0122b implements Runnable {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final /* synthetic */ String f24743a;

        public RunnableC0122b(String str) {
            this.f24743a = str;
        }

        @Override // java.lang.Runnable
        public void run() {
            if (!TextUtils.isEmpty(this.f24743a) && this.f24743a.equals(PglSSManager.REPORT_SCENE_ADSHOW)) {
                ab.b(b.this.f24733f);
            }
            al.a(b.this.f24733f).a();
            aa.b(b.this.f24733f);
        }
    }

    private b(Context context, String str) {
        this.f24733f = context;
        this.f24734g = str;
    }

    public static b a(Context context, String str, int i10, int i11, String str2) {
        if (f24728a == null) {
            synchronized (b.class) {
                try {
                    if (f24728a == null) {
                        if (context == null) {
                            context = ab.a().getApplicationContext();
                        }
                        if (context == null) {
                            f24731d = 4;
                            return null;
                        }
                        a(i10);
                        av.a aVarB = av.b(context, "nms");
                        if (aVarB != null) {
                            f24731d = aVarB.f24721a;
                            f24732e = aVarB;
                            return null;
                        }
                        b bVar = new b(context, str);
                        f24728a = bVar;
                        bVar.f24735h = i11;
                        f24728a.f24736i = str2;
                        f24728a.b(context);
                        f24728a.e(a(context));
                        z.a(context);
                        f24731d = 0;
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
        return f24728a;
    }

    public static String b() {
        if (e() != null) {
            return e().f24737j;
        }
        return null;
    }

    public static String c() {
        b bVarE = e();
        if (bVarE == null || TextUtils.isEmpty(bVarE.f24738k)) {
            return null;
        }
        return bVarE.f24738k;
    }

    public static int d() {
        return f24731d;
    }

    public static b e() {
        return f24728a;
    }

    public static av.a f() {
        return f24732e;
    }

    public String g() {
        return a4.a();
    }

    public void h() {
        a4.a(this.f24733f, this.f24734g);
        long jCurrentTimeMillis = System.currentTimeMillis();
        if (ay.a(aw.a(this.f24733f, "pgl_init_report", 0L), jCurrentTimeMillis)) {
            int i10 = f24728a.f24740m;
            if ((i10 > 0 && i10 < 100 && Math.random() * 100.0d < i10) || i10 == 100) {
                a("Start", null, TextUtils.isEmpty(a4.a()) ? 10000L : 0L);
            }
        } else {
            a("Start", null, TextUtils.isEmpty(a4.a()) ? 10000L : 0L);
            aw.b(this.f24733f, "pgl_init_report", jCurrentTimeMillis);
        }
        a("Start");
        if (this.f24741n) {
            ar.a(new a(), 20000L);
        }
    }

    private void b(Context context) {
        if (context == null || f24729b) {
            return;
        }
        try {
            com.pgl.ssdk.ces.a.meta(101, null, "1");
            com.pgl.ssdk.ces.a.meta(102, null, this.f24734g);
            com.pgl.ssdk.ces.a.meta(114, null, Integer.valueOf(this.f24735h));
            StringBuilder sb = new StringBuilder();
            sb.append(ab.h(context));
            com.pgl.ssdk.ces.a.meta(105, null, sb.toString());
            com.pgl.ssdk.ces.a.meta(152, null, ab.i(context));
            com.pgl.ssdk.ces.a.meta(153, null, ab.d(context));
            com.pgl.ssdk.ces.a.meta(106, null, ab.f(context));
            com.pgl.ssdk.ces.a.meta(107, null, ab.e(context));
            com.pgl.ssdk.ces.a.meta(108, null, ab.c(context));
            com.pgl.ssdk.ces.a.meta(109, null, ab.d());
            com.pgl.ssdk.ces.a.meta(110, null, ab.c());
            com.pgl.ssdk.ces.a.meta(115, null, this.f24736i);
            f24729b = true;
        } catch (Throwable unused) {
        }
    }

    private void e(String str) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        com.pgl.ssdk.ces.a.meta(104, null, str);
    }

    public Object a(int i10, Object obj) {
        int iA;
        boolean zA;
        if (i10 == 123) {
            return af.a(this.f24733f);
        }
        if (i10 == 121) {
            return ad.a();
        }
        if (i10 == 122) {
            return ad.b();
        }
        if (i10 == 126) {
            return ad.b(this.f24733f);
        }
        if (i10 == 128) {
            return ad.c(this.f24733f);
        }
        if (i10 == 120) {
            return ac.c();
        }
        if (i10 == 124) {
            return ag.c(this.f24733f);
        }
        if (i10 == 130) {
            return ag.a(this.f24733f);
        }
        if (i10 == 145) {
            return ah.c(this.f24733f);
        }
        if (i10 == 125) {
            return ag.b(this.f24733f);
        }
        if (i10 == 129) {
            return ae.f(this.f24733f);
        }
        if (i10 == 141) {
            return ae.e(this.f24733f);
        }
        if (i10 == 134) {
            return ak.a(this.f24733f).b();
        }
        if (i10 == 140) {
            return al.a(this.f24733f).e();
        }
        if (i10 == 144) {
            return al.a(this.f24733f).d();
        }
        if (i10 == 133) {
            return a(obj);
        }
        if (i10 == 135) {
            return v.g();
        }
        if (i10 == 201) {
            return ad.a(this.f24733f);
        }
        if (i10 == 202) {
            return ad.c();
        }
        if (i10 == 236) {
            return ax.a((String) obj);
        }
        if (i10 == 142) {
            return ab.g(this.f24733f);
        }
        if (i10 == 143) {
            return ah.a(this.f24733f);
        }
        if (i10 == 146) {
            return v.c();
        }
        if (i10 != 147) {
            if (i10 == 148) {
                return u.b(this.f24733f);
            }
            if (i10 == 149) {
                return w.a(this.f24733f);
            }
            if (i10 == 150) {
                iA = x.a(this.f24733f);
            } else {
                if (i10 == 151) {
                    return w.a();
                }
                if (i10 == 161) {
                    zA = v.h();
                } else {
                    if (i10 == 163) {
                        return aj.a();
                    }
                    if (i10 == 169) {
                        zA = aa.a(this.f24733f);
                    } else if (i10 == 170) {
                        iA = y.b((String) obj);
                    } else {
                        if (i10 == 203) {
                            return ab.b();
                        }
                        if (i10 == 205) {
                            iA = ab.k(this.f24733f);
                        } else {
                            if (i10 != 204) {
                                if (i10 == 206) {
                                    return ah.b(this.f24733f);
                                }
                                return null;
                            }
                            iA = ae.a(this.f24733f);
                        }
                    }
                }
            }
            return Integer.valueOf(iA);
        }
        zA = ab.j(this.f24733f);
        return Boolean.valueOf(zA);
    }

    public synchronized void c(String str) {
        if (!TextUtils.isEmpty(str) && !str.equals(this.f24737j)) {
            this.f24737j = str;
            com.pgl.ssdk.ces.a.meta(103, null, str);
        }
    }

    public synchronized void d(String str) {
        if (!TextUtils.isEmpty(str) && !str.equals(this.f24738k)) {
            com.pgl.ssdk.ces.a.meta(111, null, str);
            this.f24738k = str;
            a4.b();
        }
    }

    public static String a() {
        if (e() != null) {
            return e().f24734g;
        }
        return null;
    }

    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    /* JADX WARN: Removed duplicated region for block: B:26:0x0062  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private void b(String str) {
        byte b10;
        int iIntValue;
        try {
            JSONObject jSONObject = new JSONObject(str);
            Iterator<String> itKeys = jSONObject.keys();
            while (itKeys.hasNext()) {
                String next = itKeys.next();
                Object obj = jSONObject.get(next);
                switch (next.hashCode()) {
                    case -417749689:
                        b10 = !next.equals("touch_trace_enabled") ? (byte) -1 : (byte) 4;
                        break;
                    case -257777372:
                        if (next.equals("init_prob")) {
                            b10 = 5;
                            break;
                        }
                        break;
                    case -93508180:
                        if (next.equals("autoctl_detect_enable")) {
                            b10 = 0;
                            break;
                        }
                        break;
                    case 449342513:
                        if (next.equals("craw_ratio")) {
                            b10 = 3;
                            break;
                        }
                        break;
                    case 944591168:
                        if (next.equals("report_ratio")) {
                            b10 = 1;
                            break;
                        }
                        break;
                    case 1286849298:
                        if (next.equals("app_switch")) {
                            b10 = 2;
                            break;
                        }
                        break;
                    default:
                        break;
                }
                if (b10 != 0) {
                    if (b10 != 1) {
                        if (b10 != 2) {
                            if (b10 != 3) {
                                if (b10 != 4) {
                                    if (b10 == 5 && (obj instanceof Integer) && (iIntValue = ((Integer) obj).intValue()) >= 0 && iIntValue <= 100) {
                                        this.f24740m = iIntValue;
                                    }
                                } else if (obj instanceof Boolean) {
                                    y.f24801g = ((Boolean) obj).booleanValue();
                                }
                            } else if ((obj instanceof Integer) && ((Integer) obj).intValue() > 0) {
                                f.f24765b = ((Integer) obj).intValue();
                            }
                        } else if (obj instanceof Boolean) {
                            this.f24741n = ((Boolean) obj).booleanValue();
                        }
                    } else if ((obj instanceof Integer) && ((Integer) obj).intValue() > 0) {
                        this.f24739l = ((Integer) obj).intValue();
                    }
                } else if (obj instanceof Boolean) {
                    ak.f24670b = ((Boolean) obj).booleanValue();
                }
            }
        } catch (JSONException unused) {
        }
    }

    private static String a(Context context) {
        String strA = aw.a(context, "iid");
        if (!TextUtils.isEmpty(strA)) {
            return strA;
        }
        String string = UUID.randomUUID().toString();
        aw.b(context, "iid", string);
        return string;
    }

    private String a(Object obj) {
        Map<String, Object> map;
        if (!(obj instanceof String) || !"Start".equals((String) obj) || (map = f24730c) == null || map.isEmpty()) {
            return "{}";
        }
        try {
            return new JSONObject(f24730c).toString();
        } catch (Exception unused) {
            return "{}";
        }
    }

    public Map<String, String> a(String str, byte[] bArr) {
        HashMap map = new HashMap();
        Object[] objArr = new Object[2];
        if (str == null) {
            str = "";
        }
        objArr[0] = str;
        if (bArr == null) {
            bArr = new byte[0];
        }
        objArr[1] = bArr;
        String str2 = (String) com.pgl.ssdk.ces.a.meta(224, this.f24733f, objArr);
        if (!TextUtils.isEmpty(str2)) {
            map.put("X-Armors", str2);
        }
        return map;
    }

    public static void a(int i10) {
        an.a(i10);
    }

    public void a(MotionEvent motionEvent) {
        y.a(motionEvent, this.f24733f);
    }

    public void a(String str) {
        ar.b(new RunnableC0122b(str));
    }

    public void a(String str, String str2, String str3, String str4) {
        c(str2);
        d(str4);
        try {
            h();
        } catch (Throwable unused) {
        }
    }

    public void a(String str, Map<String, Object> map, long j10) {
        try {
            ar.a(new ao(this.f24733f, 222, new Object[]{str, map}), j10);
        } catch (Throwable unused) {
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:105:0x0011, code lost:
    
        continue;
     */
    /* JADX WARN: Removed duplicated region for block: B:35:0x0071  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public synchronized void a(Map<String, Object> map) {
        if (map != null) {
            try {
            } catch (Throwable th) {
                throw th;
            }
            if (!map.isEmpty()) {
                try {
                    for (String str : map.keySet()) {
                        Object obj = map.get(str);
                        if (obj != null) {
                            switch (str) {
                                case "check_clz":
                                    if (!(obj instanceof String)) {
                                        continue;
                                        break;
                                    } else {
                                        String strA = ai.a((String) obj);
                                        if (!TextUtils.isEmpty(strA)) {
                                            com.pgl.ssdk.ces.a.meta(159, null, strA);
                                        }
                                        break;
                                    }
                                    break;
                                case "key_ipv6":
                                    if (!(obj instanceof String)) {
                                        continue;
                                        break;
                                    } else {
                                        String str2 = (String) obj;
                                        if (!TextUtils.isEmpty(str2)) {
                                            am.a(str2);
                                        }
                                        break;
                                    }
                                    break;
                                case "key_transfer_host":
                                    if (!(obj instanceof String)) {
                                        continue;
                                        break;
                                    } else {
                                        an.a((String) obj);
                                        break;
                                    }
                                    break;
                                case "key_ads_url_backup":
                                    if (!(obj instanceof Set)) {
                                        continue;
                                        break;
                                    } else {
                                        an.a((Set<String>) obj);
                                        break;
                                    }
                                    break;
                                case "fields_allowed":
                                    if (!(obj instanceof Set)) {
                                        continue;
                                        break;
                                    } else {
                                        try {
                                            Set set = (Set) obj;
                                            com.pgl.ssdk.ces.a.meta(165, null, Boolean.valueOf(set.contains("boot")));
                                            com.pgl.ssdk.ces.a.meta(166, null, Boolean.valueOf(set.contains("mnc")));
                                            com.pgl.ssdk.ces.a.meta(167, null, Boolean.valueOf(set.contains("mcc")));
                                        } catch (Throwable unused) {
                                        }
                                        break;
                                    }
                                    break;
                                case "target-idc":
                                    if (!(obj instanceof String)) {
                                        continue;
                                        break;
                                    } else {
                                        an.b((String) obj);
                                        break;
                                    }
                                    break;
                                case "sec_config":
                                    if (!(obj instanceof String)) {
                                        continue;
                                        break;
                                    } else {
                                        b((String) obj);
                                        break;
                                    }
                                    break;
                            }
                            throw th;
                        }
                    }
                    if (f24730c == null) {
                        f24730c = new HashMap();
                    }
                    f24730c.putAll(map);
                } catch (Throwable unused2) {
                }
            }
        }
    }
}
