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.os.Parcelable;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Pair;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import p000.p001.p002.p003.p004.C0567;
import p037.p057.C1714;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p253.C4312;
import p138.p176.p177.p242.p258.p263.AbstractC4421;
import p138.p176.p177.p242.p258.p263.C4473;
import p138.p176.p177.p242.p258.p263.C4538;
import p138.p176.p177.p242.p258.p263.C4586;
import p138.p176.p177.p242.p258.p263.C4593;
import p138.p176.p177.p242.p258.p263.C4634;
import p138.p176.p177.p242.p258.p263.C4638;
import p138.p176.p177.p242.p258.p263.C4642;

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

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public static final String[] f14774 = {"last_bundled_timestamp", "ALTER TABLE events ADD COLUMN last_bundled_timestamp INTEGER;", "last_bundled_day", "ALTER TABLE events ADD COLUMN last_bundled_day INTEGER;", "last_sampled_complex_event_id", "ALTER TABLE events ADD COLUMN last_sampled_complex_event_id INTEGER;", "last_sampling_rate", "ALTER TABLE events ADD COLUMN last_sampling_rate INTEGER;", "last_exempt_from_sampling", "ALTER TABLE events ADD COLUMN last_exempt_from_sampling INTEGER;", "current_session_count", "ALTER TABLE events ADD COLUMN current_session_count INTEGER;"};

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public static final String[] f14775 = {"origin", "ALTER TABLE user_attributes ADD COLUMN origin TEXT;"};

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public static final String[] f14776 = {"app_version", "ALTER TABLE apps ADD COLUMN app_version TEXT;", "app_store", "ALTER TABLE apps ADD COLUMN app_store TEXT;", "gmp_version", "ALTER TABLE apps ADD COLUMN gmp_version INTEGER;", "dev_cert_hash", "ALTER TABLE apps ADD COLUMN dev_cert_hash INTEGER;", "measurement_enabled", "ALTER TABLE apps ADD COLUMN measurement_enabled INTEGER;", "last_bundle_start_timestamp", "ALTER TABLE apps ADD COLUMN last_bundle_start_timestamp INTEGER;", "day", "ALTER TABLE apps ADD COLUMN day INTEGER;", "daily_public_events_count", "ALTER TABLE apps ADD COLUMN daily_public_events_count INTEGER;", "daily_events_count", "ALTER TABLE apps ADD COLUMN daily_events_count INTEGER;", "daily_conversions_count", "ALTER TABLE apps ADD COLUMN daily_conversions_count INTEGER;", "remote_config", "ALTER TABLE apps ADD COLUMN remote_config BLOB;", "config_fetched_time", "ALTER TABLE apps ADD COLUMN config_fetched_time INTEGER;", "failed_config_fetch_time", "ALTER TABLE apps ADD COLUMN failed_config_fetch_time INTEGER;", "app_version_int", "ALTER TABLE apps ADD COLUMN app_version_int INTEGER;", "firebase_instance_id", "ALTER TABLE apps ADD COLUMN firebase_instance_id TEXT;", "daily_error_events_count", "ALTER TABLE apps ADD COLUMN daily_error_events_count INTEGER;", "daily_realtime_events_count", "ALTER TABLE apps ADD COLUMN daily_realtime_events_count INTEGER;", "health_monitor_sample", "ALTER TABLE apps ADD COLUMN health_monitor_sample TEXT;", "android_id", "ALTER TABLE apps ADD COLUMN android_id INTEGER;", "adid_reporting_enabled", "ALTER TABLE apps ADD COLUMN adid_reporting_enabled INTEGER;", "ssaid_reporting_enabled", "ALTER TABLE apps ADD COLUMN ssaid_reporting_enabled INTEGER;", "admob_app_id", "ALTER TABLE apps ADD COLUMN admob_app_id TEXT;", "linked_admob_app_id", "ALTER TABLE apps ADD COLUMN linked_admob_app_id TEXT;", "dynamite_version", "ALTER TABLE apps ADD COLUMN dynamite_version INTEGER;", "safelisted_events", "ALTER TABLE apps ADD COLUMN safelisted_events TEXT;", "ga_app_id", "ALTER TABLE apps ADD COLUMN ga_app_id TEXT;"};

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public static final String[] f14777 = {"realtime", "ALTER TABLE raw_events ADD COLUMN realtime INTEGER;"};

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public static final String[] f14778 = {"has_realtime", "ALTER TABLE queue ADD COLUMN has_realtime INTEGER;", "retry_count", "ALTER TABLE queue ADD COLUMN retry_count INTEGER;"};

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public static final String[] f14779 = {"session_scoped", "ALTER TABLE event_filters ADD COLUMN session_scoped BOOLEAN;"};

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public static final String[] f14780 = {"session_scoped", "ALTER TABLE property_filters ADD COLUMN session_scoped BOOLEAN;"};

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public static final String[] f14781 = {"previous_install_count", "ALTER TABLE app2 ADD COLUMN previous_install_count INTEGER;"};

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final C4903 f14782;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final C4862 f14783;

    public C4900(C4889 c4889) {
        super(c4889);
        this.f14783 = new C4862(this.f14588.f15022);
        this.f14782 = new C4903(this, this.f14588.f15009, "google_app_measurement.db");
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static void m8318(ContentValues contentValues, String str, Object obj) {
        C0567.m1926(str);
        C0567.m1910(obj);
        if (obj instanceof String) {
            contentValues.put(str, (String) obj);
        } else if (obj instanceof Long) {
            contentValues.put(str, (Long) obj);
        } else {
            if (!(obj instanceof Double)) {
                throw new IllegalArgumentException("Invalid value type");
            }
            contentValues.put(str, (Double) obj);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final long m8319(String str, String[] strArr, long j) {
        Cursor cursorRawQuery = null;
        try {
            try {
                cursorRawQuery = m8354().rawQuery(str, strArr);
                if (!cursorRawQuery.moveToFirst()) {
                    cursorRawQuery.close();
                    return j;
                }
                long j2 = cursorRawQuery.getLong(0);
                cursorRawQuery.close();
                return j2;
            } catch (SQLiteException e) {
                mo8165().f14444.m8036("Database error", str, e);
                throw e;
            }
        } catch (Throwable th) {
            if (cursorRawQuery != null) {
                cursorRawQuery.close();
            }
            throw th;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final long m8320(C4642 c4642) {
        mo8008();
        m8155();
        C0567.m1910(c4642);
        C0567.m1926(c4642.zzs);
        byte[] bArrM7406 = c4642.m7406();
        long jM8129 = m8157().m8129(bArrM7406);
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", c4642.zzs);
        contentValues.put("metadata_fingerprint", Long.valueOf(jM8129));
        contentValues.put("metadata", bArrM7406);
        try {
            m8354().insertWithOnConflict("raw_events_metadata", null, contentValues, 4);
            return jM8129;
        } catch (SQLiteException e) {
            mo8165().f14444.m8036("Error storing raw event metadata. appId", C4794.m8038(c4642.zzs), e);
            throw e;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final Object m8321(Cursor cursor, int i) {
        int type = cursor.getType(i);
        if (type == 0) {
            mo8165().f14444.m8034("Loaded invalid null value from database");
            return null;
        }
        if (type == 1) {
            return Long.valueOf(cursor.getLong(i));
        }
        if (type == 2) {
            return Double.valueOf(cursor.getDouble(i));
        }
        if (type == 3) {
            return cursor.getString(i);
        }
        if (type != 4) {
            mo8165().f14444.m8035("Loaded invalid unknown value type, ignoring it", Integer.valueOf(type));
            return null;
        }
        mo8165().f14444.m8034("Loaded invalid blob type value, ignoring it");
        return null;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:25:0x0053  */
    /* JADX WARN: Type inference failed for: r0v0 */
    /* JADX WARN: Type inference failed for: r0v1, types: [android.database.Cursor] */
    /* JADX WARN: Type inference failed for: r0v2 */
    /* JADX WARN: Type inference failed for: r5v0, types: [long] */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final String m8322(long j) throws Throwable {
        Cursor cursorRawQuery;
        mo8008();
        m8155();
        ?? r0 = 0;
        try {
            try {
                cursorRawQuery = m8354().rawQuery("select app_id from apps where app_id in (select distinct app_id from raw_events) and config_fetched_time < ? order by failed_config_fetch_time limit 1;", new String[]{String.valueOf((long) j)});
                try {
                    if (cursorRawQuery.moveToFirst()) {
                        String string = cursorRawQuery.getString(0);
                        cursorRawQuery.close();
                        return string;
                    }
                    mo8165().f14452.m8034("No expired configs for apps with pending events");
                    cursorRawQuery.close();
                    return null;
                } catch (SQLiteException e) {
                    e = e;
                    mo8165().f14444.m8035("Error selecting expired configs", e);
                    if (cursorRawQuery != null) {
                        cursorRawQuery.close();
                    }
                    return null;
                }
            } catch (Throwable th) {
                th = th;
                r0 = j;
                if (r0 != 0) {
                    r0.close();
                }
                throw th;
            }
        } catch (SQLiteException e2) {
            e = e2;
            cursorRawQuery = null;
        } catch (Throwable th2) {
            th = th2;
            if (r0 != 0) {
            }
            throw th;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final List<C5036> m8323(String str) throws Throwable {
        Cursor cursorQuery;
        C0567.m1926(str);
        mo8008();
        m8155();
        ArrayList arrayList = new ArrayList();
        Cursor cursor = null;
        try {
            cursorQuery = m8354().query("user_attributes", new String[]{"name", "origin", "set_timestamp", "value"}, "app_id=?", new String[]{str}, null, null, "rowid", "1000");
            try {
                try {
                    if (!cursorQuery.moveToFirst()) {
                        cursorQuery.close();
                        return arrayList;
                    }
                    do {
                        String string = cursorQuery.getString(0);
                        String string2 = cursorQuery.getString(1);
                        if (string2 == null) {
                            string2 = "";
                        }
                        String str2 = string2;
                        long j = cursorQuery.getLong(2);
                        Object objM8321 = m8321(cursorQuery, 3);
                        if (objM8321 == null) {
                            mo8165().f14444.m8035("Read invalid user property value, ignoring it. appId", C4794.m8038(str));
                        } else {
                            arrayList.add(new C5036(str, str2, string, j, objM8321));
                        }
                    } while (cursorQuery.moveToNext());
                    cursorQuery.close();
                    return arrayList;
                } catch (SQLiteException e) {
                    e = e;
                    mo8165().f14444.m8036("Error querying user properties. appId", C4794.m8038(str), e);
                    if (cursorQuery != null) {
                        cursorQuery.close();
                    }
                    return null;
                }
            } catch (Throwable th) {
                th = th;
                cursor = cursorQuery;
            }
            th = th;
            cursor = cursorQuery;
        } catch (SQLiteException e2) {
            e = e2;
            cursorQuery = null;
        } catch (Throwable th2) {
            th = th2;
        }
        if (cursor != null) {
            cursor.close();
        }
        throw th;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final List<Pair<C4642, Long>> m8324(String str, int i, int i2) {
        byte[] bArrM8142;
        mo8008();
        m8155();
        C0567.m1920(i > 0);
        C0567.m1920(i2 > 0);
        C0567.m1926(str);
        Cursor cursor = null;
        try {
            try {
                Cursor cursorQuery = m8354().query("queue", new String[]{"rowid", "data", "retry_count"}, "app_id=?", new String[]{str}, null, null, "rowid", String.valueOf(i));
                if (!cursorQuery.moveToFirst()) {
                    List<Pair<C4642, Long>> listEmptyList = Collections.emptyList();
                    cursorQuery.close();
                    return listEmptyList;
                }
                ArrayList arrayList = new ArrayList();
                int length = 0;
                do {
                    long j = cursorQuery.getLong(0);
                    try {
                        bArrM8142 = m8157().m8142(cursorQuery.getBlob(1));
                    } catch (IOException e) {
                        mo8165().f14444.m8036("Failed to unzip queued bundle. appId", C4794.m8038(str), e);
                    }
                    if (!arrayList.isEmpty() && bArrM8142.length + length > i2) {
                        break;
                    }
                    try {
                        C4642.C4643 c4643 = (C4642.C4643) C4833.m8121(C4642.m7713(), bArrM8142);
                        if (!cursorQuery.isNull(2)) {
                            c4643.m7752(cursorQuery.getInt(2));
                        }
                        length += bArrM8142.length;
                        arrayList.add(Pair.create((C4642) ((AbstractC4421) c4643.m7370()), Long.valueOf(j)));
                    } catch (IOException e2) {
                        mo8165().f14444.m8036("Failed to merge queued bundle. appId", C4794.m8038(str), e2);
                    }
                    if (!cursorQuery.moveToNext()) {
                        break;
                    }
                } while (length <= i2);
                cursorQuery.close();
                return arrayList;
            } catch (SQLiteException e3) {
                mo8165().f14444.m8036("Error querying bundles. appId", C4794.m8038(str), e3);
                List<Pair<C4642, Long>> listEmptyList2 = Collections.emptyList();
                if (0 != 0) {
                    cursor.close();
                }
                return listEmptyList2;
            }
        } catch (Throwable th) {
            if (0 != 0) {
                cursor.close();
            }
            throw th;
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:20:0x008e, code lost:
    
        mo8165().f14444.m8035("Read more than the max allowed user properties, ignoring excess", 1000);
     */
    /* JADX WARN: Removed duplicated region for block: B:52:0x0115  */
    /* JADX WARN: Removed duplicated region for block: B:57:0x011d  */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final List<C5036> m8325(String str, String str2, String str3) throws Throwable {
        String str4;
        Cursor cursorQuery;
        C0567.m1926(str);
        mo8008();
        m8155();
        ArrayList arrayList = new ArrayList();
        Cursor cursor = null;
        try {
            try {
                ArrayList arrayList2 = new ArrayList(3);
                try {
                    arrayList2.add(str);
                    StringBuilder sb = new StringBuilder("app_id=?");
                    if (TextUtils.isEmpty(str2)) {
                        str4 = str2;
                    } else {
                        str4 = str2;
                        try {
                            arrayList2.add(str4);
                            sb.append(" and origin=?");
                        } catch (SQLiteException e) {
                            e = e;
                            cursorQuery = null;
                        }
                    }
                    if (!TextUtils.isEmpty(str3)) {
                        arrayList2.add(String.valueOf(str3).concat("*"));
                        sb.append(" and name glob ?");
                    }
                    cursorQuery = m8354().query("user_attributes", new String[]{"name", "set_timestamp", "value", "origin"}, sb.toString(), (String[]) arrayList2.toArray(new String[arrayList2.size()]), null, null, "rowid", "1001");
                } catch (SQLiteException e2) {
                    e = e2;
                    str4 = str2;
                    cursorQuery = null;
                    mo8165().f14444.m8037("(2)Error querying user properties", C4794.m8038(str), str4, e);
                    if (cursorQuery != null) {
                    }
                    return null;
                }
            } catch (Throwable th) {
                th = th;
                if (cursor != null) {
                    cursor.close();
                }
                throw th;
            }
            try {
                if (!cursorQuery.moveToFirst()) {
                    cursorQuery.close();
                    return arrayList;
                }
                while (true) {
                    if (arrayList.size() >= 1000) {
                        break;
                    }
                    String string = cursorQuery.getString(0);
                    long j = cursorQuery.getLong(1);
                    try {
                        try {
                            Object objM8321 = m8321(cursorQuery, 2);
                            String string2 = cursorQuery.getString(3);
                            if (objM8321 == null) {
                                try {
                                    mo8165().f14444.m8037("(2)Read invalid user property value, ignoring it", C4794.m8038(str), string2, str3);
                                } catch (SQLiteException e3) {
                                    e = e3;
                                    str4 = string2;
                                }
                            } else {
                                arrayList.add(new C5036(str, string2, string, j, objM8321));
                            }
                            if (!cursorQuery.moveToNext()) {
                                break;
                            }
                            str4 = string2;
                        } catch (SQLiteException e4) {
                            e = e4;
                        }
                    } catch (Throwable th2) {
                        th = th2;
                        cursor = cursorQuery;
                        if (cursor != null) {
                        }
                        throw th;
                    }
                }
                cursorQuery.close();
                return arrayList;
            } catch (SQLiteException e5) {
                e = e5;
            } catch (Throwable th3) {
                th = th3;
                cursor = cursorQuery;
                if (cursor != null) {
                }
                throw th;
            }
        } catch (SQLiteException e6) {
            e = e6;
        }
        mo8165().f14444.m8037("(2)Error querying user properties", C4794.m8038(str), str4, e);
        if (cursorQuery != null) {
            cursorQuery.close();
        }
        return null;
    }

    /* JADX WARN: Code restructure failed: missing block: B:9:0x0050, code lost:
    
        mo8165().f14444.m8035("Read more than the max allowed conditional properties, ignoring extra", 1000);
     */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final List<C4891> m8326(String str, String[] strArr) {
        mo8008();
        m8155();
        ArrayList arrayList = new ArrayList();
        Cursor cursorQuery = null;
        try {
            try {
                cursorQuery = m8354().query("conditional_properties", new String[]{"app_id", "origin", "name", "value", "active", "trigger_event_name", "trigger_timeout", "timed_out_event", "creation_timestamp", "triggered_event", "triggered_timestamp", "time_to_live", "expired_event"}, str, strArr, null, null, "rowid", "1001");
                if (!cursorQuery.moveToFirst()) {
                    cursorQuery.close();
                    return arrayList;
                }
                while (true) {
                    if (arrayList.size() >= 1000) {
                        break;
                    }
                    String string = cursorQuery.getString(0);
                    String string2 = cursorQuery.getString(1);
                    String string3 = cursorQuery.getString(2);
                    Object objM8321 = m8321(cursorQuery, 3);
                    boolean z = cursorQuery.getInt(4) != 0;
                    String string4 = cursorQuery.getString(5);
                    long j = cursorQuery.getLong(6);
                    C4913 c4913 = (C4913) m8157().m8130(cursorQuery.getBlob(7), C4913.CREATOR);
                    arrayList.add(new C4891(string, string2, new C4999(string3, cursorQuery.getLong(10), objM8321, string2), cursorQuery.getLong(8), z, string4, c4913, j, (C4913) m8157().m8130(cursorQuery.getBlob(9), C4913.CREATOR), cursorQuery.getLong(11), (C4913) m8157().m8130(cursorQuery.getBlob(12), C4913.CREATOR)));
                    if (!cursorQuery.moveToNext()) {
                        break;
                    }
                }
                cursorQuery.close();
                return arrayList;
            } catch (SQLiteException e) {
                mo8165().f14444.m8035("Error querying conditional user property value", e);
                List<C4891> listEmptyList = Collections.emptyList();
                if (cursorQuery != null) {
                    cursorQuery.close();
                }
                return listEmptyList;
            }
        } catch (Throwable th) {
            if (cursorQuery != null) {
                cursorQuery.close();
            }
            throw th;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C4902 m8327(long j, String str, long j2, boolean z, boolean z2, boolean z3, boolean z4, boolean z5) {
        C0567.m1926(str);
        mo8008();
        m8155();
        String[] strArr = {str};
        C4902 c4902 = new C4902();
        Cursor cursor = null;
        try {
            try {
                SQLiteDatabase sQLiteDatabaseM8354 = m8354();
                Cursor cursorQuery = sQLiteDatabaseM8354.query("apps", new String[]{"day", "daily_events_count", "daily_public_events_count", "daily_conversions_count", "daily_error_events_count", "daily_realtime_events_count"}, "app_id=?", new String[]{str}, null, null, null);
                if (!cursorQuery.moveToFirst()) {
                    mo8165().f14447.m8035("Not updating daily counts, app is not known. appId", C4794.m8038(str));
                    cursorQuery.close();
                    return c4902;
                }
                if (cursorQuery.getLong(0) == j) {
                    c4902.f14785 = cursorQuery.getLong(1);
                    c4902.f14784 = cursorQuery.getLong(2);
                    c4902.f14786 = cursorQuery.getLong(3);
                    c4902.f14787 = cursorQuery.getLong(4);
                    c4902.f14788 = cursorQuery.getLong(5);
                }
                if (z) {
                    c4902.f14785 += j2;
                }
                if (z2) {
                    c4902.f14784 += j2;
                }
                if (z3) {
                    c4902.f14786 += j2;
                }
                if (z4) {
                    c4902.f14787 += j2;
                }
                if (z5) {
                    c4902.f14788 += j2;
                }
                ContentValues contentValues = new ContentValues();
                contentValues.put("day", Long.valueOf(j));
                contentValues.put("daily_public_events_count", Long.valueOf(c4902.f14784));
                contentValues.put("daily_events_count", Long.valueOf(c4902.f14785));
                contentValues.put("daily_conversions_count", Long.valueOf(c4902.f14786));
                contentValues.put("daily_error_events_count", Long.valueOf(c4902.f14787));
                contentValues.put("daily_realtime_events_count", Long.valueOf(c4902.f14788));
                sQLiteDatabaseM8354.update("apps", contentValues, "app_id=?", strArr);
                cursorQuery.close();
                return c4902;
            } catch (SQLiteException e) {
                mo8165().f14444.m8036("Error updating daily counts. appId", C4794.m8038(str), e);
                if (0 != 0) {
                    cursor.close();
                }
                return c4902;
            }
        } catch (Throwable th) {
            if (0 != 0) {
                cursor.close();
            }
            throw th;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C4902 m8328(long j, String str, boolean z, boolean z2) {
        return m8327(j, str, 1L, false, false, z, false, z2);
    }

    /* JADX WARN: Not initialized variable reg: 14, insn: 0x0143: MOVE (r18 I:??[OBJECT, ARRAY]) = (r14 I:??[OBJECT, ARRAY]), block:B:64:0x0143 */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C4909 m8329(String str, String str2) throws Throwable {
        Cursor cursorQuery;
        Cursor cursor;
        Cursor cursor2;
        Boolean boolValueOf;
        C0567.m1926(str);
        C0567.m1926(str2);
        mo8008();
        m8155();
        Cursor cursor3 = null;
        try {
            try {
                cursorQuery = m8354().query("events", (String[]) new ArrayList(Arrays.asList("lifetime_count", "current_bundle_count", "last_fire_timestamp", "last_bundled_timestamp", "last_bundled_day", "last_sampled_complex_event_id", "last_sampling_rate", "last_exempt_from_sampling", "current_session_count")).toArray(new String[0]), "app_id=? and name=?", new String[]{str, str2}, null, null, null);
                try {
                    if (!cursorQuery.moveToFirst()) {
                        cursorQuery.close();
                        return null;
                    }
                    long j = cursorQuery.getLong(0);
                    long j2 = cursorQuery.getLong(1);
                    long j3 = cursorQuery.getLong(2);
                    long j4 = cursorQuery.isNull(3) ? 0L : cursorQuery.getLong(3);
                    Long lValueOf = cursorQuery.isNull(4) ? null : Long.valueOf(cursorQuery.getLong(4));
                    Long lValueOf2 = cursorQuery.isNull(5) ? null : Long.valueOf(cursorQuery.getLong(5));
                    Long lValueOf3 = cursorQuery.isNull(6) ? null : Long.valueOf(cursorQuery.getLong(6));
                    if (cursorQuery.isNull(7)) {
                        boolValueOf = null;
                    } else {
                        try {
                            boolValueOf = Boolean.valueOf(cursorQuery.getLong(7) == 1);
                        } catch (SQLiteException e) {
                            e = e;
                        }
                    }
                    cursor2 = cursorQuery;
                    try {
                        C4909 c4909 = new C4909(str, str2, j, j2, cursorQuery.isNull(8) ? 0L : cursorQuery.getLong(8), j3, j4, lValueOf, lValueOf2, lValueOf3, boolValueOf);
                        if (cursor2.moveToNext()) {
                            mo8165().f14444.m8035("Got multiple records for event aggregates, expected one. appId", C4794.m8038(str));
                        }
                        cursor2.close();
                        return c4909;
                    } catch (SQLiteException e2) {
                        e = e2;
                        cursorQuery = cursor2;
                    } catch (Throwable th) {
                        th = th;
                        cursor3 = cursor2;
                        if (cursor3 != null) {
                            cursor3.close();
                        }
                        throw th;
                    }
                } catch (SQLiteException e3) {
                    e = e3;
                } catch (Throwable th2) {
                    th = th2;
                    cursor2 = cursorQuery;
                }
            } catch (Throwable th3) {
                th = th3;
                cursor3 = cursor;
            }
        } catch (SQLiteException e4) {
            e = e4;
            cursorQuery = null;
        } catch (Throwable th4) {
            th = th4;
        }
        mo8165().f14444.m8037("Error querying events. appId", C4794.m8038(str), m8161().m8110(str2), e);
        if (cursorQuery != null) {
            cursorQuery.close();
        }
        return null;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m8330(List<Long> list) {
        mo8008();
        m8155();
        C0567.m1910(list);
        if (list.size() == 0) {
            throw new IllegalArgumentException("Given Integer is zero");
        }
        if (m8357()) {
            String strJoin = TextUtils.join(",", list);
            StringBuilder sb = new StringBuilder(C2803.m4895(strJoin, 2));
            sb.append("(");
            sb.append(strJoin);
            sb.append(")");
            String string = sb.toString();
            StringBuilder sb2 = new StringBuilder(C2803.m4895(string, 80));
            sb2.append("SELECT COUNT(1) FROM queue WHERE rowid IN ");
            sb2.append(string);
            sb2.append(" AND retry_count =  2147483647 LIMIT 1");
            if (m8341(sb2.toString(), (String[]) null) > 0) {
                mo8165().f14447.m8034("The number of upload retries exceeds the limit. Will remain unchanged.");
            }
            try {
                SQLiteDatabase sQLiteDatabaseM8354 = m8354();
                StringBuilder sb3 = new StringBuilder(String.valueOf(string).length() + 127);
                sb3.append("UPDATE queue SET retry_count = IFNULL(retry_count, 0) + 1 WHERE rowid IN ");
                sb3.append(string);
                sb3.append(" AND (retry_count IS NULL OR retry_count < 2147483647)");
                sQLiteDatabaseM8354.execSQL(sb3.toString());
            } catch (SQLiteException e) {
                mo8165().f14444.m8035("Error incrementing retry count. error", e);
            }
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m8331(C4755 c4755) {
        C0567.m1910(c4755);
        mo8008();
        m8155();
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", c4755.m7939());
        contentValues.put("app_instance_id", c4755.m7942());
        contentValues.put("gmp_app_id", c4755.m7945());
        contentValues.put("resettable_device_id_hash", c4755.m7951());
        contentValues.put("last_bundle_index", Long.valueOf(c4755.m7962()));
        contentValues.put("last_bundle_start_timestamp", Long.valueOf(c4755.m7953()));
        contentValues.put("last_bundle_end_timestamp", Long.valueOf(c4755.m7954()));
        contentValues.put("app_version", c4755.m7955());
        contentValues.put("app_store", c4755.m7957());
        contentValues.put("gmp_version", Long.valueOf(c4755.m7958()));
        contentValues.put("dev_cert_hash", Long.valueOf(c4755.m7959()));
        contentValues.put("measurement_enabled", Boolean.valueOf(c4755.m7961()));
        c4755.f14289.mo8163().mo8008();
        contentValues.put("day", Long.valueOf(c4755.f14312));
        c4755.f14289.mo8163().mo8008();
        contentValues.put("daily_public_events_count", Long.valueOf(c4755.f14313));
        c4755.f14289.mo8163().mo8008();
        contentValues.put("daily_events_count", Long.valueOf(c4755.f14314));
        c4755.f14289.mo8163().mo8008();
        contentValues.put("daily_conversions_count", Long.valueOf(c4755.f14315));
        c4755.f14289.mo8163().mo8008();
        contentValues.put("config_fetched_time", Long.valueOf(c4755.f14320));
        c4755.f14289.mo8163().mo8008();
        contentValues.put("failed_config_fetch_time", Long.valueOf(c4755.f14321));
        contentValues.put("app_version_int", Long.valueOf(c4755.m7956()));
        contentValues.put("firebase_instance_id", c4755.m7952());
        c4755.f14289.mo8163().mo8008();
        contentValues.put("daily_error_events_count", Long.valueOf(c4755.f14316));
        c4755.f14289.mo8163().mo8008();
        contentValues.put("daily_realtime_events_count", Long.valueOf(c4755.f14317));
        c4755.f14289.mo8163().mo8008();
        contentValues.put("health_monitor_sample", c4755.f14318);
        contentValues.put("android_id", Long.valueOf(c4755.m7922()));
        contentValues.put("adid_reporting_enabled", Boolean.valueOf(c4755.m7929()));
        contentValues.put("ssaid_reporting_enabled", Boolean.valueOf(c4755.m7932()));
        contentValues.put("admob_app_id", c4755.m7948());
        contentValues.put("dynamite_version", Long.valueOf(c4755.m7960()));
        if (c4755.m7936() != null) {
            if (c4755.m7936().size() == 0) {
                mo8165().f14447.m8035("Safelisted events should not be an empty list. appId", c4755.m7939());
            } else {
                contentValues.put("safelisted_events", TextUtils.join(",", c4755.m7936()));
            }
        }
        if (C4538.m7580() && this.f14588.f15015.m8183(c4755.m7939(), C4915.f14896)) {
            contentValues.put("ga_app_id", c4755.m7950());
        }
        try {
            SQLiteDatabase sQLiteDatabaseM8354 = m8354();
            if (sQLiteDatabaseM8354.update("apps", contentValues, "app_id = ?", new String[]{c4755.m7939()}) == 0 && sQLiteDatabaseM8354.insertWithOnConflict("apps", null, contentValues, 5) == -1) {
                mo8165().f14444.m8035("Failed to insert/update app (got -1). appId", C4794.m8038(c4755.m7939()));
            }
        } catch (SQLiteException e) {
            mo8165().f14444.m8036("Error storing app. appId", C4794.m8038(c4755.m7939()), e);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m8332(C4909 c4909) {
        C0567.m1910(c4909);
        mo8008();
        m8155();
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", c4909.f14809);
        contentValues.put("name", c4909.f14810);
        contentValues.put("lifetime_count", Long.valueOf(c4909.f14811));
        contentValues.put("current_bundle_count", Long.valueOf(c4909.f14812));
        contentValues.put("last_fire_timestamp", Long.valueOf(c4909.f14814));
        contentValues.put("last_bundled_timestamp", Long.valueOf(c4909.f14815));
        contentValues.put("last_bundled_day", c4909.f14816);
        contentValues.put("last_sampled_complex_event_id", c4909.f14817);
        contentValues.put("last_sampling_rate", c4909.f14818);
        contentValues.put("current_session_count", Long.valueOf(c4909.f14813));
        Boolean bool = c4909.f14819;
        contentValues.put("last_exempt_from_sampling", (bool == null || !bool.booleanValue()) ? null : 1L);
        try {
            if (m8354().insertWithOnConflict("events", null, contentValues, 5) == -1) {
                mo8165().f14444.m8035("Failed to insert/update event aggregates (got -1). appId", C4794.m8038(c4909.f14809));
            }
        } catch (SQLiteException e) {
            mo8165().f14444.m8036("Error storing event aggregates. appId", C4794.m8038(c4909.f14809), e);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final boolean m8333(String str, int i, C4586 c4586) {
        m8155();
        mo8008();
        C0567.m1926(str);
        C0567.m1910(c4586);
        if (TextUtils.isEmpty(c4586.zze)) {
            mo8165().f14447.m8037("Event filter had no event name. Audience definition ignored. appId, audienceId, filterId", C4794.m8038(str), Integer.valueOf(i), String.valueOf(c4586.m7613() ? Integer.valueOf(c4586.zzd) : null));
            return false;
        }
        byte[] bArrM7406 = c4586.m7406();
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", str);
        contentValues.put("audience_id", Integer.valueOf(i));
        contentValues.put("filter_id", c4586.m7613() ? Integer.valueOf(c4586.zzd) : null);
        contentValues.put("event_name", c4586.zze);
        contentValues.put("session_scoped", (c4586.zzc & 64) != 0 ? Boolean.valueOf(c4586.zzk) : null);
        contentValues.put("data", bArrM7406);
        try {
            if (m8354().insertWithOnConflict("event_filters", null, contentValues, 5) == -1) {
                mo8165().f14444.m8035("Failed to insert event filter (got -1). appId", C4794.m8038(str));
            }
            return true;
        } catch (SQLiteException e) {
            mo8165().f14444.m8036("Error storing event filter. appId", C4794.m8038(str), e);
            return false;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final boolean m8334(String str, int i, C4593 c4593) {
        m8155();
        mo8008();
        C0567.m1926(str);
        C0567.m1910(c4593);
        if (TextUtils.isEmpty(c4593.zze)) {
            mo8165().f14447.m8037("Property filter had no property name. Audience definition ignored. appId, audienceId, filterId", C4794.m8038(str), Integer.valueOf(i), String.valueOf(c4593.m7624() ? Integer.valueOf(c4593.zzd) : null));
            return false;
        }
        byte[] bArrM7406 = c4593.m7406();
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", str);
        contentValues.put("audience_id", Integer.valueOf(i));
        contentValues.put("filter_id", c4593.m7624() ? Integer.valueOf(c4593.zzd) : null);
        contentValues.put("property_name", c4593.zze);
        contentValues.put("session_scoped", (c4593.zzc & 32) != 0 ? Boolean.valueOf(c4593.zzi) : null);
        contentValues.put("data", bArrM7406);
        try {
            if (m8354().insertWithOnConflict("property_filters", null, contentValues, 5) != -1) {
                return true;
            }
            mo8165().f14444.m8035("Failed to insert property filter (got -1). appId", C4794.m8038(str));
            return false;
        } catch (SQLiteException e) {
            mo8165().f14444.m8036("Error storing property filter. appId", C4794.m8038(str), e);
            return false;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final boolean m8335(String str, Long l, long j, C4634 c4634) {
        mo8008();
        m8155();
        C0567.m1910(c4634);
        C0567.m1926(str);
        C0567.m1910(l);
        byte[] bArrM7406 = c4634.m7406();
        mo8165().f14452.m8036("Saving complex main event, appId, data size", m8161().m8110(str), Integer.valueOf(bArrM7406.length));
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", str);
        contentValues.put("event_id", l);
        contentValues.put("children_to_process", Long.valueOf(j));
        contentValues.put("main_event", bArrM7406);
        try {
            if (m8354().insertWithOnConflict("main_event_params", null, contentValues, 5) != -1) {
                return true;
            }
            mo8165().f14444.m8035("Failed to insert complex main event (got -1). appId", C4794.m8038(str));
            return false;
        } catch (SQLiteException e) {
            mo8165().f14444.m8036("Error storing complex main event. appId", C4794.m8038(str), e);
            return false;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final boolean m8336(String str, List<Integer> list) {
        C0567.m1926(str);
        m8155();
        mo8008();
        SQLiteDatabase sQLiteDatabaseM8354 = m8354();
        try {
            long jM8341 = m8341("select count(1) from audience_filter_values where app_id=?", new String[]{str});
            int iMax = Math.max(0, Math.min(2000, this.f14588.f15015.m8179(str, C4915.f14859)));
            if (jM8341 <= iMax) {
                return false;
            }
            ArrayList arrayList = new ArrayList();
            for (int i = 0; i < list.size(); i++) {
                Integer num = list.get(i);
                if (num == null) {
                    return false;
                }
                arrayList.add(Integer.toString(num.intValue()));
            }
            String strJoin = TextUtils.join(",", arrayList);
            StringBuilder sb = new StringBuilder(C2803.m4895(strJoin, 2));
            sb.append("(");
            sb.append(strJoin);
            sb.append(")");
            String string = sb.toString();
            StringBuilder sb2 = new StringBuilder(C2803.m4895(string, 140));
            sb2.append("audience_id in (select audience_id from audience_filter_values where app_id=? and audience_id not in ");
            sb2.append(string);
            sb2.append(" order by rowid desc limit -1 offset ?)");
            return sQLiteDatabaseM8354.delete("audience_filter_values", sb2.toString(), new String[]{str, Integer.toString(iMax)}) > 0;
        } catch (SQLiteException e) {
            mo8165().f14444.m8036("Database error querying filters. appId", C4794.m8038(str), e);
            return false;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final boolean m8337(C4642 c4642, boolean z) {
        mo8008();
        m8155();
        C0567.m1910(c4642);
        C0567.m1926(c4642.zzs);
        C0567.m1939((c4642.zzc & 8) != 0);
        m8360();
        if (((C4312) this.f14588.f15022) == null) {
            throw null;
        }
        long jCurrentTimeMillis = System.currentTimeMillis();
        if (c4642.zzj < jCurrentTimeMillis - C4869.m8172() || c4642.zzj > C4869.m8172() + jCurrentTimeMillis) {
            mo8165().f14447.m8037("Storing bundle outside of the max uploading time span. appId, now, timestamp", C4794.m8038(c4642.zzs), Long.valueOf(jCurrentTimeMillis), Long.valueOf(c4642.zzj));
        }
        try {
            byte[] bArrM8143 = m8157().m8143(c4642.m7406());
            mo8165().f14452.m8035("Saving bundle, size", Integer.valueOf(bArrM8143.length));
            ContentValues contentValues = new ContentValues();
            contentValues.put("app_id", c4642.zzs);
            contentValues.put("bundle_end_timestamp", Long.valueOf(c4642.zzj));
            contentValues.put("data", bArrM8143);
            contentValues.put("has_realtime", Integer.valueOf(z ? 1 : 0));
            if ((c4642.zzd & 2) != 0) {
                contentValues.put("retry_count", Integer.valueOf(c4642.zzao));
            }
            try {
                if (m8354().insert("queue", null, contentValues) != -1) {
                    return true;
                }
                mo8165().f14444.m8035("Failed to insert bundle (got -1). appId", C4794.m8038(c4642.zzs));
                return false;
            } catch (SQLiteException e) {
                mo8165().f14444.m8036("Error storing bundle. appId", C4794.m8038(c4642.zzs), e);
                return false;
            }
        } catch (IOException e2) {
            mo8165().f14444.m8036("Data loss. Failed to serialize bundle. appId", C4794.m8038(c4642.zzs), e2);
            return false;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final boolean m8338(C4891 c4891) {
        C0567.m1910(c4891);
        mo8008();
        m8155();
        if (m8346(c4891.f14737, c4891.f14739.f15117) == null && m8341("SELECT COUNT(1) FROM conditional_properties WHERE app_id=?", new String[]{c4891.f14737}) >= 1000) {
            return false;
        }
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", c4891.f14737);
        contentValues.put("origin", c4891.f14738);
        contentValues.put("name", c4891.f14739.f15117);
        m8318(contentValues, "value", c4891.f14739.m8527());
        contentValues.put("active", Boolean.valueOf(c4891.f14741));
        contentValues.put("trigger_event_name", c4891.f14742);
        contentValues.put("trigger_timeout", Long.valueOf(c4891.f14744));
        m8167();
        contentValues.put("timed_out_event", C4887.m8228((Parcelable) c4891.f14743));
        contentValues.put("creation_timestamp", Long.valueOf(c4891.f14740));
        m8167();
        contentValues.put("triggered_event", C4887.m8228((Parcelable) c4891.f14745));
        contentValues.put("triggered_timestamp", Long.valueOf(c4891.f14739.f15118));
        contentValues.put("time_to_live", Long.valueOf(c4891.f14746));
        m8167();
        contentValues.put("expired_event", C4887.m8228((Parcelable) c4891.f14747));
        try {
            if (m8354().insertWithOnConflict("conditional_properties", null, contentValues, 5) == -1) {
                mo8165().f14444.m8035("Failed to insert/update conditional user property (got -1)", C4794.m8038(c4891.f14737));
            }
        } catch (SQLiteException e) {
            mo8165().f14444.m8036("Error storing conditional user property", C4794.m8038(c4891.f14737), e);
        }
        return true;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final boolean m8339(C4906 c4906, long j, boolean z) {
        mo8008();
        m8155();
        C0567.m1910(c4906);
        C0567.m1926(c4906.f14796);
        C4634.C4635 c4635M7653 = C4634.m7653();
        c4635M7653.m7665(c4906.f14800);
        C4908 c4908 = c4906.f14801;
        if (c4908 == null) {
            throw null;
        }
        for (String str : c4908.f14808.keySet()) {
            C4638.C4639 c4639M7674 = C4638.m7674();
            c4639M7674.m7686(str);
            m8157().m8139(c4639M7674, c4906.f14801.m8370(str));
            c4635M7653.m7662(c4639M7674);
        }
        byte[] bArrM7406 = ((C4634) ((AbstractC4421) c4635M7653.m7370())).m7406();
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", c4906.f14796);
        contentValues.put("name", c4906.f14797);
        contentValues.put("timestamp", Long.valueOf(c4906.f14799));
        contentValues.put("metadata_fingerprint", Long.valueOf(j));
        contentValues.put("data", bArrM7406);
        contentValues.put("realtime", Integer.valueOf(z ? 1 : 0));
        try {
            if (m8354().insert("raw_events", null, contentValues) != -1) {
                return true;
            }
            mo8165().f14444.m8035("Failed to insert raw event (got -1). appId", C4794.m8038(c4906.f14796));
            return false;
        } catch (SQLiteException e) {
            mo8165().f14444.m8036("Error storing raw event. appId", C4794.m8038(c4906.f14796), e);
            return false;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final boolean m8340(C5036 c5036) {
        C0567.m1910(c5036);
        mo8008();
        m8155();
        if (m8346(c5036.f15171, c5036.f15173) == null) {
            if (C4887.m8233(c5036.f15173)) {
                long jM8341 = m8341("select count(1) from user_attributes where app_id=? and name not like '!_%' escape '!'", new String[]{c5036.f15171});
                C4869 c4869 = this.f14588.f15015;
                String str = c5036.f15171;
                if (c4869 == null) {
                    throw null;
                }
                int iMax = 25;
                if (C4473.m7490() && c4869.m8183(null, C4915.f14918)) {
                    iMax = Math.max(Math.min(c4869.m8179(str, C4915.f14860), 100), 25);
                }
                if (jM8341 >= iMax) {
                    return false;
                }
            } else if (!"_npa".equals(c5036.f15173) && m8341("select count(1) from user_attributes where app_id=? and origin=? AND name like '!_%' escape '!'", new String[]{c5036.f15171, c5036.f15172}) >= 25) {
                return false;
            }
        }
        ContentValues contentValues = new ContentValues();
        contentValues.put("app_id", c5036.f15171);
        contentValues.put("origin", c5036.f15172);
        contentValues.put("name", c5036.f15173);
        contentValues.put("set_timestamp", Long.valueOf(c5036.f15174));
        m8318(contentValues, "value", c5036.f15175);
        try {
            if (m8354().insertWithOnConflict("user_attributes", null, contentValues, 5) == -1) {
                mo8165().f14444.m8035("Failed to insert/update user property (got -1). appId", C4794.m8038(c5036.f15171));
            }
        } catch (SQLiteException e) {
            mo8165().f14444.m8036("Error storing user property. appId", C4794.m8038(c5036.f15171), e);
        }
        return true;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final long m8341(String str, String[] strArr) {
        Cursor cursor = null;
        try {
            try {
                Cursor cursorRawQuery = m8354().rawQuery(str, strArr);
                if (!cursorRawQuery.moveToFirst()) {
                    throw new SQLiteException("Database returned empty set");
                }
                long j = cursorRawQuery.getLong(0);
                cursorRawQuery.close();
                return j;
            } catch (SQLiteException e) {
                mo8165().f14444.m8036("Database error", str, e);
                throw e;
            }
        } catch (Throwable th) {
            if (0 != 0) {
                cursor.close();
            }
            throw th;
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final List<C4891> m8342(String str, String str2, String str3) {
        C0567.m1926(str);
        mo8008();
        m8155();
        ArrayList arrayList = new ArrayList(3);
        arrayList.add(str);
        StringBuilder sb = new StringBuilder("app_id=?");
        if (!TextUtils.isEmpty(str2)) {
            arrayList.add(str2);
            sb.append(" and origin=?");
        }
        if (!TextUtils.isEmpty(str3)) {
            arrayList.add(String.valueOf(str3).concat("*"));
            sb.append(" and name glob ?");
        }
        return m8326(sb.toString(), (String[]) arrayList.toArray(new String[arrayList.size()]));
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final C4755 m8343(String str) throws Throwable {
        Cursor cursorQuery;
        C0567.m1926(str);
        mo8008();
        m8155();
        Cursor cursor = null;
        try {
            boolean z = true;
            cursorQuery = m8354().query("apps", new String[]{"app_instance_id", "gmp_app_id", "resettable_device_id_hash", "last_bundle_index", "last_bundle_start_timestamp", "last_bundle_end_timestamp", "app_version", "app_store", "gmp_version", "dev_cert_hash", "measurement_enabled", "day", "daily_public_events_count", "daily_events_count", "daily_conversions_count", "config_fetched_time", "failed_config_fetch_time", "app_version_int", "firebase_instance_id", "daily_error_events_count", "daily_realtime_events_count", "health_monitor_sample", "android_id", "adid_reporting_enabled", "ssaid_reporting_enabled", "admob_app_id", "dynamite_version", "safelisted_events", "ga_app_id"}, "app_id=?", new String[]{str}, null, null, null);
            try {
                try {
                    if (!cursorQuery.moveToFirst()) {
                        cursorQuery.close();
                        return null;
                    }
                    C4755 c4755 = new C4755(this.f14567.f14718, str);
                    c4755.m7919(cursorQuery.getString(0));
                    c4755.m7924(cursorQuery.getString(1));
                    c4755.m7935(cursorQuery.getString(2));
                    c4755.m7940(cursorQuery.getLong(3));
                    c4755.m7917(cursorQuery.getLong(4));
                    c4755.m7923(cursorQuery.getLong(5));
                    c4755.m7941(cursorQuery.getString(6));
                    c4755.m7944(cursorQuery.getString(7));
                    c4755.m7930(cursorQuery.getLong(8));
                    c4755.m7934(cursorQuery.getLong(9));
                    c4755.m7921(cursorQuery.isNull(10) || cursorQuery.getInt(10) != 0);
                    long j = cursorQuery.getLong(11);
                    c4755.f14289.mo8163().mo8008();
                    c4755.f14319 |= c4755.f14312 != j;
                    c4755.f14312 = j;
                    long j2 = cursorQuery.getLong(12);
                    c4755.f14289.mo8163().mo8008();
                    c4755.f14319 |= c4755.f14313 != j2;
                    c4755.f14313 = j2;
                    long j3 = cursorQuery.getLong(13);
                    c4755.f14289.mo8163().mo8008();
                    c4755.f14319 |= c4755.f14314 != j3;
                    c4755.f14314 = j3;
                    long j4 = cursorQuery.getLong(14);
                    c4755.f14289.mo8163().mo8008();
                    c4755.f14319 |= c4755.f14315 != j4;
                    c4755.f14315 = j4;
                    c4755.m7943(cursorQuery.getLong(15));
                    c4755.m7946(cursorQuery.getLong(16));
                    c4755.m7926(cursorQuery.isNull(17) ? -2147483648L : cursorQuery.getInt(17));
                    c4755.m7938(cursorQuery.getString(18));
                    long j5 = cursorQuery.getLong(19);
                    c4755.f14289.mo8163().mo8008();
                    c4755.f14319 |= c4755.f14316 != j5;
                    c4755.f14316 = j5;
                    long j6 = cursorQuery.getLong(20);
                    c4755.f14289.mo8163().mo8008();
                    c4755.f14319 |= c4755.f14317 != j6;
                    c4755.f14317 = j6;
                    c4755.m7947(cursorQuery.getString(21));
                    long j7 = 0;
                    if (!this.f14588.f15015.m8177(C4915.f14920)) {
                        c4755.m7949(cursorQuery.isNull(22) ? 0L : cursorQuery.getLong(22));
                    }
                    c4755.m7925(cursorQuery.isNull(23) || cursorQuery.getInt(23) != 0);
                    if (!cursorQuery.isNull(24) && cursorQuery.getInt(24) == 0) {
                        z = false;
                    }
                    c4755.m7928(z);
                    c4755.m7927(cursorQuery.getString(25));
                    if (!cursorQuery.isNull(26)) {
                        j7 = cursorQuery.getLong(26);
                    }
                    c4755.m7937(j7);
                    if (!cursorQuery.isNull(27)) {
                        c4755.m7920(Arrays.asList(cursorQuery.getString(27).split(",", -1)));
                    }
                    if (C4538.m7580() && this.f14588.f15015.m8183(str, C4915.f14896)) {
                        c4755.m7931(cursorQuery.getString(28));
                    }
                    c4755.f14289.mo8163().mo8008();
                    c4755.f14319 = false;
                    if (cursorQuery.moveToNext()) {
                        mo8165().f14444.m8035("Got multiple records for app, expected one. appId", C4794.m8038(str));
                    }
                    cursorQuery.close();
                    return c4755;
                } catch (SQLiteException e) {
                    e = e;
                    mo8165().f14444.m8036("Error querying app. appId", C4794.m8038(str), e);
                    if (cursorQuery != null) {
                        cursorQuery.close();
                    }
                    return null;
                }
            } catch (Throwable th) {
                th = th;
                cursor = cursorQuery;
            }
            th = th;
            cursor = cursorQuery;
        } catch (SQLiteException e2) {
            e = e2;
            cursorQuery = null;
        } catch (Throwable th2) {
            th = th2;
        }
        if (cursor != null) {
            cursor.close();
        }
        throw th;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final void m8344(String str, String str2) {
        C0567.m1926(str);
        C0567.m1926(str2);
        mo8008();
        m8155();
        try {
            m8354().delete("user_attributes", "app_id=? and name=?", new String[]{str, str2});
        } catch (SQLiteException e) {
            mo8165().f14444.m8037("Error deleting user property. appId", C4794.m8038(str), m8161().m8114(str2), e);
        }
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final long m8345(String str) {
        C0567.m1926(str);
        mo8008();
        m8155();
        try {
            return m8354().delete("raw_events", "rowid in (select rowid from raw_events where app_id=? order by rowid desc limit -1 offset ?)", new String[]{str, String.valueOf(Math.max(0, Math.min(1000000, this.f14588.f15015.m8179(str, C4915.f14843))))});
        } catch (SQLiteException e) {
            mo8165().f14444.m8036("Error deleting over the limit events. appId", C4794.m8038(str), e);
            return 0L;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:32:0x00a1  */
    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final C5036 m8346(String str, String str2) throws Throwable {
        Cursor cursorQuery;
        C0567.m1926(str);
        C0567.m1926(str2);
        mo8008();
        m8155();
        Cursor cursor = null;
        try {
            try {
                cursorQuery = m8354().query("user_attributes", new String[]{"set_timestamp", "value", "origin"}, "app_id=? and name=?", new String[]{str, str2}, null, null, null);
            } catch (Throwable th) {
                th = th;
            }
            try {
                if (!cursorQuery.moveToFirst()) {
                    cursorQuery.close();
                    return null;
                }
                try {
                    C5036 c5036 = new C5036(str, cursorQuery.getString(2), str2, cursorQuery.getLong(0), m8321(cursorQuery, 1));
                    if (cursorQuery.moveToNext()) {
                        mo8165().f14444.m8035("Got multiple records for user property, expected one. appId", C4794.m8038(str));
                    }
                    cursorQuery.close();
                    return c5036;
                } catch (SQLiteException e) {
                    e = e;
                }
            } catch (SQLiteException e2) {
                e = e2;
            } catch (Throwable th2) {
                th = th2;
                cursor = cursorQuery;
                if (cursor != null) {
                    cursor.close();
                }
                throw th;
            }
        } catch (SQLiteException e3) {
            e = e3;
            cursorQuery = null;
        } catch (Throwable th3) {
            th = th3;
            if (cursor != null) {
            }
            throw th;
        }
        mo8165().f14444.m8037("Error querying user property. appId", C4794.m8038(str), m8161().m8114(str2), e);
        if (cursorQuery != null) {
            cursorQuery.close();
        }
        return null;
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final long m8347(String str) {
        C0567.m1926(str);
        return m8319("select count(1) from events where app_id=? and name not like '!_%' escape '!'", new String[]{str}, 0L);
    }

    /* JADX WARN: Removed duplicated region for block: B:31:0x0115  */
    /* JADX WARN: Removed duplicated region for block: B:36:0x011d  */
    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final C4891 m8348(String str, String str2) throws Throwable {
        Cursor cursorQuery;
        C0567.m1926(str);
        C0567.m1926(str2);
        mo8008();
        m8155();
        Cursor cursor = null;
        try {
            cursorQuery = m8354().query("conditional_properties", new String[]{"origin", "value", "active", "trigger_event_name", "trigger_timeout", "timed_out_event", "creation_timestamp", "triggered_event", "triggered_timestamp", "time_to_live", "expired_event"}, "app_id=? and name=?", new String[]{str, str2}, null, null, null);
        } catch (SQLiteException e) {
            e = e;
            cursorQuery = null;
        } catch (Throwable th) {
            th = th;
            if (cursor != null) {
            }
            throw th;
        }
        try {
            if (!cursorQuery.moveToFirst()) {
                cursorQuery.close();
                return null;
            }
            String string = cursorQuery.getString(0);
            try {
                try {
                    Object objM8321 = m8321(cursorQuery, 1);
                    boolean z = cursorQuery.getInt(2) != 0;
                    C4891 c4891 = new C4891(str, string, new C4999(str2, cursorQuery.getLong(8), objM8321, string), cursorQuery.getLong(6), z, cursorQuery.getString(3), (C4913) m8157().m8130(cursorQuery.getBlob(5), C4913.CREATOR), cursorQuery.getLong(4), (C4913) m8157().m8130(cursorQuery.getBlob(7), C4913.CREATOR), cursorQuery.getLong(9), (C4913) m8157().m8130(cursorQuery.getBlob(10), C4913.CREATOR));
                    if (cursorQuery.moveToNext()) {
                        mo8165().f14444.m8036("Got multiple records for conditional property, expected one", C4794.m8038(str), m8161().m8114(str2));
                    }
                    cursorQuery.close();
                    return c4891;
                } catch (SQLiteException e2) {
                    e = e2;
                    mo8165().f14444.m8037("Error querying conditional property", C4794.m8038(str), m8161().m8114(str2), e);
                    if (cursorQuery != null) {
                    }
                    return null;
                }
            } catch (Throwable th2) {
                th = th2;
                cursor = cursorQuery;
                if (cursor != null) {
                    cursor.close();
                }
                throw th;
            }
        } catch (SQLiteException e3) {
            e = e3;
        } catch (Throwable th3) {
            th = th3;
            cursor = cursorQuery;
            if (cursor != null) {
            }
            throw th;
        }
        mo8165().f14444.m8037("Error querying conditional property", C4794.m8038(str), m8161().m8114(str2), e);
        if (cursorQuery != null) {
            cursorQuery.close();
        }
        return null;
    }

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final int m8349(String str, String str2) {
        C0567.m1926(str);
        C0567.m1926(str2);
        mo8008();
        m8155();
        try {
            return m8354().delete("conditional_properties", "app_id=? and name=?", new String[]{str, str2});
        } catch (SQLiteException e) {
            mo8165().f14444.m8037("Error deleting conditional property", C4794.m8038(str), m8161().m8114(str2), e);
            return 0;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:34:0x00b4  */
    /* JADX WARN: Type inference failed for: r9v0 */
    /* JADX WARN: Type inference failed for: r9v1, types: [android.database.Cursor] */
    /* JADX WARN: Type inference failed for: r9v2 */
    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Map<Integer, List<C4586>> m8350(String str, String str2) throws Throwable {
        SQLiteException e;
        Cursor cursorQuery;
        m8155();
        mo8008();
        C0567.m1926(str);
        C0567.m1926(str2);
        C1714 c1714 = new C1714();
        ?? r9 = 0;
        try {
            try {
                cursorQuery = m8354().query("event_filters", new String[]{"audience_id", "data"}, "app_id=? AND event_name=?", new String[]{str, str2}, null, null, null);
                try {
                    if (!cursorQuery.moveToFirst()) {
                        Map<Integer, List<C4586>> mapEmptyMap = Collections.emptyMap();
                        cursorQuery.close();
                        return mapEmptyMap;
                    }
                    do {
                        try {
                            C4586 c4586 = (C4586) ((AbstractC4421) ((C4586.C4587) C4833.m8121(C4586.zzl.m7362(), cursorQuery.getBlob(1))).m7370());
                            int i = cursorQuery.getInt(0);
                            List arrayList = (List) c1714.get(Integer.valueOf(i));
                            if (arrayList == null) {
                                arrayList = new ArrayList();
                                c1714.put(Integer.valueOf(i), arrayList);
                            }
                            arrayList.add(c4586);
                        } catch (IOException e2) {
                            mo8165().f14444.m8036("Failed to merge filter. appId", C4794.m8038(str), e2);
                        }
                    } while (cursorQuery.moveToNext());
                    cursorQuery.close();
                    return c1714;
                } catch (SQLiteException e3) {
                    e = e3;
                    mo8165().f14444.m8036("Database error querying filters. appId", C4794.m8038(str), e);
                    if (cursorQuery != null) {
                        cursorQuery.close();
                    }
                    return null;
                }
            } catch (Throwable th) {
                th = th;
                r9 = str2;
                if (r9 != 0) {
                    r9.close();
                }
                throw th;
            }
        } catch (SQLiteException e4) {
            e = e4;
            cursorQuery = null;
        } catch (Throwable th2) {
            th = th2;
            if (r9 != 0) {
            }
            throw th;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:34:0x00b3  */
    /* JADX WARN: Type inference failed for: r9v0 */
    /* JADX WARN: Type inference failed for: r9v1, types: [android.database.Cursor] */
    /* JADX WARN: Type inference failed for: r9v2 */
    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Map<Integer, List<C4593>> m8351(String str, String str2) throws Throwable {
        Cursor cursorQuery;
        m8155();
        mo8008();
        C0567.m1926(str);
        C0567.m1926(str2);
        C1714 c1714 = new C1714();
        ?? r9 = 0;
        try {
            try {
                cursorQuery = m8354().query("property_filters", new String[]{"audience_id", "data"}, "app_id=? AND property_name=?", new String[]{str, str2}, null, null, null);
                try {
                    if (!cursorQuery.moveToFirst()) {
                        Map<Integer, List<C4593>> mapEmptyMap = Collections.emptyMap();
                        cursorQuery.close();
                        return mapEmptyMap;
                    }
                    do {
                        try {
                            C4593 c4593 = (C4593) ((AbstractC4421) ((C4593.C4594) C4833.m8121(C4593.zzj.m7362(), cursorQuery.getBlob(1))).m7370());
                            int i = cursorQuery.getInt(0);
                            List arrayList = (List) c1714.get(Integer.valueOf(i));
                            if (arrayList == null) {
                                arrayList = new ArrayList();
                                c1714.put(Integer.valueOf(i), arrayList);
                            }
                            arrayList.add(c4593);
                        } catch (IOException e) {
                            mo8165().f14444.m8036("Failed to merge filter", C4794.m8038(str), e);
                        }
                    } while (cursorQuery.moveToNext());
                    cursorQuery.close();
                    return c1714;
                } catch (SQLiteException e2) {
                    e = e2;
                    mo8165().f14444.m8036("Database error querying filters. appId", C4794.m8038(str), e);
                    if (cursorQuery != null) {
                        cursorQuery.close();
                    }
                    return null;
                }
            } catch (Throwable th) {
                th = th;
                r9 = str2;
                if (r9 != 0) {
                    r9.close();
                }
                throw th;
            }
        } catch (SQLiteException e3) {
            e = e3;
            cursorQuery = null;
        } catch (Throwable th2) {
            th = th2;
            if (r9 != 0) {
            }
            throw th;
        }
    }

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final long m8352(String str, String str2) throws Throwable {
        long jM8319;
        C0567.m1926(str);
        C0567.m1926(str2);
        mo8008();
        m8155();
        SQLiteDatabase sQLiteDatabaseM8354 = m8354();
        sQLiteDatabaseM8354.beginTransaction();
        long j = 0;
        try {
            try {
                StringBuilder sb = new StringBuilder(String.valueOf(str2).length() + 32);
                sb.append("select ");
                sb.append(str2);
                sb.append(" from app2 where app_id=?");
                try {
                    jM8319 = m8319(sb.toString(), new String[]{str}, -1L);
                } catch (SQLiteException e) {
                    e = e;
                }
            } catch (Throwable th) {
                th = th;
                sQLiteDatabaseM8354.endTransaction();
                throw th;
            }
        } catch (SQLiteException e2) {
            e = e2;
        } catch (Throwable th2) {
            th = th2;
            sQLiteDatabaseM8354.endTransaction();
            throw th;
        }
        if (jM8319 == -1) {
            ContentValues contentValues = new ContentValues();
            contentValues.put("app_id", str);
            contentValues.put("first_open_count", (Integer) 0);
            contentValues.put("previous_install_count", (Integer) 0);
            if (sQLiteDatabaseM8354.insertWithOnConflict("app2", null, contentValues, 5) == -1) {
                mo8165().f14444.m8036("Failed to insert column (got -1). appId", C4794.m8038(str), str2);
                sQLiteDatabaseM8354.endTransaction();
                return -1L;
            }
            jM8319 = 0;
            mo8165().f14444.m8037("Error inserting column. appId", C4794.m8038(str), str2, e);
            sQLiteDatabaseM8354.endTransaction();
            return j;
        }
        try {
            ContentValues contentValues2 = new ContentValues();
            contentValues2.put("app_id", str);
            contentValues2.put(str2, Long.valueOf(1 + jM8319));
            if (sQLiteDatabaseM8354.update("app2", contentValues2, "app_id = ?", new String[]{str}) == 0) {
                mo8165().f14444.m8036("Failed to update column (got 0). appId", C4794.m8038(str), str2);
                sQLiteDatabaseM8354.endTransaction();
                return -1L;
            }
            sQLiteDatabaseM8354.setTransactionSuccessful();
            sQLiteDatabaseM8354.endTransaction();
            return jM8319;
        } catch (SQLiteException e3) {
            e = e3;
            j = jM8319;
        }
    }

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

    /* JADX INFO: renamed from: ސ, reason: contains not printable characters */
    public final void m8353() {
        m8155();
        m8354().setTransactionSuccessful();
    }

    /* JADX INFO: renamed from: ޑ, reason: contains not printable characters */
    public final SQLiteDatabase m8354() {
        mo8008();
        try {
            return this.f14782.getWritableDatabase();
        } catch (SQLiteException e) {
            mo8165().f14447.m8035("Error opening database", e);
            throw e;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:23:0x003b  */
    /* JADX WARN: Type inference failed for: r0v0, types: [android.database.sqlite.SQLiteDatabase] */
    /* JADX WARN: Type inference failed for: r0v2 */
    /* JADX WARN: Type inference failed for: r0v4, types: [android.database.Cursor] */
    /* JADX INFO: renamed from: ޒ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final String m8355() {
        Throwable th;
        Cursor cursorRawQuery;
        ?? M8354 = m8354();
        try {
            try {
                cursorRawQuery = M8354.rawQuery("select app_id from queue order by has_realtime desc, rowid asc limit 1;", null);
                try {
                    if (!cursorRawQuery.moveToFirst()) {
                        cursorRawQuery.close();
                        return null;
                    }
                    String string = cursorRawQuery.getString(0);
                    cursorRawQuery.close();
                    return string;
                } catch (SQLiteException e) {
                    e = e;
                    mo8165().f14444.m8035("Database error getting next bundle app id", e);
                    if (cursorRawQuery != null) {
                        cursorRawQuery.close();
                    }
                    return null;
                }
            } catch (Throwable th2) {
                th = th2;
                if (M8354 != 0) {
                    M8354.close();
                }
                throw th;
            }
        } catch (SQLiteException e2) {
            e = e2;
            cursorRawQuery = null;
        } catch (Throwable th3) {
            th = th3;
            M8354 = 0;
            if (M8354 != 0) {
            }
            throw th;
        }
    }

    /* JADX INFO: renamed from: ޓ, reason: contains not printable characters */
    public final long m8356() {
        Cursor cursorRawQuery = null;
        try {
            try {
                cursorRawQuery = m8354().rawQuery("select rowid from raw_events order by rowid desc limit 1;", null);
                if (!cursorRawQuery.moveToFirst()) {
                    cursorRawQuery.close();
                    return -1L;
                }
                long j = cursorRawQuery.getLong(0);
                cursorRawQuery.close();
                return j;
            } catch (SQLiteException e) {
                mo8165().f14444.m8035("Error querying raw events", e);
                if (cursorRawQuery != null) {
                    cursorRawQuery.close();
                }
                return -1L;
            }
        } catch (Throwable th) {
            if (cursorRawQuery != null) {
                cursorRawQuery.close();
            }
            throw th;
        }
    }

    /* JADX INFO: renamed from: ޔ, reason: contains not printable characters */
    public final boolean m8357() {
        return this.f14588.f15009.getDatabasePath("google_app_measurement.db").exists();
    }

    /* JADX INFO: renamed from: ޕ, reason: contains not printable characters */
    public final void m8358() {
        m8155();
        m8354().beginTransaction();
    }

    /* JADX INFO: renamed from: ޖ, reason: contains not printable characters */
    public final void m8359() {
        m8155();
        m8354().endTransaction();
    }

    /* JADX INFO: renamed from: ޗ, reason: contains not printable characters */
    public final void m8360() {
        mo8008();
        m8155();
        if (m8357()) {
            long jM8316 = m8168().f14651.m8316();
            if (((C4312) this.f14588.f15022) == null) {
                throw null;
            }
            long jElapsedRealtime = SystemClock.elapsedRealtime();
            if (Math.abs(jElapsedRealtime - jM8316) > C4915.f14852.m8054(null).longValue()) {
                m8168().f14651.m8317(jElapsedRealtime);
                mo8008();
                m8155();
                if (m8357()) {
                    SQLiteDatabase sQLiteDatabaseM8354 = m8354();
                    String[] strArr = new String[2];
                    if (((C4312) this.f14588.f15022) == null) {
                        throw null;
                    }
                    strArr[0] = String.valueOf(System.currentTimeMillis());
                    strArr[1] = String.valueOf(C4869.m8172());
                    int iDelete = sQLiteDatabaseM8354.delete("queue", "abs(bundle_end_timestamp - ?) > cast(? as integer)", strArr);
                    if (iDelete > 0) {
                        mo8165().f14452.m8035("Deleted stale rows. rowsDeleted", Integer.valueOf(iDelete));
                    }
                }
            }
        }
    }
}
