package p138.p176.p177.p242.p265.p266;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.text.TextUtils;
import com.google.android.gms.internal.measurement.zzft;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import p000.p001.p002.p003.p004.C0567;
import p037.p057.C1714;
import p138.p176.p177.p242.p246.p251.C4303;
import p138.p176.p177.p242.p258.p263.AbstractC4421;
import p138.p176.p177.p242.p258.p263.C4584;
import p138.p176.p177.p242.p258.p263.C4586;
import p138.p176.p177.p242.p258.p263.C4588;
import p138.p176.p177.p242.p258.p263.C4593;
import p138.p176.p177.p242.p258.p263.C4600;
import p138.p176.p177.p242.p258.p263.C4602;
import p138.p176.p177.p242.p258.p263.C4606;
import p138.p176.p177.p242.p258.p263.C4626;

/* JADX INFO: renamed from: ދ.ހ.֏.ހ.ބ.֏.ˌ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C4816 extends AbstractC4843 implements InterfaceC4901 {

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final Map<String, Map<String, String>> f14486;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final Map<String, Map<String, Boolean>> f14487;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final Map<String, Map<String, Boolean>> f14488;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final Map<String, C4602> f14489;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final Map<String, Map<String, Integer>> f14490;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final Map<String, String> f14491;

    public C4816(C4889 c4889) {
        super(c4889);
        this.f14486 = new C1714();
        this.f14487 = new C1714();
        this.f14488 = new C1714();
        this.f14489 = new C1714();
        this.f14491 = new C1714();
        this.f14490 = new C1714();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static Map<String, String> m8068(C4602 c4602) {
        C1714 c1714 = new C1714();
        if (c4602 != null) {
            for (C4626 c4626 : c4602.zzg) {
                c1714.put(c4626.zzd, c4626.zze);
            }
        }
        return c1714;
    }

    @Override // p138.p176.p177.p242.p265.p266.InterfaceC4901
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final String mo8069(String str, String str2) throws Throwable {
        mo8008();
        m8081(str);
        Map<String, String> map = this.f14486.get(str);
        if (map != null) {
            return map.get(str2);
        }
        return null;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C4602 m8070(String str) throws Throwable {
        m8155();
        mo8008();
        C0567.m1926(str);
        m8081(str);
        return this.f14489.get(str);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C4602 m8071(String str, byte[] bArr) {
        if (bArr == null) {
            return C4602.zzl;
        }
        try {
            C4602 c4602 = (C4602) ((AbstractC4421) ((C4602.C4603) C4833.m8121(C4602.zzl.m7362(), bArr)).m7370());
            C4792 c4792 = mo8165().f14452;
            boolean z = true;
            Long lValueOf = (c4602.zzc & 1) != 0 ? Long.valueOf(c4602.zzd) : null;
            if ((c4602.zzc & 2) == 0) {
                z = false;
            }
            c4792.m8036("Parsed config. version, gmp_app_id", lValueOf, z ? c4602.zze : null);
            return c4602;
        } catch (zzft e) {
            mo8165().f14447.m8036("Unable to merge remote config. appId", C4794.m8038(str), e);
            return C4602.zzl;
        } catch (RuntimeException e2) {
            mo8165().f14447.m8036("Unable to merge remote config. appId", C4794.m8038(str), e2);
            return C4602.zzl;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m8072(String str, C4602.C4603 c4603) {
        C1714 c1714 = new C1714();
        C1714 c17142 = new C1714();
        C1714 c17143 = new C1714();
        if (c4603 != null) {
            for (int i = 0; i < ((C4602) c4603.f13774).zzh.size(); i++) {
                C4600.C4601 c4601M7363 = ((C4602) c4603.f13774).zzh.get(i).m7363();
                if (TextUtils.isEmpty(c4601M7363.m7630())) {
                    mo8165().f14447.m8034("EventConfig contained null event name");
                } else {
                    String strM7023 = C4303.m7023(c4601M7363.m7630(), C4775.f14397, C4775.f14398);
                    if (!TextUtils.isEmpty(strM7023)) {
                        if (c4601M7363.f13775) {
                            c4601M7363.m7368();
                            c4601M7363.f13775 = false;
                        }
                        C4600.m7629((C4600) c4601M7363.f13774, strM7023);
                        if (c4603.f13775) {
                            c4603.m7368();
                            c4603.f13775 = false;
                        }
                        C4602.m7633((C4602) c4603.f13774, i, (C4600) ((AbstractC4421) c4601M7363.m7370()));
                    }
                    c1714.put(c4601M7363.m7630(), Boolean.valueOf(((C4600) c4601M7363.f13774).zze));
                    c17142.put(c4601M7363.m7630(), Boolean.valueOf(((C4600) c4601M7363.f13774).zzf));
                    if ((((C4600) c4601M7363.f13774).zzc & 8) != 0) {
                        if (c4601M7363.m7631() < 2 || c4601M7363.m7631() > 65535) {
                            mo8165().f14447.m8036("Invalid sampling rate. Event name, sample rate", c4601M7363.m7630(), Integer.valueOf(c4601M7363.m7631()));
                        } else {
                            c17143.put(c4601M7363.m7630(), Integer.valueOf(c4601M7363.m7631()));
                        }
                    }
                }
            }
        }
        this.f14487.put(str, c1714);
        this.f14488.put(str, c17142);
        this.f14490.put(str, c17143);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final boolean m8073(String str, byte[] bArr, String str2) {
        byte[] bArrM7406;
        boolean z;
        String str3;
        boolean z2;
        boolean z3;
        m8155();
        mo8008();
        C0567.m1926(str);
        C4602.C4603 c4603M7363 = m8071(str, bArr).m7363();
        if (c4603M7363 == null) {
            return false;
        }
        m8072(str, c4603M7363);
        this.f14489.put(str, (C4602) ((AbstractC4421) c4603M7363.m7370()));
        this.f14491.put(str, str2);
        this.f14486.put(str, m8068((C4602) ((AbstractC4421) c4603M7363.m7370())));
        C4900 c4900M8158 = m8158();
        ArrayList<C4584> arrayList = new ArrayList(Collections.unmodifiableList(((C4602) c4603M7363.f13774).zzi));
        if (c4900M8158 == null) {
            throw null;
        }
        String str4 = "app_id=? and audience_id=?";
        C0567.m1910(arrayList);
        int i = 0;
        while (i < arrayList.size()) {
            C4584.C4585 c4585M7363 = ((C4584) arrayList.get(i)).m7363();
            if (((C4584) c4585M7363.f13774).zzf.size() != 0) {
                int i2 = 0;
                while (i2 < ((C4584) c4585M7363.f13774).zzf.size()) {
                    C4586.C4587 c4587M7363 = ((C4584) c4585M7363.f13774).zzf.get(i2).m7363();
                    C4586.C4587 c4587 = (C4586.C4587) ((AbstractC4421.AbstractC4423) c4587M7363.clone());
                    String strM7023 = C4303.m7023(((C4586) c4587M7363.f13774).zze, C4775.f14397, C4775.f14398);
                    if (strM7023 != null) {
                        if (c4587.f13775) {
                            c4587.m7368();
                            c4587.f13775 = false;
                        }
                        C4586.m7612((C4586) c4587.f13774, strM7023);
                        z3 = true;
                    } else {
                        z3 = false;
                    }
                    int i3 = 0;
                    while (i3 < ((C4586) c4587M7363.f13774).zzf.size()) {
                        C4588 c4588 = ((C4586) c4587M7363.f13774).zzf.get(i3);
                        C4586.C4587 c45872 = c4587M7363;
                        C4602.C4603 c4603 = c4603M7363;
                        String str5 = str4;
                        String strM70232 = C4303.m7023(c4588.zzg, C4830.f14537, C4830.f14538);
                        if (strM70232 != null) {
                            C4588.C4589 c4589M7363 = c4588.m7363();
                            if (c4589M7363.f13775) {
                                c4589M7363.m7368();
                                c4589M7363.f13775 = false;
                            }
                            C4588.m7615((C4588) c4589M7363.f13774, strM70232);
                            C4588 c45882 = (C4588) ((AbstractC4421) c4589M7363.m7370());
                            if (c4587.f13775) {
                                c4587.m7368();
                                c4587.f13775 = false;
                            }
                            C4586.m7611((C4586) c4587.f13774, i3, c45882);
                            z3 = true;
                        }
                        i3++;
                        c4587M7363 = c45872;
                        c4603M7363 = c4603;
                        str4 = str5;
                    }
                    C4602.C4603 c46032 = c4603M7363;
                    String str6 = str4;
                    if (z3) {
                        if (c4585M7363.f13775) {
                            c4585M7363.m7368();
                            c4585M7363.f13775 = false;
                        }
                        C4584.m7609((C4584) c4585M7363.f13774, i2, (C4586) ((AbstractC4421) c4587.m7370()));
                        arrayList.set(i, (C4584) ((AbstractC4421) c4585M7363.m7370()));
                    }
                    i2++;
                    c4603M7363 = c46032;
                    str4 = str6;
                }
            }
            C4602.C4603 c46033 = c4603M7363;
            String str7 = str4;
            if (((C4584) c4585M7363.f13774).zze.size() != 0) {
                for (int i4 = 0; i4 < ((C4584) c4585M7363.f13774).zze.size(); i4++) {
                    C4593 c4593 = ((C4584) c4585M7363.f13774).zze.get(i4);
                    String strM70233 = C4303.m7023(c4593.zze, C4997.f15112, C4997.f15113);
                    if (strM70233 != null) {
                        C4593.C4594 c4594M7363 = c4593.m7363();
                        if (c4594M7363.f13775) {
                            c4594M7363.m7368();
                            z2 = false;
                            c4594M7363.f13775 = false;
                        } else {
                            z2 = false;
                        }
                        C4593.m7623((C4593) c4594M7363.f13774, strM70233);
                        if (c4585M7363.f13775) {
                            c4585M7363.m7368();
                            c4585M7363.f13775 = z2;
                        }
                        C4584.m7610((C4584) c4585M7363.f13774, i4, (C4593) ((AbstractC4421) c4594M7363.m7370()));
                        arrayList.set(i, (C4584) ((AbstractC4421) c4585M7363.m7370()));
                    }
                }
            }
            i++;
            c4603M7363 = c46033;
            str4 = str7;
        }
        C4602.C4603 c46034 = c4603M7363;
        String str8 = str4;
        c4900M8158.m8155();
        c4900M8158.mo8008();
        C0567.m1926(str);
        C0567.m1910(arrayList);
        SQLiteDatabase sQLiteDatabaseM8354 = c4900M8158.m8354();
        sQLiteDatabaseM8354.beginTransaction();
        try {
            c4900M8158.m8155();
            c4900M8158.mo8008();
            C0567.m1926(str);
            SQLiteDatabase sQLiteDatabaseM83542 = c4900M8158.m8354();
            sQLiteDatabaseM83542.delete("property_filters", "app_id=?", new String[]{str});
            sQLiteDatabaseM83542.delete("event_filters", "app_id=?", new String[]{str});
            for (C4584 c4584 : arrayList) {
                c4900M8158.m8155();
                c4900M8158.mo8008();
                C0567.m1926(str);
                C0567.m1910(c4584);
                if ((c4584.zzc & 1) != 0) {
                    int i5 = c4584.zzd;
                    Iterator<C4586> it = c4584.zzf.iterator();
                    while (true) {
                        if (it.hasNext()) {
                            if (!it.next().m7613()) {
                                c4900M8158.mo8165().f14447.m8036("Event filter with no ID. Audience definition ignored. appId, audienceId", C4794.m8038(str), Integer.valueOf(i5));
                                break;
                            }
                        } else {
                            Iterator<C4593> it2 = c4584.zze.iterator();
                            while (true) {
                                if (it2.hasNext()) {
                                    if (!it2.next().m7624()) {
                                        c4900M8158.mo8165().f14447.m8036("Property filter with no ID. Audience definition ignored. appId, audienceId", C4794.m8038(str), Integer.valueOf(i5));
                                        break;
                                    }
                                } else {
                                    Iterator<C4586> it3 = c4584.zzf.iterator();
                                    while (true) {
                                        if (!it3.hasNext()) {
                                            z = true;
                                            break;
                                        }
                                        if (!c4900M8158.m8333(str, i5, it3.next())) {
                                            z = false;
                                            break;
                                        }
                                    }
                                    if (z) {
                                        Iterator<C4593> it4 = c4584.zze.iterator();
                                        while (true) {
                                            if (!it4.hasNext()) {
                                                break;
                                            }
                                            if (!c4900M8158.m8334(str, i5, it4.next())) {
                                                z = false;
                                                break;
                                            }
                                        }
                                    }
                                    if (z) {
                                        str3 = str8;
                                    } else {
                                        c4900M8158.m8155();
                                        c4900M8158.mo8008();
                                        C0567.m1926(str);
                                        SQLiteDatabase sQLiteDatabaseM83543 = c4900M8158.m8354();
                                        str3 = str8;
                                        sQLiteDatabaseM83543.delete("property_filters", str3, new String[]{str, String.valueOf(i5)});
                                        sQLiteDatabaseM83543.delete("event_filters", str3, new String[]{str, String.valueOf(i5)});
                                    }
                                    str8 = str3;
                                }
                            }
                        }
                    }
                } else {
                    c4900M8158.mo8165().f14447.m8035("Audience with no ID. appId", C4794.m8038(str));
                }
            }
            ArrayList arrayList2 = new ArrayList();
            for (C4584 c45842 : arrayList) {
                arrayList2.add((c45842.zzc & 1) != 0 ? Integer.valueOf(c45842.zzd) : null);
            }
            c4900M8158.m8336(str, arrayList2);
            sQLiteDatabaseM8354.setTransactionSuccessful();
            try {
                if (c46034.f13775) {
                    c46034.m7368();
                    c46034.f13775 = false;
                }
                C4602.m7632((C4602) c46034.f13774);
                bArrM7406 = ((C4602) ((AbstractC4421) c46034.m7370())).m7406();
            } catch (RuntimeException e) {
                mo8165().f14447.m8036("Unable to serialize reduced-size config. Storing full config instead. appId", C4794.m8038(str), e);
                bArrM7406 = bArr;
            }
            C4900 c4900M81582 = m8158();
            C0567.m1926(str);
            c4900M81582.mo8008();
            c4900M81582.m8155();
            new ContentValues().put("remote_config", bArrM7406);
            try {
                if (c4900M81582.m8354().update("apps", r4, "app_id = ?", new String[]{str}) == 0) {
                    c4900M81582.mo8165().f14444.m8035("Failed to update remote config (got 0). appId", C4794.m8038(str));
                }
            } catch (SQLiteException e2) {
                c4900M81582.mo8165().f14444.m8036("Error storing remote config. appId", C4794.m8038(str), e2);
            }
            this.f14489.put(str, (C4602) ((AbstractC4421) c46034.m7370()));
            return true;
        } finally {
            sQLiteDatabaseM8354.endTransaction();
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final boolean m8074(String str) throws Throwable {
        mo8008();
        C4602 c4602M8070 = m8070(str);
        if (c4602M8070 == null) {
            return false;
        }
        return c4602M8070.zzk;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final boolean m8075(String str, String str2) throws Throwable {
        Boolean bool;
        mo8008();
        m8081(str);
        if ("1".equals(mo8069(str, "measurement.upload.blacklist_internal")) && C4887.m8234(str2)) {
            return true;
        }
        if ("1".equals(mo8069(str, "measurement.upload.blacklist_public")) && C4887.m8233(str2)) {
            return true;
        }
        Map<String, Boolean> map = this.f14487.get(str);
        if (map == null || (bool = map.get(str2)) == null) {
            return false;
        }
        return bool.booleanValue();
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final long m8076(String str) throws Throwable {
        String strMo8069 = mo8069(str, "measurement.account.time_zone_offset_minutes");
        if (TextUtils.isEmpty(strMo8069)) {
            return 0L;
        }
        try {
            return Long.parseLong(strMo8069);
        } catch (NumberFormatException e) {
            mo8165().f14447.m8036("Unable to parse timezone offset. appId", C4794.m8038(str), e);
            return 0L;
        }
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final boolean m8077(String str, String str2) throws Throwable {
        Boolean bool;
        mo8008();
        m8081(str);
        if ("ecommerce_purchase".equals(str2)) {
            return true;
        }
        if (C4606.m7638() && this.f14588.f15015.m8177(C4915.f14917) && ("purchase".equals(str2) || "refund".equals(str2))) {
            return true;
        }
        Map<String, Boolean> map = this.f14488.get(str);
        if (map == null || (bool = map.get(str2)) == null) {
            return false;
        }
        return bool.booleanValue();
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final int m8078(String str, String str2) throws Throwable {
        Integer num;
        mo8008();
        m8081(str);
        Map<String, Integer> map = this.f14490.get(str);
        if (map == null || (num = map.get(str2)) == null) {
            return 1;
        }
        return num.intValue();
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final boolean m8079(String str) {
        return "1".equals(mo8069(str, "measurement.upload.blacklist_internal"));
    }

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final boolean m8080(String str) {
        return "1".equals(mo8069(str, "measurement.upload.blacklist_public"));
    }

    /* JADX WARN: Not initialized variable reg: 2, insn: 0x00d2: MOVE (r1 I:??[OBJECT, ARRAY]) = (r2 I:??[OBJECT, ARRAY]), block:B:30:0x00d2 */
    /* JADX WARN: Removed duplicated region for block: B:26:0x0081  */
    /* JADX WARN: Removed duplicated region for block: B:28:0x00a0  */
    /* JADX WARN: Removed duplicated region for block: B:32:0x00d5  */
    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void m8081(String str) throws Throwable {
        SQLiteException e;
        Cursor cursorQuery;
        Cursor cursor;
        byte[] blob;
        m8155();
        mo8008();
        C0567.m1926(str);
        if (this.f14489.get(str) != null) {
            return;
        }
        C4900 c4900M8158 = m8158();
        Cursor cursor2 = null;
        if (c4900M8158 == null) {
            throw null;
        }
        C0567.m1926(str);
        c4900M8158.mo8008();
        c4900M8158.m8155();
        try {
            try {
                cursorQuery = c4900M8158.m8354().query("apps", new String[]{"remote_config"}, "app_id=?", new String[]{str}, null, null, null);
                try {
                } catch (SQLiteException e2) {
                    e = e2;
                    c4900M8158.mo8165().f14444.m8036("Error querying remote config. appId", C4794.m8038(str), e);
                    if (cursorQuery != null) {
                        cursorQuery.close();
                    }
                }
            } catch (Throwable th) {
                th = th;
                cursor2 = cursor;
                if (cursor2 != null) {
                    cursor2.close();
                }
                throw th;
            }
        } catch (SQLiteException e3) {
            e = e3;
            cursorQuery = null;
        } catch (Throwable th2) {
            th = th2;
            if (cursor2 != null) {
            }
            throw th;
        }
        if (cursorQuery.moveToFirst()) {
            blob = cursorQuery.getBlob(0);
            if (cursorQuery.moveToNext()) {
                c4900M8158.mo8165().f14444.m8035("Got multiple records for app config, expected one. appId", C4794.m8038(str));
            }
            cursorQuery.close();
            if (blob == null) {
                C4602.C4603 c4603M7363 = m8071(str, blob).m7363();
                m8072(str, c4603M7363);
                this.f14486.put(str, m8068((C4602) ((AbstractC4421) c4603M7363.m7370())));
                this.f14489.put(str, (C4602) ((AbstractC4421) c4603M7363.m7370()));
                this.f14491.put(str, null);
                return;
            }
            this.f14486.put(str, null);
            this.f14487.put(str, null);
            this.f14488.put(str, null);
            this.f14489.put(str, null);
            this.f14491.put(str, null);
            this.f14490.put(str, null);
            return;
        }
        cursorQuery.close();
        blob = null;
        if (blob == null) {
        }
    }

    @Override // p138.p176.p177.p242.p265.p266.AbstractC4843
    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public final boolean mo8082() {
        return false;
    }
}
